Feign: Why is there no response interceptor?

Created on 30 Nov 2019  ·  4Comments  ·  Source: OpenFeign/feign

In my project, I use the request interceptor to sign the request. I thought that there would be a corresponding response interceptor to verify the signature, but I didn't find it. Is there a better way?

feedback provided

Most helpful comment

Short answer is cause nobody implemented it.

As workaround, you could use a customized decoded to validate your response and then delegate decoding to whatever decoder you need.

All 4 comments

Short answer is cause nobody implemented it.

As workaround, you could use a customized decoded to validate your response and then delegate decoding to whatever decoder you need.

I also could use a response interceptor: my use case is to capture some response headers and run some logic on them, possibly only if the response is successful (e.g. only when the status is 200 and the decoding throws no exceptions).

What would be the appropriate place to do such change, design-wise?
Maybe in SynchronousMethodHandler.executeAndDecode(...), right after the decoder runs the method decoder.decode(response, metadata.returnType());?
(I am not considering the asyncResponseHandler because it's marked as @Experimental)

@Experimental is just for the sake of informing API may change in a unpredictable way and break compatibility between minor releases.

Just to give us a little extra flexibility =)

So, RequestInterceptor happens right after encoder and before client is invoked...
ResponseInterceptor then would happen after client, before decoder. So yes, SynchronousMethodHandler.executeAndDecode seems to be the right place, just not after decoder, but before.

Now, what are you trying to do that you can't do by chain decoders?

class MyResponseValidatorDecoder implements Decoder {
  private final Decoder realDecoder; //populated by constructor

  // inside decode method
{
  if(response.getStatus() == 302) return new RedirectObject(response);
  return realDecoder.decode();
}

}

//usage
FeignBuilder.decoder(new MyResponseValidatorDecoder(new JacksonDecoder()));

How can i send another request when response in some status, and then retry request.

The steps like this.

request: biz -> reponse: access_token expire -> request: refresh access_token ->request: retry biz

Was this page helpful?
0 / 5 - 0 ratings

Related issues

why168 picture why168  ·  5Comments

firebook picture firebook  ·  5Comments

michmzr picture michmzr  ·  4Comments

nmaoez picture nmaoez  ·  3Comments

neketsushonen picture neketsushonen  ·  3Comments