tomcat 中StandardHostValve类的源码分析:
1、源码如下:
final class StandardHostValve extends ValveBase {
private static final Log log = LogFactory.getLog(StandardHostValve.class);
// Saves a call to getClassLoader() on very request. Under high load these
// calls took just long enough to appear as a hot spot (although a very
// minor one) in a profiler.
private static final ClassLoader MY_CLASSLOADER =
StandardHostValve.class.getClassLoader();
static final boolean STRICT_SERVLET_COMPLIANCE;
static final boolean ACCESS_SESSION;
static {
STRICT_SERVLET_COMPLIANCE = Globals.STRICT_SERVLET_COMPLIANCE;
String accessSession = System.getProperty(
"org.apache.catalina.core.StandardHostValve.ACCESS_SESSION");
if (accessSession == null) {
ACCESS_SESSION = STRICT_SERVLET_COMPLIANCE;
} else {
ACCESS_SESSION = Boolean.parseBoolean(accessSession);
}
}
//------------------------------------------------------ Constructor
public StandardHostValve() {
super(true);
}
// ----------------------------------------------------- Instance Variables
/**
* The string manager for this package.
*/
private static final StringManager sm =
StringManager.getManager(Constants.Package);
// --------------------------------------------------------- Public Methods
/**
* Select the appropriate child Context to process this request,
* based on the specified request URI. If no matching Context can
* be found, return an appropriate HTTP error.
*
* @param request Request to be processed
* @param response Response to be produced
*
* @exception IOException if an input/output error occurred
* @exception ServletException if a servlet error occurred
*/
@Override
public final void invoke(Request request, Response response)
throws IOException, ServletException {
// Select the Context to be used for this Request
Context context = request.getContext();
if (context == null) {
return;
}
if (request.isAsyncSupported()) {
request.setAsyncSupported(context.getPipeline().isAsyncSupported());
}
boolean asyncAtStart = request.isAsync();
try {
context.bind(Globals.IS_SECURITY_ENABLED, MY_CLASSLOADER);
if (!asyncAtStart && !context.fireRequestInitEvent(request.getRequest())) {
// Don't fire listeners during async processing (the listener
// fired for the request that called startAsync()).
// If a request init listener throws an exception, the request
// is aborted.
return;
}