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

The following examples show how to use org.springframework.web.reactive.function.client.ExchangeStrategies. These examples are extracted from open source projects. 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 Project: Moss   Source File: AbstractAdminApplicationTest.java    License: 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 2
Source Project: Moss   Source File: AdminApplicationDiscoveryTest.java    License: 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 3
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 4
@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 5
Source Project: openapi-generator   Source File: ApiClient.java    License: 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 6
@Override
public ExchangeStrategies strategies() {
	return new ExchangeStrategies() {
		@Override
		public List<HttpMessageReader<?>> messageReaders() {
			return Collections.emptyList();
		}

		@Override
		public List<HttpMessageWriter<?>> messageWriters() {
			return Collections.emptyList();
		}
	};
}
 
Example 7
Source Project: spring-credhub   Source File: CredHubWebClientFactory.java    License: 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 8
Source Project: problem-spring-web   Source File: AdviceTraitTesting.java    License: 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 9
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 10
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
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 Project: spring-analysis-note   Source File: ClientResponseWrapper.java    License: MIT License 4 votes vote down vote up
@Override
public ExchangeStrategies strategies() {
	return this.delegate.strategies();
}
 
Example 13
Source Project: spring-analysis-note   Source File: DefaultWebTestClientBuilder.java    License: MIT License 4 votes vote down vote up
@Override
public WebTestClient.Builder exchangeStrategies(ExchangeStrategies strategies) {
	this.webClientBuilder.exchangeStrategies(strategies);
	return this;
}
 
Example 14
Source Project: java-technology-stack   Source File: ClientResponseWrapper.java    License: MIT License 4 votes vote down vote up
@Override
public ExchangeStrategies strategies() {
	return this.delegate.strategies();
}
 
Example 15
@Override
public WebTestClient.Builder exchangeStrategies(ExchangeStrategies strategies) {
	this.webClientBuilder.exchangeStrategies(strategies);
	return this;
}
 
Example 16
Source Project: soul   Source File: BodyInserterContext.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Instantiates a new Body inserter context.
 */
public BodyInserterContext() {
    this.exchangeStrategies = ExchangeStrategies.withDefaults();
}
 
Example 17
Source Project: charon-spring-boot-starter   Source File: HttpRequest.java    License: 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 18
Source Project: charon-spring-boot-starter   Source File: HttpResponse.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public ExchangeStrategies strategies() {
    return delegate.strategies();
}
 
Example 19
Source Project: spring-cloud-gateway   Source File: BodyInserterContext.java    License: Apache License 2.0 4 votes vote down vote up
public BodyInserterContext() {
	this.exchangeStrategies = ExchangeStrategies.withDefaults();
}
 
Example 20
Source Project: spring-cloud-gateway   Source File: BodyInserterContext.java    License: Apache License 2.0 4 votes vote down vote up
public BodyInserterContext(ExchangeStrategies exchangeStrategies) {
	this.exchangeStrategies = exchangeStrategies; // TODO: support custom strategies
}
 
Example 21
Source Project: spring-analysis-note   Source File: WebTestClient.java    License: 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 Project: java-technology-stack   Source File: WebTestClient.java    License: 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);