| Method from org.apache.coyote.tomcat5.CoyoteAdapter Detail: |
public void afterService(Request req,
Response res) throws Exception {
CoyoteRequest request = (CoyoteRequest) req.getNote(ADAPTER_NOTES);
CoyoteResponse response = (CoyoteResponse) res.getNote(ADAPTER_NOTES);
if ( request == null || response == null) return;
try{
response.finishResponse();
req.action( ActionCode.ACTION_POST_REQUEST , null);
}catch (Throwable t) {
log.error(sm.getString("coyoteAdapter.service"), t);
} finally {
// Recycle the wrapper request and response
request.recycle();
response.recycle();
}
}
Finish the response and close the connection based on the connection
header. |
protected static void copyBytes(byte[] b,
int dest,
int src,
int len) {
for (int pos = 0; pos < len; pos++) {
b[pos + dest] = b[pos + src];
}
}
Copy an array of bytes to a different position. Used during
normalization. |
public void fireAdapterEvent(String type,
Object data) {
if ( connector != null && connector.getContainer() != null) {
try{
((ContainerBase)connector.getContainer())
.fireContainerEvent(type,data);
} catch (Throwable t){
log.error(sm.getString("coyoteAdapter.service"), t);
}
}
}
Notify all container event listeners that a particular event has
occurred for this Adapter. The default implementation performs
this notification synchronously using the calling thread. |
public boolean isCompatWithTomcat() {
return compatWithTomcat;
}
Return true when an instance is executed the same way it does in Tomcat. |
protected void log(String message) {
log.info( message );
}
Log a message on the Logger associated with our Container (if any) |
protected void log(String message,
Throwable throwable) {
log.error( message, throwable);
}
Log a message on the Logger associated with our Container (if any) |
public static boolean normalize(MessageBytes uriMB) {
int type = uriMB.getType();
if (type == MessageBytes.T_CHARS) {
return normalizeChars(uriMB);
} else {
return normalizeBytes(uriMB);
}
}
Normalize URI.
This method normalizes "\", "//", "/./" and "/../". This method will
return false when trying to go above the root, or if the URI contains
a null byte. |
protected boolean postParseRequest(Request req,
CoyoteRequest request,
Response res,
CoyoteResponse response) throws Exception {
// XXX the processor needs to set a correct scheme and port prior to this point,
// in ajp13 protocols dont make sense to get the port from the connector..
// XXX the processor may have set a correct scheme and port prior to this point,
// in ajp13 protocols dont make sense to get the port from the connector...
// otherwise, use connector configuration
if (! req.scheme().isNull()) {
// use processor specified scheme to determine secure state
request.setSecure(req.scheme().equals("https"));
} else {
// use connector scheme and secure configuration, (defaults to
// "http" and false respectively)
req.scheme().setString(connector.getScheme());
request.setSecure(connector.getSecure());
}
// FIXME: the code below doesnt 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();
int proxyPort = connector.getProxyPort();
if (proxyPort != 0) {
req.setServerPort(proxyPort);
}
if (proxyName != null) {
req.serverName().setString(proxyName);
}
// URI decoding
MessageBytes decodedURI = req.decodedURI();
decodedURI.duplicate(req.requestURI());
try {
req.getURLDecoder().convert(decodedURI, false);
} catch (IOException ioe) {
res.setStatus(400);
res.setMessage("Invalid URI: " + ioe.getMessage());
return false;
}
/* GlassFish Issue 2339
// Normalize decoded URI
if (!normalize(req.decodedURI())) {
res.setStatus(400);
res.setMessage("Invalid URI");
return false;
}
*/
// Set the remote principal
String principal = req.getRemoteUser().toString();
if (principal != null) {
request.setUserPrincipal(new CoyotePrincipal(principal));
}
// Set the authorization type
String authtype = req.getAuthType().toString();
if (authtype != null) {
request.setAuthType(authtype);
}
/* CR 6309511
// URI character decoding
convertURI(decodedURI, request);
// Parse session Id
parseSessionId(req, request);
*/
// START CR 6309511
// URI character decoding
request.convertURI(decodedURI);
// START GlassFish Issue 2339
// Normalize decoded URI
if (!normalize(decodedURI)) {
res.setStatus(400);
res.setMessage("Invalid URI");
return false;
}
// END GlassFish Issue 2339
// Parse session Id
request.parseSessionId();
// END CR 6309511
// Remove any remaining parameters (other than session id, which has
// already been removed in parseSessionId()) from the URI, so they
// won't be considered by the mapping algorithm.
CharChunk uriCC = decodedURI.getCharChunk();
int semicolon = uriCC.indexOf(';');
String sessionVersionString = null;
if (semicolon > 0) {
sessionVersionString = request.parseSessionVersion();
decodedURI.setChars
(uriCC.getBuffer(), uriCC.getStart(), semicolon);
}
// Request mapping.
connector.getMapper().map(req.serverName(), decodedURI,
request.getMappingData());
// START GlassFish 1024
request.setDefaultContext(request.getMappingData().isDefaultContext);
// END GlassFish 1024
// START SJSAS 6253524
// request.setContext((Context) request.getMappingData().context);
// END SJSAS 6253524
// START SJSAS 6253524
Context ctx = (Context) request.getMappingData().context;
request.setContext(ctx);
// END SJSAS 6253524
request.setWrapper((Wrapper) request.getMappingData().wrapper);
// Filter trace method
if (!connector.getAllowTrace()
&& req.method().equalsIgnoreCase("TRACE")) {
Wrapper wrapper = request.getWrapper();
String header = null;
if (wrapper != null) {
String[] methods = wrapper.getServletMethods();
if (methods != null) {
for (int i=0; i< methods.length; i++) {
// Exclude TRACE from methods returned in Allow header
if ("TRACE".equals(methods[i])) {
continue;
}
if (header == null) {
header = methods[i];
} else {
header += ", " + methods[i];
}
}
}
}
res.setStatus(405);
res.addHeader("Allow", header);
res.setMessage("TRACE method is not allowed");
return false;
}
// Possible redirect
MessageBytes redirectPathMB = request.getMappingData().redirectPath;
// START SJSAS 6253524
// if (!redirectPathMB.isNull()) {
// END SJSAS 6253524
// START SJSAS 6253524
if (!redirectPathMB.isNull()
&& (!ctx.hasAdHocPaths()
|| (ctx.getAdHocServletName(((HttpServletRequest)
request.getRequest()).getServletPath()) == null))) {
// END SJSAS 6253524
String redirectPath = redirectPathMB.toString();
String query = request.getQueryString();
if (request.isRequestedSessionIdFromURL()) {
// This is not optimal, but as this is not very common, it
// shouldn't matter
redirectPath = redirectPath + ";jsessionid="
+ request.getRequestedSessionId();
}
// START GlassFish 936
redirectPath = urlEncoder.encodeURL(redirectPath);
// END GlassFish 936
if (query != null) {
// This is not optimal, but as this is not very common, it
// shouldn't matter
redirectPath = redirectPath + "?" + query;
}
// START CR 6590921
boolean authPassthroughEnabled =
connector.getAuthPassthroughEnabled();
ProxyHandler proxyHandler = connector.getProxyHandler();
if (authPassthroughEnabled && proxyHandler != null) {
if (proxyHandler.getSSLKeysize(
(HttpServletRequest)request.getRequest()) > 0) {
request.setSecure(true);
}
}
// END CR 6590921
response.sendRedirect(redirectPath);
return false;
}
// Parse session Id
/* CR 6309511
parseSessionCookiesId(req, request);
*/
// START CR 6309511
request.parseSessionCookiesId();
// END CR 6309511
// START SJSAS 6346226
request.parseJrouteCookie();
// END SJSAS 6346226
if (sessionVersionString != null) {
request.parseSessionVersionString(sessionVersionString);
}
return true;
}
Parse additional request parameters. |
public void service(Request req,
Response res) throws Exception {
CoyoteRequest request = (CoyoteRequest) req.getNote(ADAPTER_NOTES);
CoyoteResponse response = (CoyoteResponse) res.getNote(ADAPTER_NOTES);
if (request == null) {
// Create objects
request = (CoyoteRequest) connector.createRequest();
request.setCoyoteRequest(req);
response = (CoyoteResponse) 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());
}
// START SJSAS 6331392
// Check connector for disabled state
if (!connector.isEnabled()) {
String msg = sm.getString("coyoteAdapter.listenerOff",
String.valueOf(connector.getPort()));
if (log.isDebugEnabled()) {
log.debug(msg);
}
response.sendError(HttpServletResponse.SC_NOT_FOUND, msg);
return;
}
// END SJSAS 6331392
if (connector.isXpoweredBy()) {
response.addHeader("X-Powered-By", "Servlet/2.5");
}
try {
// Parse and set Catalina and configuration specific
// request parameters
if ( postParseRequest(req, request, res, response) ) {
// START S1AS 6188932
boolean authPassthroughEnabled =
connector.getAuthPassthroughEnabled();
ProxyHandler proxyHandler = connector.getProxyHandler();
if (authPassthroughEnabled && proxyHandler != null) {
// START SJSAS 6397218
if (proxyHandler.getSSLKeysize(
(HttpServletRequest)request.getRequest()) > 0) {
request.setSecure(true);
}
// END SJSAS 6397218
X509Certificate[] certs = null;
try {
certs = proxyHandler.getSSLClientCertificateChain(
request.getRequest());
} catch (CertificateException ce) {
log.error(sm.getString(
"coyoteAdapter.proxyAuthCertError"),
ce);
}
if (certs != null) {
request.setAttribute(Globals.CERTIFICATES_ATTR,
certs);
}
}
// END S1AS 6188932
response.addHeader("Server",serverName);
// Calling the container
connector.getContainer().invoke(request, response);
}
/* GlassFish Issue 79
response.finishResponse();
req.action( ActionCode.ACTION_POST_REQUEST , null);
} catch (IOException e) {
;
} catch (Throwable t) {
log.error(sm.getString("coyoteAdapter.service"), t);
} finally {
// Recycle the wrapper request and response
request.recycle();
response.recycle();
}*/
// START GlassFish Issue 798
} catch (IOException e) {
// Recycle the wrapper request and response
request.recycle();
response.recycle();
} catch (Throwable t) {
log.error(sm.getString("coyoteAdapter.service"), t);
// Recycle the wrapper request and response
request.recycle();
response.recycle();
}
// END GlassFish Issue 798
if ( compatWithTomcat ) {
afterService(req,res);
}
}
|
public void setCompatWithTomcat(boolean compatWithTomcat) {
this.compatWithTomcat = compatWithTomcat;
// Add server header
if (compatWithTomcat){
serverName = "Apache/" + serverName;
} else {
// Recalculate.
serverName = System.getProperty("product.name");
}
}
true if this class needs to be compatible with Tomcat
Adapter class. Since Tomcat Adapter implementation doesn't support
the afterService method, the afterService method must be invoked
inside the service method. |