[LOGBack-dev] svn commit: r592 - in logback/trunk: . logback-access/src/main/java/ch/qos/logback/access/pattern logback-access/src/main/java/ch/qos/logback/access/spi logback-access/src/test/java/ch/qos/logback/access/pattern logback-access/src/test/java/ch/qos/logback/access/pattern/helpers

noreply.seb at qos.ch noreply.seb at qos.ch
Tue Sep 19 10:32:02 CEST 2006


Author: seb
Date: Tue Sep 19 10:32:01 2006
New Revision: 592

Modified:
   logback/trunk/logback-access/src/main/java/ch/qos/logback/access/pattern/RequestHeaderConverter.java
   logback/trunk/logback-access/src/main/java/ch/qos/logback/access/pattern/ResponseHeaderConverter.java
   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/pattern/ConverterTest.java
   logback/trunk/logback-access/src/test/java/ch/qos/logback/access/pattern/helpers/DummyRequest.java
   logback/trunk/logback-access/src/test/java/ch/qos/logback/access/pattern/helpers/DummyResponse.java
   logback/trunk/pom.xml

Log:
- updated dependencies to use jetty 6.0.0
- modified AccessEvent method getHeader to getRequestHeader
- added getResponseHeader to AccessEvent
- updated DummyResponse to provide header access

Modified: logback/trunk/logback-access/src/main/java/ch/qos/logback/access/pattern/RequestHeaderConverter.java
==============================================================================
--- logback/trunk/logback-access/src/main/java/ch/qos/logback/access/pattern/RequestHeaderConverter.java	(original)
+++ logback/trunk/logback-access/src/main/java/ch/qos/logback/access/pattern/RequestHeaderConverter.java	Tue Sep 19 10:32:01 2006
@@ -22,7 +22,7 @@
       return "INACTIVE_HEADER_CONV";
     }
     
-    return accessEvent.getHeader(key);
+    return accessEvent.getRequestHeader(key);
   }
 
 }

Modified: logback/trunk/logback-access/src/main/java/ch/qos/logback/access/pattern/ResponseHeaderConverter.java
==============================================================================
--- logback/trunk/logback-access/src/main/java/ch/qos/logback/access/pattern/ResponseHeaderConverter.java	(original)
+++ logback/trunk/logback-access/src/main/java/ch/qos/logback/access/pattern/ResponseHeaderConverter.java	Tue Sep 19 10:32:01 2006
@@ -22,7 +22,8 @@
       return "INACTIVE_REPONSE_HEADER_CONV";
     }
     
-    return null;
+    return accessEvent.getResponseHeader(key);
+    //return null;
     
 //    HttpServletResponse response = accessEvent.getHttpResponse();
 //

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	Tue Sep 19 10:32:01 2006
@@ -9,6 +9,8 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.mortbay.jetty.Response;
+
 import ch.qos.logback.access.pattern.AccessConverter;
 
 public class AccessEvent implements Serializable {
@@ -30,7 +32,7 @@
   String method;
   String serverName;
   
-  Map headerMap;
+  Map requestHeaderMap;
 
   long contentLength = SENTINEL;
   int statusCode = SENTINEL;
@@ -169,15 +171,15 @@
     return remoteAddr;
   }
 
-  public String getHeader(String key) {
+  public String getRequestHeader(String key) {
     String result = null;
-    if (headerMap == null) {
+    if (requestHeaderMap == null) {
       if (httpRequest != null) {
-        buildHeaderMap();
-        result = (String) headerMap.get(key);
+        buildRequestHeaderMap();
+        result = (String) requestHeaderMap.get(key);
       }
     } else {
-      result = (String) headerMap.get(key);
+      result = (String) requestHeaderMap.get(key);
     }
 
     if (result != null) {
@@ -187,15 +189,26 @@
     }
   }
 
-  public void buildHeaderMap() {
-    headerMap = new HashMap();
+  public void buildRequestHeaderMap() {
+    requestHeaderMap = new HashMap();
     Enumeration e = httpRequest.getHeaderNames();
     while(e.hasMoreElements()) {
       String key = (String) e.nextElement();
-      headerMap.put(key, httpRequest.getHeader(key));
+      requestHeaderMap.put(key, httpRequest.getHeader(key));
     }
   }
-
+  
+  public String getResponseHeader(String key) {
+    //TODO buildMap
+    if (httpResponse instanceof org.mortbay.jetty.Response) {
+      return ((org.mortbay.jetty.Response)httpResponse).getHeader(key);
+    }
+    if (httpResponse instanceof ch.qos.logback.access.pattern.helpers.DummyResponse) {
+      return ((ch.qos.logback.access.pattern.helpers.DummyResponse)httpResponse).getHeader(key);
+    }
+    
+    return null;
+  }
   /**
    * Attributes are not serialized
    * 

Modified: logback/trunk/logback-access/src/test/java/ch/qos/logback/access/pattern/ConverterTest.java
==============================================================================
--- logback/trunk/logback-access/src/test/java/ch/qos/logback/access/pattern/ConverterTest.java	(original)
+++ logback/trunk/logback-access/src/test/java/ch/qos/logback/access/pattern/ConverterTest.java	Tue Sep 19 10:32:01 2006
@@ -133,14 +133,13 @@
   }
 
   public void testResponseHeaderConverter() {
-    // TODO
-    // ResponseHeaderConverter converter = new ResponseHeaderConverter();
-    // List<String> optionList = new ArrayList<String>();
-    // optionList.add("headerName1");
-    // converter.setOptionList(optionList);
-    // converter.start();
-    // String result = converter.convert(event);
-    // assertEquals(request.getHeader("headerName1"), result);
+     ResponseHeaderConverter converter = new ResponseHeaderConverter();
+     List<String> optionList = new ArrayList<String>();
+     optionList.add("headerName1");
+     converter.setOptionList(optionList);
+     converter.start();
+     String result = converter.convert(event);
+     assertEquals(request.getHeader("headerName1"), result);
   }
 
   public void testServerNameConverter() {

Modified: logback/trunk/logback-access/src/test/java/ch/qos/logback/access/pattern/helpers/DummyRequest.java
==============================================================================
--- logback/trunk/logback-access/src/test/java/ch/qos/logback/access/pattern/helpers/DummyRequest.java	(original)
+++ logback/trunk/logback-access/src/test/java/ch/qos/logback/access/pattern/helpers/DummyRequest.java	Tue Sep 19 10:32:01 2006
@@ -18,13 +18,13 @@
 public class DummyRequest implements HttpServletRequest {
 
   Hashtable<String, String> headerNames;
-  
+
   public DummyRequest() {
     headerNames = new Hashtable<String, String>();
     headerNames.put("headerName1", "headerValue1");
     headerNames.put("headerName2", "headerValue2");
   }
-  
+
   public String getAuthType() {
     return null;
   }
@@ -35,7 +35,7 @@
 
   public Cookie[] getCookies() {
     Cookie cookie = new Cookie("testName", "testCookie");
-    return new Cookie[] {cookie};
+    return new Cookie[] { cookie };
   }
 
   public long getDateHeader(String arg0) {

Modified: logback/trunk/logback-access/src/test/java/ch/qos/logback/access/pattern/helpers/DummyResponse.java
==============================================================================
--- logback/trunk/logback-access/src/test/java/ch/qos/logback/access/pattern/helpers/DummyResponse.java	(original)
+++ logback/trunk/logback-access/src/test/java/ch/qos/logback/access/pattern/helpers/DummyResponse.java	Tue Sep 19 10:32:01 2006
@@ -2,8 +2,9 @@
 
 import java.io.IOException;
 import java.io.PrintWriter;
-import java.util.Hashtable;
+import java.util.HashMap;
 import java.util.Locale;
+import java.util.Map;
 
 import javax.servlet.ServletOutputStream;
 import javax.servlet.http.Cookie;
@@ -11,19 +12,18 @@
 
 public class DummyResponse implements HttpServletResponse {
 
-  Hashtable<String, String> headerNames;
-  
+  Map<String, String> headerMap;
   public DummyResponse() {
-    headerNames = new Hashtable<String, String>();
-    headerNames.put("headerName1", "headerValue1");
-    headerNames.put("headerName2", "headerValue2");
+    headerMap = new HashMap<String, String>();
+    headerMap.put("headerName1", "headerValue1");
+    headerMap.put("headerName2", "headerValue2");
   }
-  
+
   public void addCookie(Cookie arg0) {
-    
+
   }
 
-  public void addDateHeader(String arg0, long arg1) {   
+  public void addDateHeader(String arg0, long arg1) {
   }
 
   public void addHeader(String arg0, String arg1) {
@@ -52,7 +52,7 @@
     return null;
   }
 
-  public void sendError(int arg0) throws IOException {   
+  public void sendError(int arg0) throws IOException {
   }
 
   public void sendError(int arg0, String arg1) throws IOException {
@@ -64,19 +64,19 @@
   public void setDateHeader(String arg0, long arg1) {
   }
 
-  public void setHeader(String arg0, String arg1) { 
+  public void setHeader(String arg0, String arg1) {
   }
 
-  public void setIntHeader(String arg0, int arg1) { 
+  public void setIntHeader(String arg0, int arg1) {
   }
 
-  public void setStatus(int arg0) { 
+  public void setStatus(int arg0) {
   }
 
-  public void setStatus(int arg0, String arg1) { 
+  public void setStatus(int arg0, String arg1) {
   }
 
-  public void flushBuffer() throws IOException { 
+  public void flushBuffer() throws IOException {
   }
 
   public int getBufferSize() {
@@ -110,10 +110,10 @@
   public void reset() {
   }
 
-  public void resetBuffer() { 
+  public void resetBuffer() {
   }
 
-  public void setBufferSize(int arg0) { 
+  public void setBufferSize(int arg0) {
   }
 
   public void setCharacterEncoding(String arg0) {
@@ -122,10 +122,14 @@
   public void setContentLength(int arg0) {
   }
 
-  public void setContentType(String arg0) {  
+  public void setContentType(String arg0) {
   }
 
   public void setLocale(Locale arg0) {
   }
+  
+  public String getHeader(String key) {
+    return headerMap.get(key);
+  }
 
 }

Modified: logback/trunk/pom.xml
==============================================================================
--- logback/trunk/pom.xml	(original)
+++ logback/trunk/pom.xml	Tue Sep 19 10:32:01 2006
@@ -85,7 +85,7 @@
 			<dependency>
 				<groupId>org.mortbay.jetty</groupId>
 				<artifactId>jetty</artifactId>
-				<version>6.0.0beta9</version>
+				<version>6.0.0</version>
 			</dependency>
 	
 			<dependency>
@@ -97,7 +97,7 @@
 			<dependency>
 				<groupId>org.mortbay.jetty</groupId>
 				<artifactId>servlet-api-2.5</artifactId>
-				<version>6.0.0beta9</version>
+				<version>6.0.0</version>
 			</dependency>
 		
 		</dependencies>



More information about the logback-dev mailing list