Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FeignClientFactoryBean does not provide a way to register a ResponseMapper #433

Open
celdridge91190 opened this issue Nov 24, 2020 · 5 comments
Labels
enhancement New feature or request

Comments

@celdridge91190
Copy link

celdridge91190 commented Nov 24, 2020

Feign provides an interface called ResponseMapper which allows you to do processing on a response before it is decoding. This is a useful extension for pre-processing things such as response headers without having to embed logic into your decoder. The FeignClientFactoryBean does not allow a mechanism to add one which forces consumers to abandon the auto configured feign client functionality and manually create the Feign client if they choose to take advantage of that feature. This request is simply to optionally allow a ResponseMapper to be exposed and included in the Feign client.

@ryanjbaxter
Copy link
Contributor

I think that using this customizer might give you the flexibility that you need

#289

Unfortunately it is only available in the 2020.0 milestones at the moment. Maybe you could try the milestone build and let us know if it works for you? Then we can consider backporting it into Hoxton.

@OlgaMaciaszek
Copy link
Collaborator

I have actually already backported that to Hoxton: #436. Please let us know if that can solve your issue.

@celdridge91190
Copy link
Author

celdridge91190 commented Dec 7, 2020 via email

@ryanjbaxter
Copy link
Contributor

@celdridge91190 not yet it will be in Hoxton.SR10

@aaronjwhiteside
Copy link
Contributor

The FeignBuilderCustomizer won't really help here. As the current method to set a ResponseMapper ( Feign.Builder.mapAndDecode(ResponseMapper mapper, Decoder decoder)) requires the Decoder.

This really needs to be handled in the FeignClientFactoryBean class.

Also it would be nice if Spring Cloud OpenFeign supplied a CompositeResponseMapper so that multiple ResponseMapper beans could be sourced, ordered and invoked in sequence.

As a workaround I currently have this in my @FeignClient(configuration=...) class.

    /**
     * Hack to work around the fact that Spring Cloud OpenFeign does not support any way to set a ResponseMapper.
     */
    @Bean
    public Decoder decoder(final ResponseMapper responseMapper, final ObjectFactory<HttpMessageConverters> messageConverters) {
        // this is the default decoder as per FeignClientsConfiguration#feignDecoder
        final Decoder defaultDecoder = new OptionalDecoder(
                new ResponseEntityDecoder(new SpringDecoder(messageConverters)));

        // here we delegate to the ResponseMapper before calling decode()
        return (response, type) -> defaultDecoder.decode(responseMapper.map(response, type), type);
    }

This essentially replicates what Feign.Builder.mapAndDecode() does.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants