Skip to content

Commit

Permalink
Merge pull request #314 from bcgov/BCPARIS-28
Browse files Browse the repository at this point in the history
Bcparis 28
  • Loading branch information
NikhilMM89 authored Jul 11, 2023
2 parents 36d3c60 + 53f5632 commit f0f57c4
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/main/java/ca/bc/gov/iamp/bcparis/filter/LoggingFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,20 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha

HttpRequestWrapper copiedRequest = new HttpRequestWrapper((HttpServletRequest) request);
Layer7Message l7message;

//log.info("request body: " + copiedRequest.getRequestBodyAsString());
// Message parsing
try {

l7message = new ObjectMapper().readValue(copiedRequest.getRequestBody(), Layer7Message.class);
if (l7message != null) {
MDC.put(MDC_MESSAGE_ID_KEY, l7message.getEnvelope().getMqmd().getMessageIdByte());
MDC.put(MDC_CORRELATION_ID_KEY, l7message.getEnvelope().getMqmd().getCorrelationIdByte());
MDC.put(MDC_DATA_KEY, String.format("[msgId:%s, corlId:%s]", l7message.getEnvelope().getMqmd().getMessageIdByte(), l7message.getEnvelope().getMqmd().getCorrelationIdByte()));
HttpServletRequest req = (HttpServletRequest) request;
//log.info("Request Method : " + req.getMethod().trim());
if (!req.getMethod().trim().equalsIgnoreCase("GET")) {
/* GET request means no request body, so parsing will fail */
l7message = new ObjectMapper().readValue(copiedRequest.getRequestBody(), Layer7Message.class);
if (l7message != null) {
MDC.put(MDC_MESSAGE_ID_KEY, l7message.getEnvelope().getMqmd().getMessageIdByte());
MDC.put(MDC_CORRELATION_ID_KEY, l7message.getEnvelope().getMqmd().getCorrelationIdByte());
MDC.put(MDC_DATA_KEY, String.format("[msgId:%s, corlId:%s]", l7message.getEnvelope().getMqmd().getMessageIdByte(), l7message.getEnvelope().getMqmd().getCorrelationIdByte()));
}
}

chain.doFilter(copiedRequest, response);
} catch (Exception ex) {
log.warn("Failed to parse request body at logging filter");
Expand Down

0 comments on commit f0f57c4

Please sign in to comment.