[logback-dev] svn commit: r1643 - 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
Thu Mar 13 03:59:19 CET 2008


Author: ceki
Date: Thu Mar 13 03:59:18 2008
New Revision: 1643

Added:
   logback/trunk/logback-access/src/test/java/ch/qos/logback/access/spi/AccessEventSerializationTest.java
      - copied, changed from r1629, /logback/trunk/logback-access/src/test/java/ch/qos/logback/access/spi/AccessEventTest.java
Removed:
   logback/trunk/logback-access/src/test/java/ch/qos/logback/access/spi/AccessEventTest.java
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/DummyRequest.java
   logback/trunk/logback-access/src/test/java/ch/qos/logback/access/spi/PackageTest.java

Log:
- fixing remaining issues with bug 109, in particular NPE thrown for getRequestContent and 
  getResponseContent after serialization. The idea is, as expalined in comment 3, to make a 
  copy of the contents of various httpRequest and httpResponse fields (without serializing 
  httpRequest and httpResponse). Also note many converters in the c.q.l.acces.Pattern package 
  *cannot* deal with null values returned by various get methods in AccessEvent. Thus, it is not
  enough to avoid NPE as accomplished by attachment 21 (dated 2008-01-28 21:39:11) but also to
  return valid values.

Comment 3: http://bugzilla.qos.ch/show_bug.cgi?id=109#c3

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	Thu Mar 13 03:59:18 2008
@@ -29,8 +29,9 @@
  */
 public class AccessEvent implements Serializable {
 
-  private static final long serialVersionUID = -3118194368414470960L;
-
+  
+  private static final long serialVersionUID = 866718993618836343L;
+  
   public final static String NA = "-";
   public final static String[] NA_STRING_ARRAY = new String[] { AccessEvent.NA };
 
@@ -75,10 +76,22 @@
     this.serverAdapter = adapter;
   }
 
+  /**
+   * Returns the underlying HttpServletRequest. After serialization the returned 
+   * value will be null. 
+   * 
+   * @return
+   */
   public HttpServletRequest getRequest() {
     return httpRequest;
   }
 
+  /**
+   * Returns the underlying HttpServletResponse. After serialization the returned 
+   * value will be null. 
+   * 
+   * @return
+   */
   public HttpServletResponse getResponse() {
     return httpResponse;
   }
@@ -462,6 +475,7 @@
 
     getStatusCode();
     getContentLength();
-    // getPostContent();
+    getRequestContent();
+    getResponseContent();
   }
 }
\ No newline at end of file

Modified: logback/trunk/logback-access/src/test/java/ch/qos/logback/access/dummy/DummyRequest.java
==============================================================================
--- logback/trunk/logback-access/src/test/java/ch/qos/logback/access/dummy/DummyRequest.java	(original)
+++ logback/trunk/logback-access/src/test/java/ch/qos/logback/access/dummy/DummyRequest.java	Thu Mar 13 03:59:18 2008
@@ -15,8 +15,17 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpSession;
 
+import ch.qos.logback.access.Constants;
+
 public class DummyRequest implements HttpServletRequest {
 
+  public final static String  DUMMY_CONTENT_STRING = "request contents";
+  public final static byte[] DUMMY_CONTENT_BYTES = DUMMY_CONTENT_STRING.getBytes(); 
+
+  
+  public static final String DUMMY_RESPONSE_CONTENT_STRING = "response contents";
+  public static final byte[] DUMMY_RESPONSE_CONTENT_BYTES =DUMMY_RESPONSE_CONTENT_STRING.getBytes();
+  
   Hashtable<String, String> headerNames;
   String uri;
 
@@ -130,6 +139,10 @@
   public Object getAttribute(String key) {
     if (key.equals("testKey")) {
       return "testKey";
+    } else if (Constants.LB_INPUT_BUFFER.equals(key)) {
+      return DUMMY_CONTENT_BYTES;
+    } else if (Constants.LB_OUTPUT_BUFFER.equals(key)) {
+      return DUMMY_RESPONSE_CONTENT_BYTES;
     } else {
       return null;
     }

Copied: logback/trunk/logback-access/src/test/java/ch/qos/logback/access/spi/AccessEventSerializationTest.java (from r1629, /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/AccessEventSerializationTest.java	Thu Mar 13 03:59:18 2008
@@ -1,16 +1,21 @@
 package ch.qos.logback.access.spi;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 
-import junit.framework.TestCase;
+import org.junit.Test;
+
 import ch.qos.logback.access.dummy.DummyAccessEventBuilder;
+import ch.qos.logback.access.dummy.DummyRequest;
 import ch.qos.logback.access.dummy.DummyResponse;
 
-public class AccessEventTest extends TestCase {
+public class AccessEventSerializationTest  {
 
   private Object buildSerializedAccessEvent() throws IOException,
       ClassNotFoundException {
@@ -28,11 +33,13 @@
     return ois.readObject();
   }
 
+  @Test
   public void testSerialization() throws IOException, ClassNotFoundException {
     Object o = buildSerializedAccessEvent();
     assertNotNull(o);
     AccessEvent aeBack = (AccessEvent) o;
 
+
     assertEquals(DummyResponse.DUMMY_DEFAULT_HDEADER_MAP, aeBack
         .getResponseHeaderMap());
     assertEquals(DummyResponse.DUMMY_DEFAULT_HDEADER_MAP.get("x"), aeBack
@@ -45,6 +52,12 @@
         .getContentLength());
     assertEquals(DummyResponse.DUMMY_DEFAULT_STATUS, aeBack.getStatusCode());
 
+    assertEquals(DummyRequest.DUMMY_CONTENT_STRING, aeBack
+        .getRequestContent());
+    
+    assertEquals(DummyRequest.DUMMY_RESPONSE_CONTENT_STRING, aeBack
+        .getResponseContent());
+    
   }
 
 }

Modified: logback/trunk/logback-access/src/test/java/ch/qos/logback/access/spi/PackageTest.java
==============================================================================
--- logback/trunk/logback-access/src/test/java/ch/qos/logback/access/spi/PackageTest.java	(original)
+++ logback/trunk/logback-access/src/test/java/ch/qos/logback/access/spi/PackageTest.java	Thu Mar 13 03:59:18 2008
@@ -15,7 +15,7 @@
 
   public static Test suite() {
     TestSuite suite = new TestSuite();
-    suite.addTestSuite(AccessEventTest.class);
+    suite.addTest(new JUnit4TestAdapter(AccessEventSerializationTest.class));
     return suite;
   }
 }
\ No newline at end of file



More information about the logback-dev mailing list