Search code examples
xmlspring-integrationspring-webfluxreactivedeclarative

How to add HttpMessageWriter<> to webflux outbound-gateway


Thanks for the pointers for adding the codec-configurer attribute to a webflux:inbound-gateway component. answer to previous question

That works pretty well.

I was expecting something similar for the webflux:outbound-gateway component but I haven't been able to find the equivalent of codec-configurer for that component, nor for the component used in the web-client attribute. Would there be an example of such a thing? Or, perhaps, instead, is there a way of adding my custom codec-configurer to the default list, hence obviating the additional codec-configurer?

Thanks for any new pointers.


Solution

  • That configuration is a part of the WebClient you can inject to this gateway. See its builder:

        /**
         * Configure the codecs for the {@code WebClient} in the
         * {@link #exchangeStrategies(ExchangeStrategies) underlying}
         * {@code ExchangeStrategies}.
         * @param configurer the configurer to apply
         * @since 5.1.13
         */
        Builder codecs(Consumer<ClientCodecConfigurer> configurer);
    

    And docs: https://docs.spring.io/spring-framework/docs/current/reference/html/web-reactive.html#webflux-client-builder

    Essentially this is the code you need to follow:

               WebClient.builder()
                        .codecs(clientCodecConfigurer -> clientCodecConfigurer
                                .customCodecs()
                                .register())