Author: markt
Date: Fri Dec 12 15:49:26 2014
New Revision: 1644935
URL: http://svn.apache.org/r1644935
Log:
Provide a better mechanism for the RewriteValve to inject a re-written request
that avoids:
- NPEs appearing in the log every time the Valve re-writes a request.
- unnecessary duplication of post-processing in the adapter
Modified:
tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java
tomcat/trunk/java/org/apache/catalina/valves/rewrite/RewriteValve.java
tomcat/trunk/java/org/apache/coyote/Adapter.java
Modified: tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java?rev=1644935&r1=1644934&r2=1644935&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java
(original)
+++ tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java Fri Dec
12 15:49:26 2014
@@ -415,6 +415,15 @@ public class CoyoteAdapter implements Ad
}
+ @Override
+ public boolean prepare(org.apache.coyote.Request req,
org.apache.coyote.Response res)
+ throws IOException, ServletException {
+ Request request = (Request) req.getNote(ADAPTER_NOTES);
+ Response response = (Response) res.getNote(ADAPTER_NOTES);
+
+ return postParseRequest(req, request, res, response);
+ }
+
@Override
public void errorDispatch(org.apache.coyote.Request req,
Modified: tomcat/trunk/java/org/apache/catalina/valves/rewrite/RewriteValve.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/valves/rewrite/RewriteValve.java?rev=1644935&r1=1644934&r2=1644935&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/valves/rewrite/RewriteValve.java
(original)
+++ tomcat/trunk/java/org/apache/catalina/valves/rewrite/RewriteValve.java Fri
Dec 12 15:49:26 2014
@@ -41,6 +41,8 @@ import org.apache.catalina.Host;
import org.apache.catalina.Lifecycle;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.LifecycleListener;
+import org.apache.catalina.Pipeline;
+import org.apache.catalina.connector.Connector;
import org.apache.catalina.connector.Request;
import org.apache.catalina.connector.Response;
import org.apache.catalina.util.LifecycleSupport;
@@ -486,8 +488,14 @@ public class RewriteValve extends ValveB
request.getMappingData().recycle();
// Reinvoke the whole request recursively
try {
-
request.getConnector().getProtocolHandler().getAdapter().service
- (request.getCoyoteRequest(),
response.getCoyoteResponse());
+ Connector connector = request.getConnector();
+ if
(!connector.getProtocolHandler().getAdapter().prepare(
+ request.getCoyoteRequest(),
response.getCoyoteResponse())) {
+ return;
+ }
+ Pipeline pipeline =
connector.getService().getContainer().getPipeline();
+ request.setAsyncSupported(pipeline.isAsyncSupported());
+ pipeline.getFirst().invoke(request, response);
} catch (Exception e) {
// This doesn't actually happen in the Catalina
adapter implementation
}
@@ -552,7 +560,9 @@ public class RewriteValve extends ValveB
* Example:
* RewriteCond %{REMOTE_HOST} ^host1.* [OR]
*
- * @param line
+ * @param line A line from the rewrite configuration
+ *
+ * @return The condition, rule or map resulting from parsing the line
*/
public static Object parse(String line) {
StringTokenizer tokenizer = new StringTokenizer(line);
Modified: tomcat/trunk/java/org/apache/coyote/Adapter.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/Adapter.java?rev=1644935&r1=1644934&r2=1644935&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/Adapter.java (original)
+++ tomcat/trunk/java/org/apache/coyote/Adapter.java Fri Dec 12 15:49:26 2014
@@ -30,6 +30,9 @@ public interface Adapter {
/**
* Call the service method, and notify all listeners
*
+ * @param req The request object
+ * @param res The response object
+ *
* @exception Exception if an error happens during handling of
* the request. Common errors are:
* <ul><li>IOException if an input/output error occurs and we are
@@ -42,8 +45,23 @@ public interface Adapter {
* Tomcat should be able to handle and log any other exception ( including
* runtime exceptions )
*/
- public void service(Request req, Response res)
- throws Exception;
+ public void service(Request req, Response res) throws Exception;
+
+ /**
+ * Prepare the given request/response for processing. This method requires
+ * that the request object has been populated with the information
available
+ * from the HTTP headers.
+ *
+ * @param req The request object
+ * @param res The response object
+ *
+ * @return <code>true</code> if processing can continue, otherwise
+ * <code>false</code> in which case an appropriate error will have
+ * been set on the response
+ *
+ * @throws Exception If the processing fails unexpectedly
+ */
+ public boolean prepare(Request req, Response res) throws Exception;
public boolean asyncDispatch(Request req,Response res, SocketStatus status)
throws Exception;
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]