diff --git a/cf-java-logging-support-servlet/src/main/java/com/sap/hcp/cf/logging/servlet/filter/AddHttpHeadersToLogContextFilter.java b/cf-java-logging-support-servlet/src/main/java/com/sap/hcp/cf/logging/servlet/filter/AddHttpHeadersToLogContextFilter.java index 66c4f99..cbf4ccd 100644 --- a/cf-java-logging-support-servlet/src/main/java/com/sap/hcp/cf/logging/servlet/filter/AddHttpHeadersToLogContextFilter.java +++ b/cf-java-logging-support-servlet/src/main/java/com/sap/hcp/cf/logging/servlet/filter/AddHttpHeadersToLogContextFilter.java @@ -6,7 +6,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; -import java.util.Objects; import java.util.stream.Stream; import javax.servlet.http.HttpServletRequest; @@ -23,8 +22,8 @@ */ public class AddHttpHeadersToLogContextFilter extends AbstractLoggingFilter { - private List headers; - private List fields; + private final List headers; + private final List fields; /** * The default constructor uses {@link HttpHeaders#propagated()} to define @@ -53,16 +52,16 @@ public AddHttpHeadersToLogContextFilter(HttpHeader... headers) { */ public AddHttpHeadersToLogContextFilter(List list, HttpHeader... custom) { Stream allHeaders = Stream.concat(list.stream(), Arrays.stream(custom)); - this.headers = unmodifiableList(allHeaders.filter(HttpHeader::isPropagated).collect(toList())); - this.fields = unmodifiableList(headers.stream().map(HttpHeader::getField).filter(Objects::nonNull).collect( - toList())); + this.headers = unmodifiableList(allHeaders + .filter(HttpHeader::isPropagated).filter(h -> h.getField() != null).collect(toList())); + this.fields = unmodifiableList(headers.stream().map(HttpHeader::getField).collect(toList())); } @Override protected void beforeFilter(HttpServletRequest request, HttpServletResponse response) { for (HttpHeader header: headers) { String headerValue = HttpHeaderUtilities.getHeaderValue(request, header); - if (header.getField() != null && headerValue != null) { + if (headerValue != null) { LogContext.add(header.getField(), headerValue); } }