org.springframework.web.reactive.function.client.ExchangeStrategies Java Examples

The following examples show how to use org.springframework.web.reactive.function.client.ExchangeStrategies. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
* Build the RestTemplate used to make HTTP requests.
* @return RestTemplate
*/
public static WebClient buildWebClient(ObjectMapper mapper) {
    ExchangeStrategies strategies = ExchangeStrategies
        .builder()
        .codecs(clientDefaultCodecsConfigurer -> {
            clientDefaultCodecsConfigurer.defaultCodecs().jackson2JsonEncoder(new Jackson2JsonEncoder(mapper, MediaType.APPLICATION_JSON));
            clientDefaultCodecsConfigurer.defaultCodecs().jackson2JsonDecoder(new Jackson2JsonDecoder(mapper, MediaType.APPLICATION_JSON));
        }).build();
    WebClient.Builder webClient = WebClient.builder().exchangeStrategies(strategies);
    return webClient.build();
}
 
Example #2
Source File: AbstractAdminApplicationTest.java    From spring-boot-admin with Apache License 2.0 5 votes vote down vote up
protected WebTestClient createWebClient(int port) {
	ObjectMapper mapper = new ObjectMapper().registerModule(new JsonOrgModule());
	return WebTestClient.bindToServer().baseUrl("http://localhost:" + port)
			.exchangeStrategies(ExchangeStrategies.builder().codecs((configurer) -> {
				configurer.defaultCodecs().jackson2JsonDecoder(new Jackson2JsonDecoder(mapper));
				configurer.defaultCodecs().jackson2JsonEncoder(new Jackson2JsonEncoder(mapper));
			}).build()).build();
}
 
Example #3
Source File: AdminApplicationDiscoveryTest.java    From spring-boot-admin with Apache License 2.0 5 votes vote down vote up
private WebTestClient createWebClient(int port) {
	ObjectMapper mapper = new ObjectMapper().registerModule(new JsonOrgModule());
	return WebTestClient.bindToServer().baseUrl("http://localhost:" + port)
			.exchangeStrategies(ExchangeStrategies.builder().codecs((configurer) -> {
				configurer.defaultCodecs().jackson2JsonDecoder(new Jackson2JsonDecoder(mapper));
				configurer.defaultCodecs().jackson2JsonEncoder(new Jackson2JsonEncoder(mapper));
			}).build()).build();
}
 
Example #4
Source File: WebClientTransportClientFactory.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
private void setExchangeStrategies(WebClient.Builder builder) {
	ObjectMapper objectMapper = objectMapper();
	ExchangeStrategies strategies = ExchangeStrategies.builder()
			.codecs(clientDefaultCodecsConfigurer -> {
				clientDefaultCodecsConfigurer.defaultCodecs()
						.jackson2JsonEncoder(new Jackson2JsonEncoder(objectMapper,
								MediaType.APPLICATION_JSON));
				clientDefaultCodecsConfigurer.defaultCodecs()
						.jackson2JsonDecoder(new Jackson2JsonDecoder(objectMapper,
								MediaType.APPLICATION_JSON));

			}).build();
	builder.exchangeStrategies(strategies);
}
 
Example #5
Source File: AdviceTraitTesting.java    From problem-spring-web with MIT License 5 votes vote down vote up
default WebTestClient webTestClient() {
    return WebTestClient.bindToController(new ExampleRestController())
            .apply(new MockServerConfigurer() {
                @Override
                public void beforeServerCreated(WebHttpHandlerBuilder builder) {
                    builder.exceptionHandlers(handlers ->
                            handlers.add(0, new ProblemExceptionHandler(mapper(), unit())));
                }
            })
            .controllerAdvice(unit())
            .httpMessageCodecs(this::configureJson)
            .configureClient()
            .exchangeStrategies(ExchangeStrategies.builder().codecs(this::configureJson).build())
            .build();
}
 
Example #6
Source File: CredHubWebClientFactory.java    From spring-credhub with Apache License 2.0 5 votes vote down vote up
private static WebClient.Builder buildWebClient(String baseUri, ClientHttpConnector clientHttpConnector) {
	ExchangeStrategies strategies = ExchangeStrategies.builder().codecs((configurer) -> {
		ObjectMapper mapper = JsonUtils.buildObjectMapper();

		CodecConfigurer.DefaultCodecs dc = configurer.defaultCodecs();
		dc.jackson2JsonDecoder(new Jackson2JsonDecoder(mapper));
		dc.jackson2JsonEncoder(new Jackson2JsonEncoder(mapper));
	}).build();

	return WebClient.builder().clientConnector(clientHttpConnector).baseUrl(baseUri)
			.defaultHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE)
			.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
			.exchangeStrategies(strategies);
}
 
Example #7
Source File: MockClientResponse.java    From Hands-On-Reactive-Programming-in-Spring-5 with MIT License 5 votes vote down vote up
@Override
public ExchangeStrategies strategies() {
	return new ExchangeStrategies() {
		@Override
		public List<HttpMessageReader<?>> messageReaders() {
			return Collections.emptyList();
		}

		@Override
		public List<HttpMessageWriter<?>> messageWriters() {
			return Collections.emptyList();
		}
	};
}
 
Example #8
Source File: ReactiveWebClientBuilderInitializer.java    From spring-fu with Apache License 2.0 5 votes vote down vote up
@Override
public void customize(WebClient.Builder builder) {
	builder.exchangeStrategies(ExchangeStrategies.empty()
					.codecs(codecs -> this.codecCustomizers
							.forEach((customizer) -> customizer.customize(codecs))).build());
	if (this.baseUrl != null) {
		builder.baseUrl(this.baseUrl);
	}
}
 
Example #9
Source File: VertxWebTestClientSupplier.java    From vertx-spring-boot with Apache License 2.0 5 votes vote down vote up
private void customizeWebTestClientCodecs(WebTestClient.Builder builder) {
    Collection<CodecCustomizer> customizers = applicationContext.getBeansOfType(CodecCustomizer.class).values();

    ExchangeStrategies strategies = ExchangeStrategies.builder()
        .codecs(codecs -> customizers.forEach(customizer -> customizer.customize(codecs)))
        .build();

    builder.exchangeStrategies(strategies);
}
 
Example #10
Source File: AdminApplicationDiscoveryTest.java    From Moss with Apache License 2.0 5 votes vote down vote up
private WebTestClient createWebClient(int port) {
    ObjectMapper mapper = new ObjectMapper().registerModule(new JsonOrgModule());
    return WebTestClient.bindToServer()
                        .baseUrl("http://localhost:" + port)
                        .exchangeStrategies(ExchangeStrategies.builder().codecs((configurer) -> {
                            configurer.defaultCodecs().jackson2JsonDecoder(new Jackson2JsonDecoder(mapper));
                            configurer.defaultCodecs().jackson2JsonEncoder(new Jackson2JsonEncoder(mapper));
                        }).build())
                        .build();
}
 
Example #11
Source File: AbstractAdminApplicationTest.java    From Moss with Apache License 2.0 5 votes vote down vote up
protected WebTestClient createWebClient(int port) {
    ObjectMapper mapper = new ObjectMapper().registerModule(new JsonOrgModule());
    return WebTestClient.bindToServer()
                        .baseUrl("http://localhost:" + port)
                        .exchangeStrategies(ExchangeStrategies.builder().codecs((configurer) -> {
                            configurer.defaultCodecs().jackson2JsonDecoder(new Jackson2JsonDecoder(mapper));
                            configurer.defaultCodecs().jackson2JsonEncoder(new Jackson2JsonEncoder(mapper));
                        }).build())
                        .build();
}
 
Example #12
Source File: BodyInserterContext.java    From soul with Apache License 2.0 4 votes vote down vote up
/**
 * Instantiates a new Body inserter context.
 */
public BodyInserterContext() {
    this.exchangeStrategies = ExchangeStrategies.withDefaults();
}
 
Example #13
Source File: ClientResponseWrapper.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public ExchangeStrategies strategies() {
	return this.delegate.strategies();
}
 
Example #14
Source File: DefaultWebTestClientBuilder.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public WebTestClient.Builder exchangeStrategies(ExchangeStrategies strategies) {
	this.webClientBuilder.exchangeStrategies(strategies);
	return this;
}
 
Example #15
Source File: ClientResponseWrapper.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public ExchangeStrategies strategies() {
	return this.delegate.strategies();
}
 
Example #16
Source File: HttpRequest.java    From charon-spring-boot-starter with Apache License 2.0 4 votes vote down vote up
@Override
public Mono<Void> writeTo(ClientHttpRequest request, ExchangeStrategies strategies) {
    return delegate.writeTo(request, strategies);
}
 
Example #17
Source File: HttpResponse.java    From charon-spring-boot-starter with Apache License 2.0 4 votes vote down vote up
@Override
public ExchangeStrategies strategies() {
    return delegate.strategies();
}
 
Example #18
Source File: BodyInserterContext.java    From spring-cloud-gateway with Apache License 2.0 4 votes vote down vote up
public BodyInserterContext() {
	this.exchangeStrategies = ExchangeStrategies.withDefaults();
}
 
Example #19
Source File: BodyInserterContext.java    From spring-cloud-gateway with Apache License 2.0 4 votes vote down vote up
public BodyInserterContext(ExchangeStrategies exchangeStrategies) {
	this.exchangeStrategies = exchangeStrategies; // TODO: support custom strategies
}
 
Example #20
Source File: DefaultWebTestClientBuilder.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public WebTestClient.Builder exchangeStrategies(ExchangeStrategies strategies) {
	this.webClientBuilder.exchangeStrategies(strategies);
	return this;
}
 
Example #21
Source File: WebTestClient.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * Configure the {@link ExchangeStrategies} to use.
 * <p>By default {@link ExchangeStrategies#withDefaults()} is used.
 * @param strategies the strategies to use
 */
Builder exchangeStrategies(ExchangeStrategies strategies);
 
Example #22
Source File: WebTestClient.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Configure the {@link ExchangeStrategies} to use.
 * <p>By default {@link ExchangeStrategies#withDefaults()} is used.
 * @param strategies the strategies to use
 */
Builder exchangeStrategies(ExchangeStrategies strategies);