0

My Requirement is to Add some header in a interceptor on all requests coming via RestTemplate so I am using a ClientHttpRequestInterceptor But I also need to add all params encoaded in header but in this interceptor we get HTTPREQUEST Object which do not have any way to get Params

I have tried using HandlerInterceptorAdapter which gives me HttpServletRequest to do all I need but I can' set this interceptor in restTemplate.setInterceptors

public class RequestResponseInterceptor implements ClientHttpRequestInterceptor {

@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution)
        throws IOException {
    // Add additional headers
    addRequestHeaders(request);
    return execution.execute(request, body);
}

but in addRequestHeaders how to get param from request ?

1 Answers1

0
You can add custom header like below...

@Override
public ClientHttpResponse intercept(
  HttpRequest request, 
  byte[] body, 
  ClientHttpRequestExecution execution) throws IOException {

    ClientHttpResponse response = execution.execute(request, body);
    response.getHeaders().add("Foo", "bar");
    return response;
}
brijesh
  • 760
  • 6
  • 4
  • Thanks for replying but My issue is not that I need to add header in request and I am able to do that but my problem is in one header I need to add Encoaded parameters of request so how to get parameters here from request Object ? – Rohit Saxena Jul 29 '19 at 20:41
  • addAll(MultiValueMap values) – brijesh Jul 31 '19 at 19:38