From 9e51c65d7ebc9ee12533b01292b4c417f9b581fd Mon Sep 17 00:00:00 2001 From: NikhilMM89 <117143852+NikhilMM89@users.noreply.github.com> Date: Wed, 28 Jun 2023 11:17:31 -0700 Subject: [PATCH 1/4] Update LoggingFilter.java Added a log to view incoming body --- src/main/java/ca/bc/gov/iamp/bcparis/filter/LoggingFilter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ca/bc/gov/iamp/bcparis/filter/LoggingFilter.java b/src/main/java/ca/bc/gov/iamp/bcparis/filter/LoggingFilter.java index 72bec2b5..179c8f41 100644 --- a/src/main/java/ca/bc/gov/iamp/bcparis/filter/LoggingFilter.java +++ b/src/main/java/ca/bc/gov/iamp/bcparis/filter/LoggingFilter.java @@ -24,7 +24,7 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha HttpRequestWrapper copiedRequest = new HttpRequestWrapper((HttpServletRequest) request); Layer7Message l7message; - + log.info("request body: " + copiedRequest.getRequestBody().toString()); // Message parsing try { From d6e2d4688d6875559a92503c1e6241fc5f076f84 Mon Sep 17 00:00:00 2001 From: NikhilMM89 <117143852+NikhilMM89@users.noreply.github.com> Date: Wed, 28 Jun 2023 11:25:44 -0700 Subject: [PATCH 2/4] Update LoggingFilter.java --- src/main/java/ca/bc/gov/iamp/bcparis/filter/LoggingFilter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ca/bc/gov/iamp/bcparis/filter/LoggingFilter.java b/src/main/java/ca/bc/gov/iamp/bcparis/filter/LoggingFilter.java index 179c8f41..b05b2126 100644 --- a/src/main/java/ca/bc/gov/iamp/bcparis/filter/LoggingFilter.java +++ b/src/main/java/ca/bc/gov/iamp/bcparis/filter/LoggingFilter.java @@ -24,7 +24,7 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha HttpRequestWrapper copiedRequest = new HttpRequestWrapper((HttpServletRequest) request); Layer7Message l7message; - log.info("request body: " + copiedRequest.getRequestBody().toString()); + log.info("request body: " + copiedRequest.getRequestBodyAsString()); // Message parsing try { From 7d7d9bca837b386062826adbe5276d148cba4aa3 Mon Sep 17 00:00:00 2001 From: NikhilMM89 <117143852+NikhilMM89@users.noreply.github.com> Date: Wed, 28 Jun 2023 11:45:50 -0700 Subject: [PATCH 3/4] Update LoggingFilter.java --- .../gov/iamp/bcparis/filter/LoggingFilter.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main/java/ca/bc/gov/iamp/bcparis/filter/LoggingFilter.java b/src/main/java/ca/bc/gov/iamp/bcparis/filter/LoggingFilter.java index b05b2126..99e73e4a 100644 --- a/src/main/java/ca/bc/gov/iamp/bcparis/filter/LoggingFilter.java +++ b/src/main/java/ca/bc/gov/iamp/bcparis/filter/LoggingFilter.java @@ -27,14 +27,17 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha 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"); From 53f56328626a9a01f22cf8200a588c98e6c978ef Mon Sep 17 00:00:00 2001 From: NikhilMM89 <117143852+NikhilMM89@users.noreply.github.com> Date: Wed, 28 Jun 2023 12:02:45 -0700 Subject: [PATCH 4/4] Update LoggingFilter.java modified the code to only parse the incoming request incase the request method is not GET. Because GET request don't have any body content. There fore parsing an empty body is throwing an exception. continuous triggering of GET request is due to liveness probe configure at OCP. --- .../java/ca/bc/gov/iamp/bcparis/filter/LoggingFilter.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/ca/bc/gov/iamp/bcparis/filter/LoggingFilter.java b/src/main/java/ca/bc/gov/iamp/bcparis/filter/LoggingFilter.java index 99e73e4a..e3057d4d 100644 --- a/src/main/java/ca/bc/gov/iamp/bcparis/filter/LoggingFilter.java +++ b/src/main/java/ca/bc/gov/iamp/bcparis/filter/LoggingFilter.java @@ -24,11 +24,11 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha HttpRequestWrapper copiedRequest = new HttpRequestWrapper((HttpServletRequest) request); Layer7Message l7message; - log.info("request body: " + copiedRequest.getRequestBodyAsString()); + //log.info("request body: " + copiedRequest.getRequestBodyAsString()); // Message parsing try { HttpServletRequest req = (HttpServletRequest) request; - log.info("Request Method : " + req.getMethod().trim()); + //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);