incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1532326 - in /sling/trunk/contrib/extensions/slf4j-mdc/src/main/java/org/apache/sling/extensions/mdc/internal: MDCInsertingFilter.java SlingMDCFilter.java
Date Tue, 15 Oct 2013 13:24:55 GMT
Author: bdelacretaz
Date: Tue Oct 15 13:24:54 2013
New Revision: 1532326

URL: http://svn.apache.org/r1532326
Log:
SLING-3048 - remove JCR session info from MDC, contributed by Chetan Mehrotra, thanks!

Modified:
    sling/trunk/contrib/extensions/slf4j-mdc/src/main/java/org/apache/sling/extensions/mdc/internal/MDCInsertingFilter.java
    sling/trunk/contrib/extensions/slf4j-mdc/src/main/java/org/apache/sling/extensions/mdc/internal/SlingMDCFilter.java

Modified: sling/trunk/contrib/extensions/slf4j-mdc/src/main/java/org/apache/sling/extensions/mdc/internal/MDCInsertingFilter.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/slf4j-mdc/src/main/java/org/apache/sling/extensions/mdc/internal/MDCInsertingFilter.java?rev=1532326&r1=1532325&r2=1532326&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/slf4j-mdc/src/main/java/org/apache/sling/extensions/mdc/internal/MDCInsertingFilter.java
(original)
+++ sling/trunk/contrib/extensions/slf4j-mdc/src/main/java/org/apache/sling/extensions/mdc/internal/MDCInsertingFilter.java
Tue Oct 15 13:24:54 2013
@@ -116,34 +116,34 @@ public class MDCInsertingFilter implemen
     }
 
     private void insertIntoMDC(ServletRequest request) {
-        MDC.put(REQUEST_REMOTE_HOST_MDC_KEY, request.getRemoteHost());
+        nullSafePut(REQUEST_REMOTE_HOST_MDC_KEY, request.getRemoteHost());
 
         if (request instanceof HttpServletRequest) {
             HttpServletRequest httpRequest = (HttpServletRequest) request;
-            MDC.put(REQUEST_REQUEST_URI, httpRequest.getRequestURI());
+            nullSafePut(REQUEST_REQUEST_URI, httpRequest.getRequestURI());
 
             StringBuffer requestURL = httpRequest.getRequestURL();
             if (requestURL != null) {
-                MDC.put(REQUEST_REQUEST_URL, requestURL.toString());
+                nullSafePut(REQUEST_REQUEST_URL, requestURL.toString());
             }
 
-            MDC.put(REQUEST_QUERY_STRING, httpRequest.getQueryString());
-            MDC.put(REQUEST_USER_AGENT_MDC_KEY, httpRequest.getHeader("User-Agent"));
-            MDC.put(REQUEST_X_FORWARDED_FOR, httpRequest.getHeader("X-Forwarded-For"));
+            nullSafePut(REQUEST_QUERY_STRING, httpRequest.getQueryString());
+            nullSafePut(REQUEST_USER_AGENT_MDC_KEY, httpRequest.getHeader("User-Agent"));
+            nullSafePut(REQUEST_X_FORWARDED_FOR, httpRequest.getHeader("X-Forwarded-For"));
 
             for(String paramName : parameterNames){
-                MDC.put(paramName,httpRequest.getParameter(paramName));
+                nullSafePut(paramName,httpRequest.getParameter(paramName));
             }
 
             for(String headerName :headerNames){
-                MDC.put(headerName, httpRequest.getHeader(headerName));
+                nullSafePut(headerName, httpRequest.getHeader(headerName));
             }
 
             Cookie[] cookies = httpRequest.getCookies();
             if(cookies != null){
                 for(Cookie c : cookies){
                     if(cookieNames.contains(c.getName())){
-                        MDC.put(c.getName(),c.getValue());
+                        nullSafePut(c.getName(),c.getValue());
                     }
                 }
             }
@@ -211,6 +211,12 @@ public class MDCInsertingFilter implemen
         }
     }
 
+    private void nullSafePut(String key,String value){
+        if(key != null && value != null){
+            MDC.put(key,value);
+        }
+    }
+
     private static Set<String> toTrimmedValues(Map<String,Object> config,String
propName){
         String[] values = PropertiesUtil.toStringArray(config.get(propName),EMPTY_VALUE);
         Set<String> result = new HashSet<String>(values.length);

Modified: sling/trunk/contrib/extensions/slf4j-mdc/src/main/java/org/apache/sling/extensions/mdc/internal/SlingMDCFilter.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/slf4j-mdc/src/main/java/org/apache/sling/extensions/mdc/internal/SlingMDCFilter.java?rev=1532326&r1=1532325&r2=1532326&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/slf4j-mdc/src/main/java/org/apache/sling/extensions/mdc/internal/SlingMDCFilter.java
(original)
+++ sling/trunk/contrib/extensions/slf4j-mdc/src/main/java/org/apache/sling/extensions/mdc/internal/SlingMDCFilter.java
Tue Oct 15 13:24:54 2013
@@ -37,7 +37,6 @@ class SlingMDCFilter implements Filter {
 
     private static final String[] DEFAULT_KEY_NAMES = {
             SLING_USER,
-            JCR_SESSION_ID
     };
 
     public void init(FilterConfig filterConfig) throws ServletException {
@@ -67,11 +66,6 @@ class SlingMDCFilter implements Filter {
         if(rr.getUserID() != null){
             MDC.put(SLING_USER,rr.getUserID());
         }
-
-        Session session = rr.adaptTo(Session.class);
-        if(session != null){
-            MDC.put(JCR_SESSION_ID,session.toString());
-        }
     }
 
     public void destroy() {



Mime
View raw message