@Override public void deploy() { DeploymentInfo deploymentInfo = originalDeployment.clone(); deploymentInfo.validate(); final DeploymentImpl deployment = new DeploymentImpl(deploymentInfo); this.deployment = deployment; final ServletContextImpl servletContext = new ServletContextImpl(servletContainer, deployment); deployment.setServletContext(servletContext); 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(); deployment.setApplicationListeners(listeners); // 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(); } } listeners.contextInitialized(); initializeErrorPages(deployment, deploymentInfo); initializeMimeMappings(deployment, deploymentInfo); initializeTempDir(servletContext, deploymentInfo); // run ServletPathMatches matches = setupServletChains(servletContext, threadSetupAction, listeners); deployment.setServletPaths(matches); HttpHandler wrappedHandlers = ServletDispatchingHandler.INSTANCE; wrappedHandlers = wrapHandlers(wrappedHandlers, deploymentInfo.getInnerHandlerChainWrappers()); HttpHandler securityHandler = setupSecurityHandlers(wrappedHandlers); wrappedHandlers = new PredicateHandler(DispatcherTypePredicate.REQUEST, securityHandler, wrappedHandlers); wrappedHandlers = wrapHandlers(wrappedHandlers, deploymentInfo.getOuterHandlerChainWrappers()); final ServletInitialHandler servletInitialHandler = new ServletInitialHandler( matches, wrappedHandlers, deployment.getThreadSetupAction(), servletContext); deployment.setServletHandler(servletInitialHandler); } catch (Exception e) { throw new RuntimeException(e); } finally { handle.tearDown(); } state = State.DEPLOYED; }
@Override public void deploy() { DeploymentInfo deploymentInfo = originalDeployment.clone(); if (deploymentInfo.getServletStackTraces() == ServletStackTraces.ALL) { UndertowServletLogger.REQUEST_LOGGER.servletStackTracesAll( deploymentInfo.getDeploymentName()); } deploymentInfo.validate(); final ConvergedDeploymentImpl deployment = new ConvergedDeploymentImpl(this, deploymentInfo, servletContainer); // set deployment to parent using reflection try { Field deploymentField = DeploymentManagerImpl.class.getDeclaredField("deployment"); deploymentField.setAccessible(true); deploymentField.set(this, deployment); deploymentField.setAccessible(false); } catch (NoSuchFieldException | IllegalAccessException e) { throw new RuntimeException(e); } final ServletContextImpl servletContexImpl = new ServletContextImpl(servletContainer, deployment); final ServletContext servletContext = new ConvergedServletContextImpl(servletContexImpl); // deployment.setServletContext(((ConvergedServletContextImpl)servletContext).getDelegatedContext()); this.invokeDeploymentMethod( deployment, "setServletContext", new Class[] {ServletContextImpl.class}, new Object[] {((ConvergedServletContextImpl) servletContext).getDelegatedContext()}); deployment.setConvergedServletContext((ConvergedServletContextImpl) servletContext); handleExtensions(deploymentInfo, servletContext); deployment.setDefaultCharset(Charset.forName(deploymentInfo.getDefaultEncoding())); handleDeploymentSessionConfig( deploymentInfo, ((ConvergedServletContextImpl) servletContext).getDelegatedContext()); // deployment.setSessionManager(deploymentInfo.getSessionManagerFactory().createSessionManager(deployment)); this.invokeDeploymentMethod( deployment, "setSessionManager", new Class[] {SessionManager.class}, new Object[] {deploymentInfo.getSessionManagerFactory().createSessionManager(deployment)}); deployment .getSessionManager() .setDefaultSessionTimeout(deploymentInfo.getDefaultSessionTimeout()); for (SessionListener listener : deploymentInfo.getSessionListeners()) { deployment.getSessionManager().registerSessionListener(listener); } final List<ThreadSetupAction> setup = new ArrayList<>(); setup.add(ServletRequestContextThreadSetupAction.INSTANCE); 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); this.invokeDeploymentMethod( deployment, "setApplicationListeners", new Class[] {ApplicationListeners.class}, new Object[] {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 ConvergedSessionListenerBridge( threadSetupAction, listeners, servletContext, deployment.getSessionManager())); 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); this.invokeDeploymentMethod( deployment, "setServletHandler", new Class[] {ServletInitialHandler.class}, new Object[] {servletInitialHandler}); deployment.getServletPaths().invalidate(); // make sure we have a fresh set of servlet paths ((ConvergedServletContextImpl) servletContext).initDone(); } catch (Exception e) { throw new RuntimeException(e); } finally { handle.tearDown(); } // set state using reflection: try { Field stateField = DeploymentManagerImpl.class.getDeclaredField("state"); stateField.setAccessible(true); stateField.set(this, State.DEPLOYED); stateField.setAccessible(false); } catch (NoSuchFieldException | IllegalAccessException e) { throw new RuntimeException(e); } }