Skip to content

Instantly share code, notes, and snippets.

@khandar-william
Created July 23, 2020 08:15
Show Gist options
  • Save khandar-william/fede32e497321429f089833ccb488458 to your computer and use it in GitHub Desktop.
Save khandar-william/fede32e497321429f089833ccb488458 to your computer and use it in GitHub Desktop.
// RestTemplate interceptor
public class CustomRequestInterceptor implements ClientHttpRequestInterceptor {
@Override
public ClientHttpResponse intercept(
final HttpRequest request,
final byte[] body,
final ClientHttpRequestExecution execution
) throws IOException {
log.info("INTERCEPT {} {} {} body {}", request.getMethodValue(), request.getURI(), request.getHeaders(),
body);
final ClientHttpResponse response = execution.execute(request, body);
return response;
}
}
// Use:
// restTemplate.getInterceptors().add(new CustomRequestInterceptor());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment