deploymentInfo.validate();
final DeploymentImpl deployment = new DeploymentImpl(this, deploymentInfo, servletContainer);
this.deployment = deployment;
final ServletContextImpl servletContext = new ServletContextImpl(servletContainer, deployment);
deployment.setServletContext(servletContext);
handleExtensions(deploymentInfo, servletContext);
deployment.setDefaultCharset(Charset.forName(deploymentInfo.getDefaultEncoding()));
handleDeploymentSessionConfig(deploymentInfo, servletContext);
deployment.setSessionManager(deploymentInfo.getSessionManagerFactory().createSessionManager(deployment));
deployment.getSessionManager().setDefaultSessionTimeout(deploymentInfo.getDefaultSessionTimeout());
final List<ThreadSetupAction> setup = new ArrayList<ThreadSetupAction>();
setup.add(new ContextClassLoaderSetupAction(deploymentInfo.getClassLoader()));
setup.addAll(deploymentInfo.getThreadSetupActions());
final CompositeThreadSetupAction threadSetupAction = new CompositeThreadSetupAction(setup);
deployment.setThreadSetupAction(threadSetupAction);
ThreadSetupAction.Handle handle = threadSetupAction.setup(null);
try {
final ApplicationListeners listeners = createListeners();
listeners.start();
deployment.setApplicationListeners(listeners);
//now create the servlets and filters that we know about. We can still get more later
createServletsAndFilters(deployment, deploymentInfo);
//first run the SCI's
for (final ServletContainerInitializerInfo sci : deploymentInfo.getServletContainerInitializers()) {
final InstanceHandle<? extends ServletContainerInitializer> instance = sci.getInstanceFactory().createInstance();
try {
instance.getInstance().onStartup(sci.getHandlesTypes(), servletContext);
} finally {
instance.release();
}
}
deployment.getSessionManager().registerSessionListener(new SessionListenerBridge(threadSetupAction, listeners, servletContext));
initializeErrorPages(deployment, deploymentInfo);
initializeMimeMappings(deployment, deploymentInfo);
initializeTempDir(servletContext, deploymentInfo);
listeners.contextInitialized();
//run
HttpHandler wrappedHandlers = ServletDispatchingHandler.INSTANCE;
wrappedHandlers = wrapHandlers(wrappedHandlers, deploymentInfo.getInnerHandlerChainWrappers());
HttpHandler securityHandler = setupSecurityHandlers(wrappedHandlers);
wrappedHandlers = new PredicateHandler(DispatcherTypePredicate.REQUEST, securityHandler, wrappedHandlers);
HttpHandler outerHandlers = wrapHandlers(wrappedHandlers, deploymentInfo.getOuterHandlerChainWrappers());
wrappedHandlers = new PredicateHandler(DispatcherTypePredicate.REQUEST, outerHandlers, wrappedHandlers);
wrappedHandlers = handleDevelopmentModePersistentSessions(wrappedHandlers, deploymentInfo, deployment.getSessionManager(), servletContext);
MetricsCollector metrics = deploymentInfo.getMetricsCollector();
if(metrics != null) {
wrappedHandlers = new MetricsChainHandler(wrappedHandlers, metrics, deployment);
}
final ServletInitialHandler servletInitialHandler = SecurityActions.createServletInitialHandler(deployment.getServletPaths(), wrappedHandlers, deployment.getThreadSetupAction(), servletContext);
HttpHandler initialHandler = wrapHandlers(servletInitialHandler, deployment.getDeploymentInfo().getInitialHandlerChainWrappers());
initialHandler = new HttpContinueReadHandler(initialHandler);
if(deploymentInfo.getUrlEncoding() != null) {
initialHandler = Handlers.urlDecodingHandler(deploymentInfo.getUrlEncoding(), initialHandler);
}
deployment.setInitialHandler(initialHandler);
deployment.setServletHandler(servletInitialHandler);
deployment.getServletPaths().invalidate(); //make sure we have a fresh set of servlet paths
servletContext.initDone();
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
handle.tearDown();
}