We are integrating with a third party that is sending xml with the content-type header as text/html. We were planning on using Spring\'s RestTemplate to map it to classes we
I did not see an example posted of how to actually do this with a custom interceptor, so here is one for reference sake:
public class MyXmlInterceptor implements ClientHttpRequestInterceptor {
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
ClientHttpResponse response = execution.execute(request, body);
HttpHeaders headers = response.getHeaders();
// you'd want to check if the value needs to be changed
if (headers.containsKey("Content-Type")) {
headers.remove("Content-Type");
}
headers.add("Content-Type", "application/xml");
return response;
}
Then, you would need to add the interceptor to your RestTemplate object:
RestTemplate t = new RestTemplate();
t.getInterceptors().add(new MyXmlInterceptor());