Extend access logging to requests rejected in the Processors
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 3 Jun 2010 18:13:47 +0000 (18:13 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 3 Jun 2010 18:13:47 +0000 (18:13 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@951093 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/connector/CoyoteAdapter.java
java/org/apache/coyote/Adapter.java
java/org/apache/coyote/ajp/AjpAprProcessor.java
java/org/apache/coyote/ajp/AjpProcessor.java
java/org/apache/coyote/http11/Http11AprProcessor.java
java/org/apache/coyote/http11/Http11NioProcessor.java
java/org/apache/coyote/http11/Http11Processor.java

index 4c75475..e099dd9 100644 (file)
@@ -457,6 +457,41 @@ public class CoyoteAdapter implements Adapter {
     }
 
 
+    public void log(org.apache.coyote.Request req,
+            org.apache.coyote.Response res, long time) {
+
+        Request request = (Request) req.getNote(ADAPTER_NOTES);
+        Response response = (Response) res.getNote(ADAPTER_NOTES);
+
+        if (request == null) {
+
+            // Create objects
+            request = connector.createRequest();
+            request.setCoyoteRequest(req);
+            response = connector.createResponse();
+            response.setCoyoteResponse(res);
+
+            // Link objects
+            request.setResponse(response);
+            response.setRequest(request);
+
+            // Set as notes
+            req.setNote(ADAPTER_NOTES, request);
+            res.setNote(ADAPTER_NOTES, response);
+
+            // Set query string encoding
+            req.getParameters().setQueryStringEncoding
+                (connector.getURIEncoding());
+        }
+        
+        connector.getService().getContainer().logAccess(
+                request, response, 0, true);
+        
+        request.recycle();
+        response.recycle();
+    }
+    
+    
     // ------------------------------------------------------ Protected Methods
 
 
index a712fcc..ffa5d35 100644 (file)
@@ -45,11 +45,13 @@ public interface Adapter {
      *  runtime exceptions )
      */
     public void service(Request req, Response res)
-       throws Exception;
+            throws Exception;
 
     public boolean event(Request req, Response res, SocketStatus status)
-    throws Exception;
+            throws Exception;
     
-    public boolean asyncDispatch(Request req,Response res, SocketStatus status) throws Exception;
+    public boolean asyncDispatch(Request req,Response res, SocketStatus status)
+            throws Exception;
 
+    public void log(Request req, Response res, long time);
 }
index b79c730..b8c773c 100644 (file)
@@ -416,6 +416,7 @@ public class AjpAprProcessor implements ActionHook {
                 log.debug(sm.getString("ajpprocessor.header.error"), t);
                 // 400 - Bad Request
                 response.setStatus(400);
+                adapter.log(request, response, 0);
                 error = true;
             }
 
@@ -427,6 +428,7 @@ public class AjpAprProcessor implements ActionHook {
                 log.debug(sm.getString("ajpprocessor.request.prepare"), t);
                 // 400 - Internal Server Error
                 response.setStatus(400);
+                adapter.log(request, response, 0);
                 error = true;
             }
 
@@ -441,6 +443,7 @@ public class AjpAprProcessor implements ActionHook {
                     log.error(sm.getString("ajpprocessor.request.process"), t);
                     // 500 - Internal Server Error
                     response.setStatus(500);
+                    adapter.log(request, response, 0);
                     error = true;
                 }
             }
@@ -501,6 +504,7 @@ public class AjpAprProcessor implements ActionHook {
             log.error(sm.getString("http11processor.request.process"), t);
             // 500 - Internal Server Error
             response.setStatus(500);
+            adapter.log(request, response, 0);
             error = true;
         }
 
@@ -892,6 +896,7 @@ public class AjpAprProcessor implements ActionHook {
                     secret = true;
                     if (!tmpMB.equals(requiredSecret)) {
                         response.setStatus(403);
+                        adapter.log(request, response, 0);
                         error = true;
                     }
                 }
@@ -908,6 +913,7 @@ public class AjpAprProcessor implements ActionHook {
         // Check if secret was submitted if required
         if ((requiredSecret != null) && !secret) {
             response.setStatus(403);
+            adapter.log(request, response, 0);
             error = true;
         }
 
@@ -956,6 +962,7 @@ public class AjpAprProcessor implements ActionHook {
                 request.serverName().duplicate(request.localName());
             } catch (IOException e) {
                 response.setStatus(400);
+                adapter.log(request, response, 0);
                 error = true;
             }
             return;
@@ -1007,6 +1014,7 @@ public class AjpAprProcessor implements ActionHook {
                     error = true;
                     // 400 - Bad request
                     response.setStatus(400);
+                    adapter.log(request, response, 0);
                     break;
                 }
                 port = port + (charValue * mult);
index 6f44911..7ffb1dd 100644 (file)
@@ -427,6 +427,7 @@ public class AjpProcessor implements ActionHook {
                 log.debug(sm.getString("ajpprocessor.header.error"), t);
                 // 400 - Bad Request
                 response.setStatus(400);
+                adapter.log(request, response, 0);
                 error = true;
             }
 
@@ -438,6 +439,7 @@ public class AjpProcessor implements ActionHook {
                 log.debug(sm.getString("ajpprocessor.request.prepare"), t);
                 // 400 - Internal Server Error
                 response.setStatus(400);
+                adapter.log(request, response, 0);
                 error = true;
             }
 
@@ -452,6 +454,7 @@ public class AjpProcessor implements ActionHook {
                     log.error(sm.getString("ajpprocessor.request.process"), t);
                     // 500 - Internal Server Error
                     response.setStatus(500);
+                    adapter.log(request, response, 0);
                     error = true;
                 }
             }
@@ -505,6 +508,7 @@ public class AjpProcessor implements ActionHook {
             log.error(sm.getString("http11processor.request.process"), t);
             // 500 - Internal Server Error
             response.setStatus(500);
+            adapter.log(request, response, 0);
             error = true;
         }
 
@@ -900,6 +904,7 @@ public class AjpProcessor implements ActionHook {
                     secret = true;
                     if (!tmpMB.equals(requiredSecret)) {
                         response.setStatus(403);
+                        adapter.log(request, response, 0);
                         error = true;
                     }
                 }
@@ -916,6 +921,7 @@ public class AjpProcessor implements ActionHook {
         // Check if secret was submitted if required
         if ((requiredSecret != null) && !secret) {
             response.setStatus(403);
+            adapter.log(request, response, 0);
             error = true;
         }
 
@@ -964,6 +970,7 @@ public class AjpProcessor implements ActionHook {
                 request.serverName().duplicate(request.localName());
             } catch (IOException e) {
                 response.setStatus(400);
+                adapter.log(request, response, 0);
                 error = true;
             }
             return;
@@ -1015,6 +1022,7 @@ public class AjpProcessor implements ActionHook {
                     error = true;
                     // 400 - Bad request
                     response.setStatus(400);
+                    adapter.log(request, response, 0);
                     break;
                 }
                 port = port + (charValue * mult);
index b8a927c..3c0ce1c 100644 (file)
@@ -734,6 +734,7 @@ public class Http11AprProcessor implements ActionHook {
             log.error(sm.getString("http11processor.request.process"), t);
             // 500 - Internal Server Error
             response.setStatus(500);
+            adapter.log(request, response, 0);
             error = true;
         }
         
@@ -821,6 +822,7 @@ public class Http11AprProcessor implements ActionHook {
                 }
                 // 400 - Bad Request
                 response.setStatus(400);
+                adapter.log(request, response, 0);
                 error = true;
             }
 
@@ -835,6 +837,7 @@ public class Http11AprProcessor implements ActionHook {
                     }
                     // 400 - Internal Server Error
                     response.setStatus(400);
+                    adapter.log(request, response, 0);
                     error = true;
                 }
             }
@@ -862,6 +865,7 @@ public class Http11AprProcessor implements ActionHook {
                     log.error(sm.getString("http11processor.request.process"), t);
                     // 500 - Internal Server Error
                     response.setStatus(500);
+                    adapter.log(request, response, 0);
                     error = true;
                 }
             }
@@ -939,6 +943,7 @@ public class Http11AprProcessor implements ActionHook {
             log.error(sm.getString("http11processor.request.process"), t);
             // 500 - Internal Server Error
             response.setStatus(500);
+            adapter.log(request, response, 0);
             error = true;
         }
 
@@ -976,6 +981,7 @@ public class Http11AprProcessor implements ActionHook {
             log.error(sm.getString("http11processor.request.finish"), t);
             // 500 - Internal Server Error
             response.setStatus(500);
+            adapter.log(request, response, 0);
             error = true;
         }
         try {
@@ -1351,6 +1357,7 @@ public class Http11AprProcessor implements ActionHook {
             error = true;
             // Send 505; Unsupported HTTP version
             response.setStatus(505);
+            adapter.log(request, response, 0);
         }
 
         MessageBytes methodMB = request.method();
@@ -1448,6 +1455,7 @@ public class Http11AprProcessor implements ActionHook {
                     error = true;
                     // 501 - Unimplemented
                     response.setStatus(501);
+                    adapter.log(request, response, 0);
                 }
                 startPos = commaPos + 1;
                 commaPos = transferEncodingValue.indexOf(',', startPos);
@@ -1459,6 +1467,7 @@ public class Http11AprProcessor implements ActionHook {
                 error = true;
                 // 501 - Unimplemented
                 response.setStatus(501);
+                adapter.log(request, response, 0);
             }
         }
 
@@ -1477,6 +1486,7 @@ public class Http11AprProcessor implements ActionHook {
             error = true;
             // 400 - Bad request
             response.setStatus(400);
+            adapter.log(request, response, 0);
         }
 
         parseHost(valueMB);
@@ -1559,6 +1569,7 @@ public class Http11AprProcessor implements ActionHook {
                     error = true;
                     // 400 - Bad request
                     response.setStatus(400);
+                    adapter.log(request, response, 0);
                     break;
                 }
                 port = port + (charValue * mult);
index 6f70794..992f98d 100644 (file)
@@ -222,6 +222,7 @@ public class Http11NioProcessor extends AbstractHttp11Processor implements Actio
             log.error(sm.getString("http11processor.request.process"), t);
             // 500 - Internal Server Error
             response.setStatus(500);
+            adapter.log(request, response, 0);
             error = true;
         }
 
@@ -279,6 +280,7 @@ public class Http11NioProcessor extends AbstractHttp11Processor implements Actio
             log.error(sm.getString("http11processor.request.process"), t);
             // 500 - Internal Server Error
             response.setStatus(500);
+            adapter.log(request, response, 0);
             error = true;
         }
 
@@ -370,6 +372,7 @@ public class Http11NioProcessor extends AbstractHttp11Processor implements Actio
                 }
                 // 400 - Bad Request
                 response.setStatus(400);
+                adapter.log(request, response, 0);
                 error = true;
             }
 
@@ -384,6 +387,7 @@ public class Http11NioProcessor extends AbstractHttp11Processor implements Actio
                     }
                     // 400 - Internal Server Error
                     response.setStatus(400);
+                    adapter.log(request, response, 0);
                     error = true;
                 }
             }
@@ -425,6 +429,7 @@ public class Http11NioProcessor extends AbstractHttp11Processor implements Actio
                     log.error(sm.getString("http11processor.request.process"), t);
                     // 500 - Internal Server Error
                     response.setStatus(500);
+                    adapter.log(request, response, 0);
                     error = true;
                 }
             }
@@ -497,6 +502,7 @@ public class Http11NioProcessor extends AbstractHttp11Processor implements Actio
             log.error(sm.getString("http11processor.request.finish"), t);
             // 500 - Internal Server Error
             response.setStatus(500);
+            adapter.log(request, response, 0);
             error = true;
         }
         try {
@@ -839,6 +845,7 @@ public class Http11NioProcessor extends AbstractHttp11Processor implements Actio
             error = true;
             // Send 505; Unsupported HTTP version
             response.setStatus(505);
+            adapter.log(request, response, 0);
         }
 
         MessageBytes methodMB = request.method();
@@ -936,6 +943,7 @@ public class Http11NioProcessor extends AbstractHttp11Processor implements Actio
                     error = true;
                     // 501 - Unimplemented
                     response.setStatus(501);
+                    adapter.log(request, response, 0);
                 }
                 startPos = commaPos + 1;
                 commaPos = transferEncodingValue.indexOf(',', startPos);
@@ -947,6 +955,7 @@ public class Http11NioProcessor extends AbstractHttp11Processor implements Actio
                 error = true;
                 // 501 - Unimplemented
                 response.setStatus(501);
+                adapter.log(request, response, 0);
             }
         }
 
@@ -965,6 +974,7 @@ public class Http11NioProcessor extends AbstractHttp11Processor implements Actio
             error = true;
             // 400 - Bad request
             response.setStatus(400);
+            adapter.log(request, response, 0);
         }
 
         parseHost(valueMB);
@@ -1048,6 +1058,7 @@ public class Http11NioProcessor extends AbstractHttp11Processor implements Actio
                     error = true;
                     // 400 - Bad request
                     response.setStatus(400);
+                    adapter.log(request, response, 0);
                     break;
                 }
                 port = port + (charValue * mult);
index 2dd853a..cee3721 100644 (file)
@@ -226,6 +226,7 @@ public class Http11Processor extends AbstractHttp11Processor implements ActionHo
                 }
                 // 400 - Bad Request
                 response.setStatus(400);
+                adapter.log(request, response, 0);
                 error = true;
             }
 
@@ -240,6 +241,7 @@ public class Http11Processor extends AbstractHttp11Processor implements ActionHo
                     }
                     // 400 - Internal Server Error
                     response.setStatus(400);
+                    adapter.log(request, response, 0);
                     error = true;
                 }
             }
@@ -268,6 +270,7 @@ public class Http11Processor extends AbstractHttp11Processor implements ActionHo
                     log.error(sm.getString("http11processor.request.process"), t);
                     // 500 - Internal Server Error
                     response.setStatus(500);
+                    adapter.log(request, response, 0);
                     error = true;
                 }
             }
@@ -287,6 +290,7 @@ public class Http11Processor extends AbstractHttp11Processor implements ActionHo
                 log.error(sm.getString("http11processor.request.finish"), t);
                 // 500 - Internal Server Error
                 response.setStatus(500);
+                adapter.log(request, response, 0);
                 error = true;
             }
             try {
@@ -347,6 +351,7 @@ public class Http11Processor extends AbstractHttp11Processor implements ActionHo
             log.error(sm.getString("http11processor.request.process"), t);
             // 500 - Internal Server Error
             response.setStatus(500);
+            adapter.log(request, response, 0);
             error = true;
         }
 
@@ -379,6 +384,7 @@ public class Http11Processor extends AbstractHttp11Processor implements ActionHo
             log.error(sm.getString("http11processor.request.finish"), t);
             // 500 - Internal Server Error
             response.setStatus(500);
+            adapter.log(request, response, 0);
             error = true;
         }
         try {
@@ -681,6 +687,7 @@ public class Http11Processor extends AbstractHttp11Processor implements ActionHo
                           " Unsupported HTTP version \""+protocolMB+"\"");
             }
             response.setStatus(505);
+            adapter.log(request, response, 0);
         }
 
         MessageBytes methodMB = request.method();
@@ -778,6 +785,7 @@ public class Http11Processor extends AbstractHttp11Processor implements ActionHo
                     error = true;
                     // 501 - Unimplemented
                     response.setStatus(501);
+                    adapter.log(request, response, 0);
                 }
                 startPos = commaPos + 1;
                 commaPos = transferEncodingValue.indexOf(',', startPos);
@@ -793,6 +801,7 @@ public class Http11Processor extends AbstractHttp11Processor implements ActionHo
                               " Unsupported transfer encoding \""+encodingName+"\"");
                 }
                 response.setStatus(501);
+                adapter.log(request, response, 0);
             }
         }
 
@@ -815,6 +824,7 @@ public class Http11Processor extends AbstractHttp11Processor implements ActionHo
                           " host header missing");
             }
             response.setStatus(400);
+            adapter.log(request, response, 0);
         }
 
         parseHost(valueMB);
@@ -1109,6 +1119,7 @@ public class Http11Processor extends AbstractHttp11Processor implements ActionHo
                     error = true;
                     // 400 - Bad request
                     response.setStatus(400);
+                    adapter.log(request, response, 0);
                     break;
                 }
                 port = port + (charValue * mult);