[logback-dev] svn commit: r1609 - in logback/trunk/logback-access/src: main/java/ch/qos/logback/access/spi test/java/ch/qos/logback/access/dummy test/java/ch/qos/logback/access/spi

noreply.ceki at qos.ch noreply.ceki at qos.ch
Fri Jan 25 12:21:20 CET 2008


Author: ceki
Date: Fri Jan 25 12:21:19 2008
New Revision: 1609

Modified:
   logback/trunk/logback-access/src/main/java/ch/qos/logback/access/spi/AccessEvent.java
   logback/trunk/logback-access/src/test/java/ch/qos/logback/access/dummy/DummyResponse.java
   logback/trunk/logback-access/src/test/java/ch/qos/logback/access/spi/AccessEventTest.java

Log:
- bug 109 (corrected, with test case showing correct survival of AccessEvent fields values)
  

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	Fri Jan 25 12:21:19 2008
@@ -2,7 +2,6 @@
 
 import java.io.Serializable;
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.List;
@@ -40,7 +39,7 @@
 
   private transient final HttpServletRequest httpRequest;
   private transient final HttpServletResponse httpResponse;
-  
+
   String requestURI;
   String requestURL;
   String remoteHost;
@@ -55,7 +54,7 @@
   Map<String, String> requestHeaderMap;
   Map<String, String[]> requestParameterMap;
   Map<String, String> responseHeaderMap;
-  
+
   long contentLength = SENTINEL;
   int statusCode = SENTINEL;
   int localPort = SENTINEL;
@@ -226,7 +225,7 @@
       return list.elements();
     }
     return httpRequest.getHeaderNames();
-    
+
   }
 
   public Map<String, String> getRequestHeaderMap() {
@@ -427,35 +426,30 @@
   }
 
   public String getResponseHeader(String key) {
-    synchronized (responseHeaderMap) {
-      if (responseHeaderMap == null) {
-        responseHeaderMap = serverAdapter.builResponseHeaderMap();
-      }
-      return responseHeaderMap.get(key);
+    buildResponseHeaderMap();
+    return responseHeaderMap.get(key);
+  }
+
+  void buildResponseHeaderMap() {
+    if (responseHeaderMap == null) {
+      responseHeaderMap = serverAdapter.builResponseHeaderMap();
     }
   }
 
   public Map<String, String> getResponseHeaderMap() {
-    synchronized (responseHeaderMap) {
-      if (responseHeaderMap == null) {
-        responseHeaderMap = serverAdapter.builResponseHeaderMap();
-      }
-      return responseHeaderMap;
-    }
+    buildResponseHeaderMap();
+    return responseHeaderMap;
   }
 
   public List<String> getResponseHeaderNameList() {
-    synchronized (responseHeaderMap) {
-      if (responseHeaderMap == null) {
-        responseHeaderMap = serverAdapter.builResponseHeaderMap();
-      }
-      return new ArrayList<String>(responseHeaderMap.keySet());
-    }
+    buildResponseHeaderMap();
+    return new ArrayList<String>(responseHeaderMap.keySet());
   }
-  
+
   public void prepareForDeferredProcessing() {
     buildRequestHeaderMap();
     buildRequestParameterMap();
+    buildResponseHeaderMap();
     getLocalPort();
     getMethod();
     getProtocol();

Modified: logback/trunk/logback-access/src/test/java/ch/qos/logback/access/dummy/DummyResponse.java
==============================================================================
--- logback/trunk/logback-access/src/test/java/ch/qos/logback/access/dummy/DummyResponse.java	(original)
+++ logback/trunk/logback-access/src/test/java/ch/qos/logback/access/dummy/DummyResponse.java	Fri Jan 25 12:21:19 2008
@@ -12,17 +12,23 @@
 
 public class DummyResponse implements HttpServletResponse {
 
-  int status;
+  public static final int DUMMY_DEFAULT_STATUS = 200;
+  public static final int DUMMY_DEFAULT_CONTENT_COUNT = 1000;
+  public static final Map<String, String> DUMMY_DEFAULT_HDEADER_MAP = new HashMap<String, String>();;
+  
+  static {
+    DUMMY_DEFAULT_HDEADER_MAP.put("headerName1", "headerValue1");
+    DUMMY_DEFAULT_HDEADER_MAP.put("headerName2", "headerValue2");
+  }
+  
+  int status = DUMMY_DEFAULT_STATUS ;
   public Map<String, String> headerMap;
   
   public DummyResponse() {
-    headerMap = new HashMap<String, String>();
-    headerMap.put("headerName1", "headerValue1");
-    headerMap.put("headerName2", "headerValue2");
+    headerMap = DUMMY_DEFAULT_HDEADER_MAP;
   }
 
   public void addCookie(Cookie arg0) {
-
   }
 
   public void addDateHeader(String arg0, long arg1) {
@@ -132,7 +138,7 @@
   }
   
   public long getContentCount() {
-    return 10000L;
+    return DUMMY_DEFAULT_CONTENT_COUNT;
   }
   
   public int getStatus() {

Modified: logback/trunk/logback-access/src/test/java/ch/qos/logback/access/spi/AccessEventTest.java
==============================================================================
--- logback/trunk/logback-access/src/test/java/ch/qos/logback/access/spi/AccessEventTest.java	(original)
+++ logback/trunk/logback-access/src/test/java/ch/qos/logback/access/spi/AccessEventTest.java	Fri Jan 25 12:21:19 2008
@@ -8,10 +8,12 @@
 
 import junit.framework.TestCase;
 import ch.qos.logback.access.dummy.DummyAccessEventBuilder;
+import ch.qos.logback.access.dummy.DummyResponse;
 
 public class AccessEventTest extends TestCase {
 
-  private Object buildSerializedAccessEvent() throws IOException, ClassNotFoundException{
+  private Object buildSerializedAccessEvent() throws IOException,
+      ClassNotFoundException {
     ByteArrayOutputStream baos = new ByteArrayOutputStream();
     ObjectOutputStream oos = new ObjectOutputStream(baos);
     AccessEvent ae = DummyAccessEventBuilder.buildNewAccessEvent();
@@ -26,19 +28,23 @@
     return ois.readObject();
   }
 
-  
   public void testSerialization() throws IOException, ClassNotFoundException {
     Object o = buildSerializedAccessEvent();
     assertNotNull(o);
     AccessEvent aeBack = (AccessEvent) o;
 
-    aeBack.getRequestHeaderNames();
-    aeBack.getResponseHeader("x");
-    aeBack.getResponseHeaderNameList();
-    aeBack.getContentLength();
-    aeBack.getStatusCode();
-    
-    
+    assertEquals(DummyResponse.DUMMY_DEFAULT_HDEADER_MAP, aeBack
+        .getResponseHeaderMap());
+    assertEquals(DummyResponse.DUMMY_DEFAULT_HDEADER_MAP.get("x"), aeBack
+        .getResponseHeader("x"));
+    assertEquals(DummyResponse.DUMMY_DEFAULT_HDEADER_MAP.get("headerName1"),
+        aeBack.getResponseHeader("headerName1"));
+    assertEquals(DummyResponse.DUMMY_DEFAULT_HDEADER_MAP.size(), aeBack
+        .getResponseHeaderNameList().size());
+    assertEquals(DummyResponse.DUMMY_DEFAULT_CONTENT_COUNT, aeBack
+        .getContentLength());
+    assertEquals(DummyResponse.DUMMY_DEFAULT_STATUS, aeBack.getStatusCode());
+
   }
 
 }



More information about the logback-dev mailing list