question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WebClientConfigurer overrides exchange strategies

See original GitHub issue

Not 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:closed
  • Created 5 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
odrotbohmcommented, Mar 22, 2019

I’ve upgraded to Spring Framework 5.2 snapshots for #919, feel free to prepare the necessary changes.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found