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 2019/07/24 14:51:25 UTC
[tomcat] 05/11: Polish. Align with 8.5.x. Spacing,
Javadoc. No functional change.
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 7.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit 81b3bf2a377b495bac9fef2c3a01360a5b7c3df1
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed Jul 24 10:55:35 2019 +0100
Polish. Align with 8.5.x. Spacing, Javadoc. No functional change.
---
.../apache/catalina/connector/CoyoteAdapter.java | 137 ++++++++++++---------
1 file changed, 78 insertions(+), 59 deletions(-)
diff --git a/java/org/apache/catalina/connector/CoyoteAdapter.java b/java/org/apache/catalina/connector/CoyoteAdapter.java
index 882ca47..02e5fbf 100644
--- a/java/org/apache/catalina/connector/CoyoteAdapter.java
+++ b/java/org/apache/catalina/connector/CoyoteAdapter.java
@@ -143,8 +143,8 @@ public class CoyoteAdapter implements Adapter {
* @return false to indicate an error, expected or not
*/
@Override
- public boolean event(org.apache.coyote.Request req,
- org.apache.coyote.Response res, SocketStatus status) {
+ public boolean event(org.apache.coyote.Request req, org.apache.coyote.Response res,
+ SocketStatus status) {
Request request = (Request) req.getNote(ADAPTER_NOTES);
Response response = (Response) res.getNote(ADAPTER_NOTES);
@@ -272,7 +272,9 @@ public class CoyoteAdapter implements Adapter {
boolean comet = false;
boolean success = true;
AsyncContextImpl asyncConImpl = request.getAsyncContextInternal();
+
req.getRequestProcessor().setWorkerThreadName(Thread.currentThread().getName());
+
try {
if (!request.isAsync() && !comet) {
// Error or timeout
@@ -301,13 +303,14 @@ public class CoyoteAdapter implements Adapter {
// if the application doesn't define one)?
if (!request.isAsyncDispatching() && request.isAsync() &&
response.isErrorReportRequired()) {
- connector.getService().getContainer().getPipeline().getFirst().invoke(request, response);
+ connector.getService().getContainer().getPipeline().getFirst().invoke(
+ request, response);
}
if (request.isAsyncDispatching()) {
- connector.getService().getContainer().getPipeline().getFirst().invoke(request, response);
- Throwable t = (Throwable) request.getAttribute(
- RequestDispatcher.ERROR_EXCEPTION);
+ connector.getService().getContainer().getPipeline().getFirst().invoke(
+ request, response);
+ Throwable t = (Throwable) request.getAttribute(RequestDispatcher.ERROR_EXCEPTION);
if (t != null) {
asyncConImpl.setErrorState(t, true);
}
@@ -390,19 +393,14 @@ public class CoyoteAdapter implements Adapter {
}
- /**
- * Service method.
- */
@Override
- public void service(org.apache.coyote.Request req,
- org.apache.coyote.Response res)
- throws Exception {
+ public void service(org.apache.coyote.Request req, org.apache.coyote.Response res)
+ throws Exception {
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);
@@ -418,8 +416,7 @@ public class CoyoteAdapter implements Adapter {
res.setNote(ADAPTER_NOTES, response);
// Set query string encoding
- req.getParameters().setQueryStringEncoding
- (connector.getURIEncoding());
+ req.getParameters().setQueryStringEncoding(connector.getURIEncoding());
}
@@ -438,9 +435,11 @@ public class CoyoteAdapter implements Adapter {
postParseSuccess = postParseRequest(req, request, res, response);
if (postParseSuccess) {
//check valves if we support async
- request.setAsyncSupported(connector.getService().getContainer().getPipeline().isAsyncSupported());
+ request.setAsyncSupported(
+ connector.getService().getContainer().getPipeline().isAsyncSupported());
// Calling the container
- connector.getService().getContainer().getPipeline().getFirst().invoke(request, response);
+ connector.getService().getContainer().getPipeline().getFirst().invoke(
+ request, response);
if (request.isComet()) {
if (!response.isClosed() && !response.isError()) {
@@ -493,6 +492,7 @@ public class CoyoteAdapter implements Adapter {
req.action(ActionCode.POST_REQUEST , null);
}
}
+
} catch (IOException e) {
// Ignore
} finally {
@@ -574,8 +574,7 @@ public class CoyoteAdapter implements Adapter {
res.setNote(ADAPTER_NOTES, response);
// Set query string encoding
- req.getParameters().setQueryStringEncoding
- (connector.getURIEncoding());
+ req.getParameters().setQueryStringEncoding(connector.getURIEncoding());
}
try {
@@ -594,8 +593,7 @@ public class CoyoteAdapter implements Adapter {
}
}
if (!logged) {
- connector.getService().getContainer().logAccess(
- request, response, time, true);
+ connector.getService().getContainer().logAccess(request, response, time, true);
}
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
@@ -653,19 +651,30 @@ public class CoyoteAdapter implements Adapter {
// ------------------------------------------------------ Protected Methods
-
/**
- * Parse additional request parameters.
+ * Perform the necessary processing after the HTTP headers have been parsed
+ * to enable the request/response pair to be passed to the start of the
+ * container pipeline for processing.
+ *
+ * @param req The coyote request object
+ * @param request The catalina request object
+ * @param res The coyote response object
+ * @param response The catalina response object
+ *
+ * @return <code>true</code> if the request should be passed on to the start
+ * of the container pipeline, otherwise <code>false</code>
+ *
+ * @throws IOException If there is insufficient space in a buffer while
+ * processing headers
+ * @throws ServletException If the supported methods of the target servlet
+ * cannot be determined
*/
- protected boolean postParseRequest(org.apache.coyote.Request req,
- Request request,
- org.apache.coyote.Response res,
- Response response)
- throws Exception {
+ protected boolean postParseRequest(org.apache.coyote.Request req, Request request,
+ org.apache.coyote.Response res, Response response) throws Exception {
- // XXX the processor may have set a correct scheme and port prior to this point,
- // in ajp13 protocols don't make sense to get the port from the connector...
- // otherwise, use connector configuration
+ // If the processor has set the scheme (AJP does this, HTTP does this if
+ // SSL is enabled) use this to set the secure flag as well. If the
+ // processor hasn't set it, use the settings from the connector
if (! req.scheme().isNull()) {
// use processor specified scheme to determine secure state
request.setSecure(req.scheme().equals("https"));
@@ -676,9 +685,6 @@ public class CoyoteAdapter implements Adapter {
request.setSecure(connector.getSecure());
}
- // FIXME: the code below doesn't belongs to here,
- // this is only have sense
- // in Http11, not in ajp13..
// At this point the Host header has been processed.
// Override if the proxyPort/proxyHost are set
String proxyName = connector.getProxyName();
@@ -761,13 +767,14 @@ public class CoyoteAdapter implements Adapter {
while (mapRequired) {
// This will map the the latest version by default
- connector.getMapper().map(serverName, decodedURI, version,
- request.getMappingData());
+ connector.getMapper().map(serverName, decodedURI,
+ version, request.getMappingData());
request.setContext((Context) request.getMappingData().context);
request.setWrapper((Wrapper) request.getMappingData().wrapper);
- // If there is no context at this point, it is likely no ROOT context
- // has been deployed
+ // If there is no context at this point, either this is a 404
+ // because no ROOT context has been deployed or the URI was invalid
+ // so no context could be mapped.
if (request.getContext() == null) {
res.setStatus(404);
res.setMessage("Not found");
@@ -815,7 +822,7 @@ public class CoyoteAdapter implements Adapter {
// No session ID means no possibility of remap
if (contexts != null && sessionID != null) {
// Find the context associated with the session
- for (int i = (contexts.length); i > 0; i--) {
+ for (int i = contexts.length; i > 0; i--) {
Context ctxt = (Context) contexts[i - 1];
if (ctxt.getManager().findSession(sessionID) != null) {
// We found a context. Is it the one that has
@@ -946,9 +953,9 @@ public class CoyoteAdapter implements Adapter {
}
// Set the authorization type
- String authtype = req.getAuthType().toString();
- if (authtype != null) {
- request.setAuthType(authtype);
+ String authType = req.getAuthType().toString();
+ if (authType != null) {
+ request.setAuthType(authType);
}
}
@@ -959,8 +966,8 @@ public class CoyoteAdapter implements Adapter {
* interested in the session ID that will be in this form. Other parameters
* can safely be ignored.
*
- * @param req
- * @param request
+ * @param req The Coyote request object
+ * @param request The Servlet request object
*/
protected void parsePathParameters(org.apache.coyote.Request req,
Request request) {
@@ -1059,15 +1066,14 @@ public class CoyoteAdapter implements Adapter {
/**
* Look for SSL session ID if required. Only look for SSL Session ID if it
* is the only tracking method enabled.
+ *
+ * @param request The Servlet request object
*/
protected void parseSessionSslId(Request request) {
if (request.getRequestedSessionId() == null &&
SSL_ONLY.equals(request.getServletContext()
.getEffectiveSessionTrackingModes()) &&
request.connector.secure) {
- // TODO Is there a better way to map SSL sessions to our session ID?
- // TODO The request.getAttribute() will cause a number of other SSL
- // attribute to be populated. Is this a performance concern?
String sessionId = (String) request.getAttribute(SSLSupport.SESSION_ID_KEY);
if (sessionId != null) {
request.setRequestedSessionId(sessionId);
@@ -1079,6 +1085,8 @@ public class CoyoteAdapter implements Adapter {
/**
* Parse session id in Cookie.
+ *
+ * @param request The Servlet request object
*/
protected void parseSessionCookiesId(org.apache.coyote.Request req, Request request) {
@@ -1133,9 +1141,12 @@ public class CoyoteAdapter implements Adapter {
/**
* Character conversion of the URI.
+ *
+ * @param uri MessageBytes object containing the URI
+ * @param request The Servlet request object
+ * @throws IOException if a IO exception occurs sending an error to the client
*/
- protected void convertURI(MessageBytes uri, Request request)
- throws Exception {
+ protected void convertURI(MessageBytes uri, Request request) throws Exception {
ByteChunk bc = uri.getByteChunk();
int length = bc.getLength();
@@ -1183,6 +1194,8 @@ public class CoyoteAdapter implements Adapter {
/**
* Character conversion of the a US-ASCII MessageBytes.
+ *
+ * @param mb The MessageBytes instance containing the bytes that should be converted to chars
*/
protected void convertMB(MessageBytes mb) {
@@ -1209,13 +1222,13 @@ public class CoyoteAdapter implements Adapter {
/**
- * Normalize URI.
- * <p>
- * This method normalizes "\", "//", "/./" and "/../". This method will
- * return false when trying to go above the root, or if the URI contains
- * a null byte.
+ * This method normalizes "\", "//", "/./" and "/../".
*
* @param uriMB URI to be normalized
+ *
+ * @return <code>false</code> if normalizing this URI would require going
+ * above the root, or if the URI contains a null byte, otherwise
+ * <code>true</code>
*/
public static boolean normalize(MessageBytes uriMB) {
@@ -1321,13 +1334,14 @@ public class CoyoteAdapter implements Adapter {
/**
- * Check that the URI is normalized following character decoding.
- * <p>
- * This method checks for "\", 0, "//", "/./" and "/../". This method will
- * return false if sequences that are supposed to be normalized are still
- * present in the URI.
+ * Check that the URI is normalized following character decoding. This
+ * method checks for "\", 0, "//", "/./" and "/../".
*
* @param uriMB URI to be checked (should be chars)
+ *
+ * @return <code>false</code> if sequences that are supposed to be
+ * normalized are still present in the URI, otherwise
+ * <code>true</code>
*/
public static boolean checkNormalize(MessageBytes uriMB) {
@@ -1387,6 +1401,11 @@ public class CoyoteAdapter implements Adapter {
/**
* Copy an array of bytes to a different position. Used during
* normalization.
+ *
+ * @param b The bytes that should be copied
+ * @param dest Destination offset
+ * @param src Source offset
+ * @param len Length
*/
protected static void copyBytes(byte[] b, int dest, int src, int len) {
for (int pos = 0; pos < len; pos++) {
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org