From 96559522aa4b37859518f354c387b1e14e136288 Mon Sep 17 00:00:00 2001 From: ajaypj Date: Wed, 7 Aug 2024 18:39:57 +0530 Subject: [PATCH] null check for content length (#83) --------- Co-authored-by: Kinshuk Bairagi --- .../flipkart/gjex/core/filter/http/AccessLogHttpFilter.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/com/flipkart/gjex/core/filter/http/AccessLogHttpFilter.java b/core/src/main/java/com/flipkart/gjex/core/filter/http/AccessLogHttpFilter.java index 5de28c7c..c4da84b9 100644 --- a/core/src/main/java/com/flipkart/gjex/core/filter/http/AccessLogHttpFilter.java +++ b/core/src/main/java/com/flipkart/gjex/core/filter/http/AccessLogHttpFilter.java @@ -10,6 +10,7 @@ import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletResponse; import java.util.Map; +import java.util.Optional; /** * Implements an HTTP filter for logging access requests. This filter captures and logs @@ -81,8 +82,9 @@ public void doProcessResponse(ServletResponse response) { HttpServletResponse httpServletResponse = (HttpServletResponse) response; if (isSuccess(httpServletResponse.getStatus())) { // 2xx response - accessLogContextBuilder.contentLength(Integer.valueOf(httpServletResponse - .getHeader(HttpHeaderNames.CONTENT_LENGTH.toString()))); + int contentLength = Optional.ofNullable(httpServletResponse.getHeader(HttpHeaderNames.CONTENT_LENGTH.toString())) + .map(Integer::parseInt).orElse(0); + accessLogContextBuilder.contentLength(contentLength); } else { // non-2xx response accessLogContextBuilder.contentLength(0);