I have a Feign client, which has code like this
private final HttpResponseLoggingInterceptor httpResponseLoggingInterceptor;
private final HttpRequestLoggingInterceptor httpRequestLoggingInterceptor;
...
httpClientBuilder.addInterceptorLast(httpRequestLoggingInterceptor);
httpClientBuilder.addInterceptorLast(httpResponseLoggingInterceptor);
return new ApacheHttpClient(httpClientBuilder.build());
My HttpResponseLoggingInterceptor is
@Component
public class HttpResponseLoggingInterceptor implements HttpResponseInterceptor {
private static final Log LOG = LogFactory.getLog(HttpResponseLoggingInterceptor.class);
@Override
public void process(HttpResponse httpResponse, HttpContext httpContext) {
try {
String message =
buildStatus(httpResponse) + buildHeaders(httpResponse.getAllHeaders()) + buildEntity(httpResponse);
LOG.info(message);
} catch (Exception e) {
LOG.error("Error in logging the message", e);
}
}
private String buildStatus(HttpResponse response) {
return "Response - " + response.getStatusLine().getStatusCode() + " " +
response.getStatusLine().getReasonPhrase() + " ";
}
private String buildHeaders(Header[] headers) {
return "Headers: [" +
Arrays.stream(headers).map(header -> header.getName() + ": " + header.getValue())
.collect(Collectors.joining(", ")) + "] ";
}
private String buildEntity(HttpResponse httpResponse) throws IOException {
try (BufferedReader buffer = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent()))) {
String payload = buffer.lines().collect(Collectors.joining(""));
httpResponse.setEntity(new StringEntity(payload));
return "Payload: " + payload;
}
}
}
I have an HttpRequestLoggingInterceptor very similar. In my spring boot integration test, I see both request and response getting logged. However, in our open-shift cluster, the log in the HttpResponseLoggingInterceptor is not getting logged, so I can’t get the actual response. I’m unable to replicate in my integration test. I am baffled, is there anything that I’m doing wrong?
Both request and response are log.info(..);
, we have enabled info logging across all packages, so not blocked there.