tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1099553 - in /tomcat/trunk: java/org/apache/catalina/valves/AccessLogValve.java webapps/docs/changelog.xml
Date Wed, 04 May 2011 18:19:10 GMT
Author: markt
Date: Wed May  4 18:19:10 2011
New Revision: 1099553

URL: http://svn.apache.org/viewvc?rev=1099553&view=rev
Log:
Make access logging more robust for 400 responses.

Modified:
    tomcat/trunk/java/org/apache/catalina/valves/AccessLogValve.java
    tomcat/trunk/webapps/docs/changelog.xml

Modified: tomcat/trunk/java/org/apache/catalina/valves/AccessLogValve.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/valves/AccessLogValve.java?rev=1099553&r1=1099552&r2=1099553&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/valves/AccessLogValve.java (original)
+++ tomcat/trunk/java/org/apache/catalina/valves/AccessLogValve.java Wed May  4 18:19:10 2011
@@ -926,16 +926,20 @@ public class AccessLogValve extends Valv
         @Override
         public void addElement(StringBuilder buf, Date date, Request request,
                 Response response, long time) {
+            String value = null;
             if (requestAttributesEnabled) {
                 Object host = request.getAttribute(REMOTE_HOST_ATTRIBUTE);
-                if (host == null) {
-                    buf.append(request.getRemoteHost());
-                } else {
-                    buf.append(host);
+                if (host != null) {
+                    value = host.toString();
                 }
-            } else {
-                buf.append(request.getRemoteHost());
             }
+            if (value == null || value.length() == 0) {
+                value = request.getRemoteHost();
+            }
+            if (value == null || value.length() == 0) {
+                value = "-";
+            }
+            buf.append(value);
         }
     }
     
@@ -1027,17 +1031,23 @@ public class AccessLogValve extends Valv
         public void addElement(StringBuilder buf, Date date, Request request,
                 Response response, long time) {
             if (request != null) {
-                buf.append(request.getMethod());
-                buf.append(' ');
-                buf.append(request.getRequestURI());
-                if (request.getQueryString() != null) {
-                    buf.append('?');
-                    buf.append(request.getQueryString());
+                String method = request.getMethod();
+                if (method == null) {
+                    // No method means no request line
+                    buf.append('-');
+                } else {
+                    buf.append(request.getMethod());
+                    buf.append(' ');
+                    buf.append(request.getRequestURI());
+                    if (request.getQueryString() != null) {
+                        buf.append('?');
+                        buf.append(request.getQueryString());
+                    }
+                    buf.append(' ');
+                    buf.append(request.getProtocol());
                 }
-                buf.append(' ');
-                buf.append(request.getProtocol());
             } else {
-                buf.append("- - ");
+                buf.append('-');
             }
         }
     }

Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1099553&r1=1099552&r2=1099553&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Wed May  4 18:19:10 2011
@@ -107,6 +107,11 @@
         Partial sync of MIME type mapping with mime.types from the Apache web
         server. About 600 MIME types added, some changed. (rjung)
       </add>
+      <fix>
+        Make access logging more robust when logging requests that generate 400
+        responses since the request object is unlikely to be fully/correctly
+        populated in that case. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Coyote">



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message