[logback-dev] svn commit: r1605 - in logback/trunk/logback-access/src/main/java/ch/qos/logback/access: pattern spi

noreply.ceki at qos.ch noreply.ceki at qos.ch
Wed Jan 23 10:52:20 CET 2008


Author: ceki
Date: Wed Jan 23 10:52:19 2008
New Revision: 1605

Modified:
   logback/trunk/logback-access/src/main/java/ch/qos/logback/access/pattern/RequestParameterConverter.java
   logback/trunk/logback-access/src/main/java/ch/qos/logback/access/spi/AccessEvent.java

Log:
- request parameters can be multi-valued as observed in bug 110
  http://bugzilla.qos.ch/show_bug.cgi?id=110

Modified: logback/trunk/logback-access/src/main/java/ch/qos/logback/access/pattern/RequestParameterConverter.java
==============================================================================
--- logback/trunk/logback-access/src/main/java/ch/qos/logback/access/pattern/RequestParameterConverter.java	(original)
+++ logback/trunk/logback-access/src/main/java/ch/qos/logback/access/pattern/RequestParameterConverter.java	Wed Jan 23 10:52:19 2008
@@ -1,9 +1,10 @@
 package ch.qos.logback.access.pattern;
 
+import java.util.Arrays;
+
 import ch.qos.logback.access.spi.AccessEvent;
 import ch.qos.logback.core.util.OptionHelper;
 
-
 public class RequestParameterConverter extends AccessConverter {
 
   String key;
@@ -22,7 +23,14 @@
       return "INACTIVE_REQUEST_PARAM_CONV";
     }
 
-    return accessEvent.getRequestParameter(key);
+    String[] paramArray = accessEvent.getRequestParameter(key);
+    if (paramArray.length == 1) {
+      return paramArray[0];
+    } else {
+      // for an array string {"a", "b"} named 'sa', Array.toString(sa) returns the string 
+      // "[a, b]".
+      return Arrays.toString(paramArray);
+    }
   }
 
 }

Modified: logback/trunk/logback-access/src/main/java/ch/qos/logback/access/spi/AccessEvent.java
==============================================================================
--- logback/trunk/logback-access/src/main/java/ch/qos/logback/access/spi/AccessEvent.java	(original)
+++ logback/trunk/logback-access/src/main/java/ch/qos/logback/access/spi/AccessEvent.java	Wed Jan 23 10:52:19 2008
@@ -14,6 +14,8 @@
 import ch.qos.logback.access.pattern.AccessConverter;
 import ch.qos.logback.access.servlet.Util;
 
+// Contributors:  Joern Huxhorn (see also bug #110)
+
 /**
  * The Access module's internal representation of logging events. When the
  * logging component instance is called in the container to log then a
@@ -28,6 +30,8 @@
   private static final long serialVersionUID = -3118194368414470960L;
 
   public final static String NA = "-";
+  public final static String[] NA_STRING_ARRAY = new String[] {AccessEvent.NA};
+  
   public final static String EMPTY = "";
   public static final int SENTINEL = -1;
 
@@ -46,7 +50,7 @@
   String responseContent;
 
   Map<String, String> requestHeaderMap;
-  Map<String, Object> requestParameterMap;
+  Map<String, String[]> requestParameterMap;
 
   long contentLength = SENTINEL;
   int statusCode = SENTINEL;
@@ -235,17 +239,24 @@
   }
 
   public void buildRequestParameterMap() {
-    requestParameterMap = new HashMap<String, Object>();
+    requestParameterMap = new HashMap<String, String[]>();
     Enumeration e = httpRequest.getParameterNames();
     if (e == null) {
       return;
     }
     while (e.hasMoreElements()) {
       String key = (String) e.nextElement();
-      requestParameterMap.put(key, httpRequest.getParameter(key));
+      requestParameterMap.put(key, httpRequest.getParameterValues(key));
     }
   }
 
+  public Map<String, String[]> getRequestParameterMap() {
+    if (requestParameterMap == null) {
+      buildRequestParameterMap();
+    }
+    return requestParameterMap;
+}
+  
   public String getResponseHeader(String key) {
     return serverAdapter.getResponseHeader(key);
   }
@@ -273,16 +284,16 @@
     }
   }
 
-  public String getRequestParameter(String key) {
+  public String[] getRequestParameter(String key) {
     if (httpRequest != null) {
-      Object value = httpRequest.getParameter(key);
+     String[] value = httpRequest.getParameterValues(key);
       if (value == null) {
-        return AccessEvent.NA;
+        return NA_STRING_ARRAY;
       } else {
-        return value.toString();
+        return value;
       }
     } else {
-      return AccessEvent.NA;
+      return NA_STRING_ARRAY;
     }
   }
 



More information about the logback-dev mailing list