You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2010/11/02 20:26:08 UTC
svn commit: r1030188 - in /tomcat/tc6.0.x/trunk: ./
java/org/apache/catalina/ java/org/apache/catalina/connector/
java/org/apache/catalina/core/ java/org/apache/catalina/valves/
java/org/apache/coyote/ java/org/apache/coyote/ajp/ java/org/apache/coyote...
Author: markt
Date: Tue Nov 2 19:26:07 2010
New Revision: 1030188
URL: http://svn.apache.org/viewvc?rev=1030188&view=rev
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=49099
Include requests rejected by CoyoteAdapter in the access log(s)
Added:
tomcat/tc6.0.x/trunk/java/org/apache/catalina/AccessLog.java (with props)
Modified:
tomcat/tc6.0.x/trunk/ (props changed)
tomcat/tc6.0.x/trunk/STATUS.txt
tomcat/tc6.0.x/trunk/java/org/apache/catalina/Container.java
tomcat/tc6.0.x/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java
tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/ContainerBase.java
tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/StandardEngine.java
tomcat/tc6.0.x/trunk/java/org/apache/catalina/valves/AccessLogValve.java
tomcat/tc6.0.x/trunk/java/org/apache/catalina/valves/JDBCAccessLogValve.java
tomcat/tc6.0.x/trunk/java/org/apache/coyote/Adapter.java
tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpAprProcessor.java
tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpProcessor.java
tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11AprProcessor.java
tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java
tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11Processor.java
tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml
tomcat/tc6.0.x/trunk/webapps/docs/config/valve.xml
Propchange: tomcat/tc6.0.x/trunk/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Nov 2 19:26:07 2010
@@ -1 +1 @@
-/tomcat/trunk:601180,606992,612607,630314,640888,652744,653247,666232,673796,673820,677910,683969,683982,684001,684081,684234,684269-684270,685177,687503,687645,689402,690781,691392,691805,692748,693378,694992,695053,695311,696780,696782,698012,698227,698236,698613,699427,699634,701355,709294,709811,709816,710063,710066,710125,710205,711126,711600,712461,712467,713953,714002,718360,719119,719124,719602,719626,719628,720046,720069,721040,721286,721708,721886,723404,723738,726052,727303,728032,728768,728947,729057,729567,729569,729571,729681,729809,729815,729934,730250,730590,731651,732859,732863,734734,740675,740684,742677,742697,742714,744160,744238,746321,746384,746425,747834,747863,748344,750258,750291,750921,751286-751287,751289,751295,752323,753039,757335,757774,758249,758365,758596,758616,758664,759074,761601,762868,762929,762936-762937,763166,763183,763193,763228,763262,763298,763302,763325,763599,763611,763654,763681,763706,764985,764997,765662,768335,769979,770716,77
0809,770876,772872,776921,776924,776935,776945,777464,777466,777576,777625,778379,778523-778524,781528,781779,782145,782791,783316,783696,783724,783756,783762,783766,783863,783934,784453,784602,784614,785381,785688,785768,785859,786468,786487,786490,786496,786667,787627,787770,787985,789389,790405,791041,791184,791194,791224,791243,791326,791328,791789,792740,793372,793757,793882,793981,794082,794673,794822,795043,795152,795210,795457,795466,797168,797425,797596,797607,802727,802940,804462,804544,804734,805153,809131,809603,810916,810977,812125,812137,812432,813001,813013,813866,814180,814708,814876,815972,816252,817442,817822,819339,819361,820110,820132,820874,820954,821397,828196,828201,828210,828225,828759,830378-830379,830999,831106,831774,831785,831828,831850,831860,832214,832218,833121,833545,834047,835036,835336,836405,881396,881412,883130,883134,883146,883165,883177,883362,883565,884341,885038,885231,885241,885260,885901,885991,886019,888072,889363,889606,889716,8901
39,890265,890349-890350,890417,891185-891187,891583,892198,892341,892415,892464,892555,892812,892814,892817,892843,892887,893321,893493,894580,894586,894805,894831,895013,895045,895057,895191,895392,895703,896370,896384,897380-897381,897776,898126,898256,898468,898527,898555,898558,898718,898836,898906,899284,899348,899420,899653,899769-899770,899783,899788,899792,899916,899918-899919,899935,899949,903916,905020,905151,905722,905728,905735,907311,907513,907538,907652,907819,907825,907864,908002,908721,908754,908759,909097,909206,909212,909525,909636,909869,909875,909887,910266,910370,910442,910471,910485,910974,915226,915737,915861,916097,916141,916157,916170,917598,917633,918093,918489,918594,918684,918787,918792,918799,918803,918885,919851,919914,920025,920055,920298,920449,920596,920824,920840,921444,922010,926716,927062,927621,928482,928695,928732,928798,931709,932357,932967,935105,935983,939491,939551,940064,941356,941463,944409,944416,945231,945808,945835,945841,946686
,948057,950164,950596,950614,950851,950905,951615,953434,954435,955648,955655,956832,957130,957830,958192,960701,963868,964614,966177-966178,966292,966692,981815,991837,993042,1001955,1002185,1002263,1002274,1002349,1002359,1002362,1002481,1002514,1003481,1003488,1003556,1003572,1003581,1003861,1004868-1004869,1005452,1005467,1005647,1005802,1022120,1022134,1022606,1022623,1024224,1024251,1026042,1026784,1026912,1026920
+/tomcat/trunk:601180,606992,612607,630314,640888,652744,653247,666232,673796,673820,677910,683969,683982,684001,684081,684234,684269-684270,685177,687503,687645,689402,690781,691392,691805,692748,693378,694992,695053,695311,696780,696782,698012,698227,698236,698613,699427,699634,701355,709294,709811,709816,710063,710066,710125,710205,711126,711600,712461,712467,713953,714002,718360,719119,719124,719602,719626,719628,720046,720069,721040,721286,721708,721886,723404,723738,726052,727303,728032,728768,728947,729057,729567,729569,729571,729681,729809,729815,729934,730250,730590,731651,732859,732863,734734,740675,740684,742677,742697,742714,744160,744238,746321,746384,746425,747834,747863,748344,750258,750291,750921,751286-751287,751289,751295,752323,753039,757335,757774,758249,758365,758596,758616,758664,759074,761601,762868,762929,762936-762937,763166,763183,763193,763228,763262,763298,763302,763325,763599,763611,763654,763681,763706,764985,764997,765662,768335,769979,770716,77
0809,770876,772872,776921,776924,776935,776945,777464,777466,777576,777625,778379,778523-778524,781528,781779,782145,782791,783316,783696,783724,783756,783762,783766,783863,783934,784453,784602,784614,785381,785688,785768,785859,786468,786487,786490,786496,786667,787627,787770,787985,789389,790405,791041,791184,791194,791224,791243,791326,791328,791789,792740,793372,793757,793882,793981,794082,794673,794822,795043,795152,795210,795457,795466,797168,797425,797596,797607,802727,802940,804462,804544,804734,805153,809131,809603,810916,810977,812125,812137,812432,813001,813013,813866,814180,814708,814876,815972,816252,817442,817822,819339,819361,820110,820132,820874,820954,821397,828196,828201,828210,828225,828759,830378-830379,830999,831106,831774,831785,831828,831850,831860,832214,832218,833121,833545,834047,835036,835336,836405,881396,881412,883130,883134,883146,883165,883177,883362,883565,884341,885038,885231,885241,885260,885901,885991,886019,888072,889363,889606,889716,8901
39,890265,890349-890350,890417,891185-891187,891583,892198,892341,892415,892464,892555,892812,892814,892817,892843,892887,893321,893493,894580,894586,894805,894831,895013,895045,895057,895191,895392,895703,896370,896384,897380-897381,897776,898126,898256,898468,898527,898555,898558,898718,898836,898906,899284,899348,899420,899653,899769-899770,899783,899788,899792,899916,899918-899919,899935,899949,903916,905020,905151,905722,905728,905735,907311,907513,907538,907652,907819,907825,907864,908002,908721,908754,908759,909097,909206,909212,909525,909636,909869,909875,909887,910266,910370,910442,910471,910485,910974,915226,915737,915861,916097,916141,916157,916170,917598,917633,918093,918489,918594,918684,918787,918792,918799,918803,918885,919851,919914,920025,920055,920298,920449,920596,920824,920840,921444,922010,926716,927062,927621,928482,928695,928732,928798,931709,932357,932967,935105,935983,939491,939551,940064,941356,941463,944409,944416,945231,945808,945835,945841,946686
,948057,950164,950596,950614,950851,950905,951615,953434,954435,955648,955655,956832,957130,957830,958192,960701,963868,964614,966177-966178,966292,966692,981815,991837,993042,1001955,1002185,1002263,1002274,1002349,1002359,1002362,1002481,1002514,1003481,1003488,1003556,1003572,1003581,1003861,1004868-1004869,1005452,1005467,1005647,1005802,1022120,1022134,1022606,1022623,1024224,1024251,1026042,1026784,1026912,1026920,1029767
Modified: tomcat/tc6.0.x/trunk/STATUS.txt
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/STATUS.txt?rev=1030188&r1=1030187&r2=1030188&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/STATUS.txt (original)
+++ tomcat/tc6.0.x/trunk/STATUS.txt Tue Nov 2 19:26:07 2010
@@ -89,42 +89,6 @@ PATCHES PROPOSED TO BACKPORT:
cause confusion. I'd prefer not to invent a new name, but mention the
one that we already have when documenting virtualClasspath.
-* Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=49099
- Provide a mechanism for including requests rejected by the CoyoteAdapter in
- the standard access log
- http://people.apache.org/~markt/patches/2010-07-07-bug49099.patch
- This is a backport of: r950587, r950809, r951018, r951093, r951447,
- r951892, r952295
- +1: markt, mturk
- +1: kkolinko: s/if (accessLog != null)/if (getAccessLog() != null)/
- in StandardEngine.logAccess(..), because otherwise accessLog field is never
- initialized and remains null.
- -1:
- rjung: Would be +1, but one question: in ContainerBase method logAccess(),
- if getAccessLog() succeeds, isn't the logging done twice, once there and again
- to the parent? It seems either we should check for "!logged" before logging
- to the parent (at the moment "logged" isn't used at all), or simply return, because
- nothing else is done after parent logging.
-
- kkolinko (Re: rjung): I understand that it is intended: It is logged in all
- parents, but not in the siblings (because passing 'false' as useDefault
- argument when calling getParent().logAccess(..)).
-
- markt (Re: rjung): It is done this way to maintain default behaviour. If you
- define an AccessLog for a Host and an Engine, requests to the Host will be
- logged in both. The logged flag is used to determine if we need to try and
- find a default logger to ensure the request is logged somewhere.
-
- kkolinko: I do not quite understand why CoyoteAdapter.log() recycles
- request and response even if it did not create them, but I do not see
- valid reasons why it should not. Access logging occurs once request
- processing is completed, so it seems valid to recycle them at that point.
-
- markt (Re: kkolinko): CoyoteAdapter.log() recycles the request and response
- since it may get called without a call to CoyoteAdapter.service() and it was
- easier to always recycle than to figure out if a recycle was required or not.
-
-
* Backport the CSRF prevention filter to Tomcat 6 and configure the Manager and
Host Manager applications to use it. The configuration is such that the using
the old roles (manager, admin) will work and will bypass the CSRF protection
Added: tomcat/tc6.0.x/trunk/java/org/apache/catalina/AccessLog.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/AccessLog.java?rev=1030188&view=auto
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/catalina/AccessLog.java (added)
+++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/AccessLog.java Tue Nov 2 19:26:07 2010
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.catalina;
+
+import org.apache.catalina.connector.Request;
+import org.apache.catalina.connector.Response;
+
+
+/**
+ * Intended for use by a {@link Valve} to indicate that the {@link Valve}
+ * provides access logging. It is used by the Tomcat internals to identify a
+ * Valve that logs access requests so requests that are rejected
+ * earlier in the processing chain can still be added to the access log.
+ * Implementations of this interface should be robust against the provided
+ * {@link Request} and {@link Response} objects being null, having null
+ * attributes or any other 'oddness' that may result from attempting to log
+ * a request that was almost certainly rejected because it was mal-formed.
+ */
+public interface AccessLog {
+
+ /**
+ * Add the request/response to the access log using the specified processing
+ * time.
+ *
+ * @param request Request (associated with the response) to log
+ * @param response Response (associated with the request) to log
+ * @param time Time taken to process the request/response in
+ * milliseconds (use 0 if not known)
+ */
+ public void log(Request request, Response response, long time);
+}
Propchange: tomcat/tc6.0.x/trunk/java/org/apache/catalina/AccessLog.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/Container.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/Container.java?rev=1030188&r1=1030187&r2=1030188&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/catalina/Container.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/Container.java Tue Nov 2 19:26:07 2010
@@ -440,4 +440,27 @@ public interface Container {
public void removePropertyChangeListener(PropertyChangeListener listener);
+
+
+ /**
+ * Log a request/response that was destined for this container but has been
+ * handled earlier in the processing chain so that the request/response
+ * still appears in the correct access logs.
+ * @param request Request (associated with the response) to log
+ * @param response Response (associated with the request) to log
+ * @param time Time taken to process the request/response in
+ * milliseconds (use 0 if not known)
+ * @param useDefault Flag that indicates that the request/response should
+ * be logged in the engine's default access log
+ */
+ public void logAccess(Request request, Response response, long time,
+ boolean useDefault);
+
+
+ /**
+ * Identify the AccessLog to use to log a request/response that was destined
+ * for this container but was handled earlier in the processing chain so
+ * that the request/response still appears in the correct access logs.
+ */
+ public AccessLog getAccessLog();
}
Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java?rev=1030188&r1=1030187&r2=1030188&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java Tue Nov 2 19:26:07 2010
@@ -344,6 +344,41 @@ public class CoyoteAdapter implements Ad
}
+ 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, time, true);
+
+ request.recycle();
+ response.recycle();
+ }
+
+
// ------------------------------------------------------ Protected Methods
@@ -406,12 +441,16 @@ public class CoyoteAdapter implements Ad
} catch (IOException ioe) {
res.setStatus(400);
res.setMessage("Invalid URI: " + ioe.getMessage());
+ connector.getService().getContainer().logAccess(
+ request, response, 0, true);
return false;
}
// Normalization
if (!normalize(req.decodedURI())) {
res.setStatus(400);
res.setMessage("Invalid URI");
+ connector.getService().getContainer().logAccess(
+ request, response, 0, true);
return false;
}
// Character decoding
@@ -420,6 +459,8 @@ public class CoyoteAdapter implements Ad
if (!checkNormalize(req.decodedURI())) {
res.setStatus(400);
res.setMessage("Invalid URI character encoding");
+ connector.getService().getContainer().logAccess(
+ request, response, 0, true);
return false;
}
} else {
@@ -494,6 +535,7 @@ public class CoyoteAdapter implements Ad
res.setStatus(405);
res.addHeader("Allow", header);
res.setMessage("TRACE method is not allowed");
+ request.getContext().logAccess(request, response, 0, true);
return false;
}
@@ -514,6 +556,7 @@ public class CoyoteAdapter implements Ad
redirectPath = redirectPath + "?" + query;
}
response.sendRedirect(redirectPath);
+ request.getContext().logAccess(request, response, 0, true);
return false;
}
@@ -897,8 +940,6 @@ public class CoyoteAdapter implements Ad
b[pos + dest] = b[pos + src];
}
}
-
-
private String getSessionCookieName(Context context) {
String result = null;
Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/ContainerBase.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/ContainerBase.java?rev=1030188&r1=1030187&r2=1030188&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/ContainerBase.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/ContainerBase.java Tue Nov 2 19:26:07 2010
@@ -37,6 +37,7 @@ import javax.management.ObjectName;
import javax.naming.directory.DirContext;
import javax.servlet.ServletException;
+import org.apache.catalina.AccessLog;
import org.apache.catalina.Cluster;
import org.apache.catalina.Container;
import org.apache.catalina.ContainerEvent;
@@ -279,6 +280,13 @@ public abstract class ContainerBase
private boolean threadDone = false;
+ /**
+ * The access log to use for requests normally handled by this container
+ * that have been handled earlier in the processing chain.
+ */
+ protected volatile AccessLog accessLog = null;
+ private volatile boolean accessLogScanComplete = false;
+
// ------------------------------------------------------------- Properties
@@ -1191,6 +1199,46 @@ public abstract class ContainerBase
}
+
+ /**
+ * Check this container for an access log and if none is found, look to the
+ * parent. If there is no parent and still none is found, use the NoOp
+ * access log.
+ */
+ public void logAccess(Request request, Response response, long time,
+ boolean useDefault) {
+
+ boolean logged = false;
+
+ if (getAccessLog() != null) {
+ getAccessLog().log(request, response, time);
+ logged = true;
+ }
+
+ if (getParent() != null) {
+ // No need to use default logger once request/response has been logged
+ // once
+ getParent().logAccess(request, response, time, (useDefault && !logged));
+ }
+ }
+
+ public AccessLog getAccessLog() {
+
+ if (accessLogScanComplete) {
+ return accessLog;
+ }
+
+ Valve valves[] = getPipeline().getValves();
+ for (Valve valve : valves) {
+ if (valve instanceof AccessLog) {
+ accessLog = (AccessLog) valve;
+ break;
+ }
+ }
+ accessLogScanComplete = true;
+ return accessLog;
+ }
+
// ------------------------------------------------------- Pipeline Methods
@@ -1614,5 +1662,10 @@ public abstract class ContainerBase
}
+ protected static final class NoopAccessLog implements AccessLog {
+ public void log(Request request, Response response, long time) {
+ // NOOP
+ }
+ }
}
Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/StandardEngine.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/StandardEngine.java?rev=1030188&r1=1030187&r2=1030188&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/StandardEngine.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/StandardEngine.java Tue Nov 2 19:26:07 2010
@@ -26,12 +26,16 @@ import javax.management.MBeanServer;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
+import org.apache.catalina.AccessLog;
import org.apache.catalina.Container;
+import org.apache.catalina.Context;
import org.apache.catalina.Engine;
import org.apache.catalina.Host;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.Realm;
import org.apache.catalina.Service;
+import org.apache.catalina.connector.Request;
+import org.apache.catalina.connector.Response;
import org.apache.catalina.realm.JAASRealm;
import org.apache.catalina.util.ServerInfo;
import org.apache.juli.logging.Log;
@@ -124,6 +128,11 @@ public class StandardEngine
*/
private String jvmRouteId;
+ /**
+ * Default access log to use for request/response pairs where we can't ID
+ * the intended host and context.
+ */
+ private volatile AccessLog defaultAccessLog;
// ------------------------------------------------------------- Properties
@@ -470,8 +479,44 @@ public class StandardEngine
}
+ /**
+ * Override the default implementation. If no access log is defined for the
+ * Engine, look for one in the Engine's default host and then the default
+ * host's ROOT context. If still none is found, return the default NoOp
+ * access log.
+ */
+ public void logAccess(Request request, Response response, long time,
+ boolean useDefault) {
- // ------------------------------------------------------ Protected Methods
+ boolean logged = false;
+
+ if (getAccessLog() != null) {
+ accessLog.log(request, response, time);
+ logged = true;
+ }
+
+ if (!logged && useDefault) {
+ Host host = null;
+ if (defaultAccessLog == null) {
+ // If we reached this point, this Engine can't have an AccessLog
+ // Look in the defaultHost
+ host = (Host) findChild(getDefaultHost());
+ defaultAccessLog = host.getAccessLog();
+
+ if (defaultAccessLog == null) {
+ // Try the ROOT context of default host
+ Context context = (Context) host.findChild("");
+ defaultAccessLog = context.getAccessLog();
+
+ if (defaultAccessLog == null) {
+ defaultAccessLog = new NoopAccessLog();
+ }
+ }
+ }
+
+ defaultAccessLog.log(request, response, time);
+ }
+ }
// -------------------- JMX registration --------------------
Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/valves/AccessLogValve.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/valves/AccessLogValve.java?rev=1030188&r1=1030187&r2=1030188&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/catalina/valves/AccessLogValve.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/valves/AccessLogValve.java Tue Nov 2 19:26:07 2010
@@ -35,6 +35,7 @@ import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpSession;
+import org.apache.catalina.AccessLog;
import org.apache.catalina.Lifecycle;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.LifecycleListener;
@@ -118,9 +119,7 @@ import org.apache.juli.logging.LogFactor
* @version $Id$
*/
-public class AccessLogValve
- extends ValveBase
- implements Lifecycle {
+public class AccessLogValve extends ValveBase implements AccessLog, Lifecycle {
private static Log log = LogFactory.getLog(AccessLogValve.class);
@@ -556,25 +555,30 @@ public class AccessLogValve
long t2 = System.currentTimeMillis();
long time = t2 - t1;
-
- if (logElements == null || condition != null
- && null != request.getRequest().getAttribute(condition)) {
- return;
- }
-
- Date date = getDate();
- StringBuffer result = new StringBuffer(128);
-
- for (int i = 0; i < logElements.length; i++) {
- logElements[i].addElement(result, date, request, response, time);
- }
-
- log(result.toString());
+
+ log(request, response, time);
} else
getNext().invoke(request, response);
}
+ public void log(Request request, Response response, long time) {
+ if (logElements == null || condition != null
+ && null != request.getRequest().getAttribute(condition)) {
+ return;
+ }
+
+ Date date = getDate();
+ StringBuffer result = new StringBuffer(128);
+
+ for (int i = 0; i < logElements.length; i++) {
+ logElements[i].addElement(result, date, request, response, time);
+ }
+
+ log(result.toString());
+ }
+
+
/**
* Rename the existing log file to something else. Then open the
* old log file name up once again. Intended to be called by a JMX
Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/valves/JDBCAccessLogValve.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/valves/JDBCAccessLogValve.java?rev=1030188&r1=1030187&r2=1030188&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/catalina/valves/JDBCAccessLogValve.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/valves/JDBCAccessLogValve.java Tue Nov 2 19:26:07 2010
@@ -29,6 +29,7 @@ import java.util.Properties;
import javax.servlet.ServletException;
+import org.apache.catalina.AccessLog;
import org.apache.catalina.Lifecycle;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.LifecycleListener;
@@ -114,9 +115,8 @@ import org.apache.catalina.util.StringMa
* @author Peter Rossbach
*/
-public final class JDBCAccessLogValve
- extends ValveBase
- implements Lifecycle {
+public final class JDBCAccessLogValve extends ValveBase
+ implements AccessLog, Lifecycle {
// ----------------------------------------------------------- Constructors
@@ -458,11 +458,18 @@ public final class JDBCAccessLogValve
*/
public void invoke(Request request, Response response)
throws IOException, ServletException {
- final String EMPTY = "" ;
getNext().invoke(request, response);
- String remoteHost = EMPTY;
+ log (request, response, 0);
+ }
+
+
+ public void log(Request request, Response response, long time) {
+ final String EMPTY = "" ;
+
+ String remoteHost;
+
if(resolveHosts)
remoteHost = request.getRemoteHost();
else
Modified: tomcat/tc6.0.x/trunk/java/org/apache/coyote/Adapter.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/coyote/Adapter.java?rev=1030188&r1=1030187&r2=1030188&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/coyote/Adapter.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/coyote/Adapter.java Tue Nov 2 19:26:07 2010
@@ -45,9 +45,10 @@ 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 void log(Request req, Response res, long time);
}
Modified: tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpAprProcessor.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpAprProcessor.java?rev=1030188&r1=1030187&r2=1030188&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpAprProcessor.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpAprProcessor.java Tue Nov 2 19:26:07 2010
@@ -406,6 +406,7 @@ public class AjpAprProcessor implements
log.debug(sm.getString("ajpprocessor.header.error"), t);
// 400 - Bad Request
response.setStatus(400);
+ adapter.log(request, response, 0);
error = true;
}
@@ -417,6 +418,7 @@ public class AjpAprProcessor implements
log.debug(sm.getString("ajpprocessor.request.prepare"), t);
// 400 - Internal Server Error
response.setStatus(400);
+ adapter.log(request, response, 0);
error = true;
}
@@ -431,6 +433,7 @@ public class AjpAprProcessor implements
log.error(sm.getString("ajpprocessor.request.process"), t);
// 500 - Internal Server Error
response.setStatus(500);
+ adapter.log(request, response, 0);
error = true;
}
}
@@ -811,6 +814,7 @@ public class AjpAprProcessor implements
secret = true;
if (!tmpMB.equals(requiredSecret)) {
response.setStatus(403);
+ adapter.log(request, response, 0);
error = true;
}
}
@@ -827,6 +831,7 @@ public class AjpAprProcessor implements
// Check if secret was submitted if required
if ((requiredSecret != null) && !secret) {
response.setStatus(403);
+ adapter.log(request, response, 0);
error = true;
}
@@ -875,6 +880,7 @@ public class AjpAprProcessor implements
request.serverName().duplicate(request.localName());
} catch (IOException e) {
response.setStatus(400);
+ adapter.log(request, response, 0);
error = true;
}
return;
@@ -926,6 +932,7 @@ public class AjpAprProcessor implements
error = true;
// 400 - Bad request
response.setStatus(400);
+ adapter.log(request, response, 0);
break;
}
port = port + (charValue * mult);
Modified: tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpProcessor.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpProcessor.java?rev=1030188&r1=1030187&r2=1030188&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpProcessor.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpProcessor.java Tue Nov 2 19:26:07 2010
@@ -423,6 +423,7 @@ public class AjpProcessor implements Act
log.debug(sm.getString("ajpprocessor.header.error"), t);
// 400 - Bad Request
response.setStatus(400);
+ adapter.log(request, response, 0);
error = true;
}
@@ -434,6 +435,7 @@ public class AjpProcessor implements Act
log.debug(sm.getString("ajpprocessor.request.prepare"), t);
// 400 - Internal Server Error
response.setStatus(400);
+ adapter.log(request, response, 0);
error = true;
}
@@ -448,6 +450,7 @@ public class AjpProcessor implements Act
log.error(sm.getString("ajpprocessor.request.process"), t);
// 500 - Internal Server Error
response.setStatus(500);
+ adapter.log(request, response, 0);
error = true;
}
}
@@ -816,6 +819,7 @@ public class AjpProcessor implements Act
secret = true;
if (!tmpMB.equals(requiredSecret)) {
response.setStatus(403);
+ adapter.log(request, response, 0);
error = true;
}
}
@@ -832,6 +836,7 @@ public class AjpProcessor implements Act
// Check if secret was submitted if required
if ((requiredSecret != null) && !secret) {
response.setStatus(403);
+ adapter.log(request, response, 0);
error = true;
}
@@ -880,6 +885,7 @@ public class AjpProcessor implements Act
request.serverName().duplicate(request.localName());
} catch (IOException e) {
response.setStatus(400);
+ adapter.log(request, response, 0);
error = true;
}
return;
@@ -931,6 +937,7 @@ public class AjpProcessor implements Act
error = true;
// 400 - Bad request
response.setStatus(400);
+ adapter.log(request, response, 0);
break;
}
port = port + (charValue * mult);
Modified: tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11AprProcessor.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11AprProcessor.java?rev=1030188&r1=1030187&r2=1030188&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11AprProcessor.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11AprProcessor.java Tue Nov 2 19:26:07 2010
@@ -747,6 +747,7 @@ public class Http11AprProcessor implemen
log.error(sm.getString("http11processor.request.process"), t);
// 500 - Internal Server Error
response.setStatus(500);
+ adapter.log(request, response, 0);
error = true;
}
@@ -833,6 +834,7 @@ public class Http11AprProcessor implemen
}
// 400 - Bad Request
response.setStatus(400);
+ adapter.log(request, response, 0);
error = true;
}
@@ -847,6 +849,7 @@ public class Http11AprProcessor implemen
}
// 400 - Internal Server Error
response.setStatus(400);
+ adapter.log(request, response, 0);
error = true;
}
}
@@ -874,6 +877,7 @@ public class Http11AprProcessor implemen
log.error(sm.getString("http11processor.request.process"), t);
// 500 - Internal Server Error
response.setStatus(500);
+ adapter.log(request, response, 0);
error = true;
}
}
@@ -945,6 +949,7 @@ public class Http11AprProcessor implemen
log.error(sm.getString("http11processor.request.finish"), t);
// 500 - Internal Server Error
response.setStatus(500);
+ adapter.log(request, response, 0);
error = true;
}
try {
@@ -1289,6 +1294,7 @@ public class Http11AprProcessor implemen
error = true;
// Send 505; Unsupported HTTP version
response.setStatus(505);
+ adapter.log(request, response, 0);
}
MessageBytes methodMB = request.method();
@@ -1386,6 +1392,7 @@ public class Http11AprProcessor implemen
error = true;
// 501 - Unimplemented
response.setStatus(501);
+ adapter.log(request, response, 0);
}
startPos = commaPos + 1;
commaPos = transferEncodingValue.indexOf(',', startPos);
@@ -1397,6 +1404,7 @@ public class Http11AprProcessor implemen
error = true;
// 501 - Unimplemented
response.setStatus(501);
+ adapter.log(request, response, 0);
}
}
@@ -1415,6 +1423,7 @@ public class Http11AprProcessor implemen
error = true;
// 400 - Bad request
response.setStatus(400);
+ adapter.log(request, response, 0);
}
parseHost(valueMB);
@@ -1497,6 +1506,7 @@ public class Http11AprProcessor implemen
error = true;
// 400 - Bad request
response.setStatus(400);
+ adapter.log(request, response, 0);
break;
}
port = port + (charValue * mult);
Modified: tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java?rev=1030188&r1=1030187&r2=1030188&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java Tue Nov 2 19:26:07 2010
@@ -771,6 +771,7 @@ public class Http11NioProcessor implemen
log.error(sm.getString("http11processor.request.process"), t);
// 500 - Internal Server Error
response.setStatus(500);
+ adapter.log(request, response, 0);
error = true;
}
@@ -858,6 +859,7 @@ public class Http11NioProcessor implemen
}
// 400 - Bad Request
response.setStatus(400);
+ adapter.log(request, response, 0);
error = true;
}
@@ -872,6 +874,7 @@ public class Http11NioProcessor implemen
}
// 400 - Internal Server Error
response.setStatus(400);
+ adapter.log(request, response, 0);
error = true;
}
}
@@ -911,6 +914,7 @@ public class Http11NioProcessor implemen
log.error(sm.getString("http11processor.request.process"), t);
// 500 - Internal Server Error
response.setStatus(500);
+ adapter.log(request, response, 0);
error = true;
}
}
@@ -983,6 +987,7 @@ public class Http11NioProcessor implemen
log.error(sm.getString("http11processor.request.finish"), t);
// 500 - Internal Server Error
response.setStatus(500);
+ adapter.log(request, response, 0);
error = true;
}
try {
@@ -1317,6 +1322,7 @@ public class Http11NioProcessor implemen
error = true;
// Send 505; Unsupported HTTP version
response.setStatus(505);
+ adapter.log(request, response, 0);
}
MessageBytes methodMB = request.method();
@@ -1414,6 +1420,7 @@ public class Http11NioProcessor implemen
error = true;
// 501 - Unimplemented
response.setStatus(501);
+ adapter.log(request, response, 0);
}
startPos = commaPos + 1;
commaPos = transferEncodingValue.indexOf(',', startPos);
@@ -1425,6 +1432,7 @@ public class Http11NioProcessor implemen
error = true;
// 501 - Unimplemented
response.setStatus(501);
+ adapter.log(request, response, 0);
}
}
@@ -1443,6 +1451,7 @@ public class Http11NioProcessor implemen
error = true;
// 400 - Bad request
response.setStatus(400);
+ adapter.log(request, response, 0);
}
parseHost(valueMB);
@@ -1526,6 +1535,7 @@ public class Http11NioProcessor implemen
error = true;
// 400 - Bad request
response.setStatus(400);
+ adapter.log(request, response, 0);
break;
}
port = port + (charValue * mult);
Modified: tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11Processor.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11Processor.java?rev=1030188&r1=1030187&r2=1030188&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11Processor.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11Processor.java Tue Nov 2 19:26:07 2010
@@ -829,6 +829,7 @@ public class Http11Processor implements
}
// 400 - Bad Request
response.setStatus(400);
+ adapter.log(request, response, 0);
error = true;
}
@@ -843,6 +844,7 @@ public class Http11Processor implements
}
// 400 - Internal Server Error
response.setStatus(400);
+ adapter.log(request, response, 0);
error = true;
}
}
@@ -871,6 +873,7 @@ public class Http11Processor implements
log.error(sm.getString("http11processor.request.process"), t);
// 500 - Internal Server Error
response.setStatus(500);
+ adapter.log(request, response, 0);
error = true;
}
}
@@ -890,6 +893,7 @@ public class Http11Processor implements
log.error(sm.getString("http11processor.request.finish"), t);
// 500 - Internal Server Error
response.setStatus(500);
+ adapter.log(request, response, 0);
error = true;
}
try {
@@ -1197,6 +1201,7 @@ public class Http11Processor implements
" Unsupported HTTP version \""+protocolMB+"\"");
}
response.setStatus(505);
+ adapter.log(request, response, 0);
}
MessageBytes methodMB = request.method();
@@ -1294,6 +1299,7 @@ public class Http11Processor implements
error = true;
// 501 - Unimplemented
response.setStatus(501);
+ adapter.log(request, response, 0);
}
startPos = commaPos + 1;
commaPos = transferEncodingValue.indexOf(',', startPos);
@@ -1309,6 +1315,7 @@ public class Http11Processor implements
" Unsupported transfer encoding \""+encodingName+"\"");
}
response.setStatus(501);
+ adapter.log(request, response, 0);
}
}
@@ -1331,6 +1338,7 @@ public class Http11Processor implements
" host header missing");
}
response.setStatus(400);
+ adapter.log(request, response, 0);
}
parseHost(valueMB);
Modified: tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml?rev=1030188&r1=1030187&r2=1030188&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml Tue Nov 2 19:26:07 2010
@@ -45,6 +45,10 @@
<subsection name="General">
<changelog>
<fix>
+ <bug>49909</bug>: Provide a mechanism to log requests rejected before
+ they reach the AccessLogValve to appear in the access log. (markt)
+ </fix>
+ <fix>
<bug>49674</bug>: Update to Commons Daemon 1.0.3. (markt)
</fix>
<update>
Modified: tomcat/tc6.0.x/trunk/webapps/docs/config/valve.xml
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/webapps/docs/config/valve.xml?rev=1030188&r1=1030187&r2=1030188&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/webapps/docs/config/valve.xml (original)
+++ tomcat/tc6.0.x/trunk/webapps/docs/config/valve.xml Tue Nov 2 19:26:07 2010
@@ -66,6 +66,20 @@
<code>Host</code>, or <code>Engine</code>), and
will record ALL requests processed by that container.</p>
+ <p>Some requests may be handled by Tomcat before they are passed to a
+ container. These include redirects from /foo to /foo/ and the rejection of
+ invalid requests. Where Tomcat can identify the <code>Context</code> that
+ would have handled the request, the request/response will be logged in the
+ <code>AccessLog</code>(s) associated <code>Context</code>, <code>Host</code>
+ and <code>Engine</code>. Where Tomcat cannot identify the
+ <code>Context</code> that would have handled the request, e.g. in cases
+ where the URL is invalid, Tomcat will look first in the <code>Engine</code>,
+ then the default <code>Host</code> for the <code>Engine</code> and finally
+ the ROOT (or default) <code>Context</code> for the default <code>Host</code>
+ for an <code>AccessLog</code> implementation. Tomcat will use the first
+ <code>AccessLog</code> implementation found to log those requests that are
+ rejected before they are passed to a container.</p>
+
</subsection>
<subsection name="Attributes">
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org