WebClientConfigurer overrides exchange strategies
See original GitHub issueNot sure if feature or bug 😉 (Hateoas version 1.0.0.M1)
public class WebClientConfigurer {
private final ObjectMapper mapper;
private final Collection<HypermediaMappingInformation> hypermediaTypes;
/**
* Return a set of {@link ExchangeStrategies} driven by registered {@link HypermediaType}s.
*
* @return a collection of {@link Encoder}s and {@link Decoder} assembled into a {@link ExchangeStrategies}.
*/
public ExchangeStrategies hypermediaExchangeStrategies() {
List<Encoder<?>> encoders = new ArrayList<>();
List<Decoder<?>> decoders = new ArrayList<>();
this.hypermediaTypes.forEach(hypermedia -> {
ObjectMapper objectMapper = hypermedia.configureObjectMapper(this.mapper.copy());
MimeType[] mimeTypes = hypermedia.getMediaTypes().toArray(new MimeType[0]);
encoders.add(new Jackson2JsonEncoder(objectMapper, mimeTypes));
decoders.add(new Jackson2JsonDecoder(objectMapper, mimeTypes));
});
encoders.add(CharSequenceEncoder.allMimeTypes());
decoders.add(StringDecoder.allMimeTypes());
return ExchangeStrategies.builder().codecs(clientCodecConfigurer -> {
encoders.forEach(encoder -> clientCodecConfigurer.customCodecs().encoder(encoder));
decoders.forEach(decoder -> clientCodecConfigurer.customCodecs().decoder(decoder));
clientCodecConfigurer.registerDefaults(false);
}).build();
}
/**
* Register the proper {@link ExchangeStrategies} for a given {@link WebClient}.
*
* @param webClient
* @return mutated webClient with hypermedia support.
*/
public WebClient registerHypermediaTypes(WebClient webClient) {
return webClient.mutate().exchangeStrategies(hypermediaExchangeStrategies()).build();
}
}
this
public WebClient registerHypermediaTypes(WebClient webClient) {
return webClient.mutate().exchangeStrategies(hypermediaExchangeStrategies()).build();
}
overrides the existing exchangeStrategies
, which results in
org.springframework.web.reactive.function.UnsupportedMediaTypeException: Content type 'text/plain;charset=UTF-8' not supported for bodyType=org.springframework.core.io.buffer.DataBuffer
when working with Sleuth.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Customize Spring WebClient with WebClientCustomizer
This overrides the default singleton scope to use the prototype scope. Spring won't share instances of these beans among the application like ...
Read more >WebClient.Builder (Spring Framework 6.0.2 API)
Provide an ExchangeFunction pre-configured with ClientHttpConnector and ExchangeStrategies . This is an alternative to, and effectively overrides ...
Read more >Spring boot Webclient's retrieve vs exchange - Stack Overflow
I have started using WebClient in my Spring boot project recently. Can somebody throw some light on the differences/usages between exchange ...
Read more >Guide to Retry in Spring WebFlux - Baeldung
The Spring WebClient provides a few techniques out of the box for retrying ... retry behaviour with a few additional configuration options.
Read more >WebClient.Builder (spring-webflux 5.1.0.RELEASE API)
Configure a base URL for requests performed through the client. ... a consumer to modify every request being built just before the call...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’ve upgraded to Spring Framework 5.2 snapshots for #919, feel free to prepare the necessary changes.
Resolved via https://github.com/spring-projects/spring-hateoas/commit/fc3767b90ba0049017753caf0d1411c57464ef79.