You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 09:33:46 UTC
[sling-org-apache-sling-extensions-slf4j-mdc] 02/07: SLING-3048 -
remove JCR session info from MDC, contributed by Chetan Mehrotra, thanks!
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.extensions.slf4j.mdc-1.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-extensions-slf4j-mdc.git
commit 0c9dba304f08461a8ec4f33a62bdbe56a4b1fcf1
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Tue Oct 15 13:24:54 2013 +0000
SLING-3048 - remove JCR session info from MDC, contributed by Chetan Mehrotra, thanks!
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/slf4j-mdc@1532326 13f79535-47bb-0310-9956-ffa450edef68
---
.../mdc/internal/MDCInsertingFilter.java | 24 ++++++++++++++--------
.../extensions/mdc/internal/SlingMDCFilter.java | 6 ------
2 files changed, 15 insertions(+), 15 deletions(-)
diff --git a/src/main/java/org/apache/sling/extensions/mdc/internal/MDCInsertingFilter.java b/src/main/java/org/apache/sling/extensions/mdc/internal/MDCInsertingFilter.java
index 3f68a90..fcb8145 100644
--- a/src/main/java/org/apache/sling/extensions/mdc/internal/MDCInsertingFilter.java
+++ b/src/main/java/org/apache/sling/extensions/mdc/internal/MDCInsertingFilter.java
@@ -116,34 +116,34 @@ public class MDCInsertingFilter implements Filter {
}
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 implements Filter {
}
}
+ 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);
diff --git a/src/main/java/org/apache/sling/extensions/mdc/internal/SlingMDCFilter.java b/src/main/java/org/apache/sling/extensions/mdc/internal/SlingMDCFilter.java
index 9b3044b..1b3c1a5 100644
--- a/src/main/java/org/apache/sling/extensions/mdc/internal/SlingMDCFilter.java
+++ b/src/main/java/org/apache/sling/extensions/mdc/internal/SlingMDCFilter.java
@@ -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() {
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.