@Override public void cancel() { if (WildFlySecurityManager.isChecking()) { doPrivileged((PrivilegedAction<Void>) () -> { SecurityDomain.unregisterClassLoader(deploymentInfo.getClassLoader()); return null; }); } else { SecurityDomain.unregisterClassLoader(deploymentInfo.getClassLoader()); } synchronized(registrations) { registrations.remove(this); } }
public void startContext() throws ServletException { final ClassLoader old = Thread.currentThread().getContextClassLoader(); DeploymentInfo deploymentInfo = deploymentInfoInjectedValue.getValue(); Thread.currentThread().setContextClassLoader(deploymentInfo.getClassLoader()); try { StartupContext.setInjectionContainer(webInjectionContainer); try { deploymentManager = container.getValue().getServletContainer().addDeployment(deploymentInfo); deploymentManager.deploy(); HttpHandler handler = deploymentManager.start(); Deployment deployment = deploymentManager.getDeployment(); host.getValue().registerDeployment(deployment, handler); } finally { StartupContext.setInjectionContainer(null); } } finally { Thread.currentThread().setContextClassLoader(old); } }
public void stopContext() { final ClassLoader old = Thread.currentThread().getContextClassLoader(); DeploymentInfo deploymentInfo = deploymentInfoInjectedValue.getValue(); Thread.currentThread().setContextClassLoader(deploymentInfo.getClassLoader()); try { if (deploymentManager != null) { Deployment deployment = deploymentManager.getDeployment(); try { host.getValue().unregisterDeployment(deployment); deploymentManager.stop(); } catch (ServletException e) { throw new RuntimeException(e); } deploymentManager.undeploy(); container.getValue().getServletContainer().removeDeployment(deploymentInfoInjectedValue.getValue()); } recursiveDelete(deploymentInfoInjectedValue.getValue().getTempDir()); } finally { Thread.currentThread().setContextClassLoader(old); } }
@Override public ClassLoader getClassLoader() { return deploymentInfo.getClassLoader(); }
@Override public void addListener(final String className) { try { Class<? extends EventListener> clazz = (Class<? extends EventListener>) deploymentInfo.getClassLoader().loadClass(className); addListener(clazz); } catch (ClassNotFoundException e) { throw new IllegalArgumentException(e); } }
@Override public void cancel() { if (WildFlySecurityManager.isChecking()) { doPrivileged((PrivilegedAction<Void>) () -> { SecurityDomain.unregisterClassLoader(deploymentInfo.getClassLoader()); return null; }); } else { SecurityDomain.unregisterClassLoader(deploymentInfo.getClassLoader()); } synchronized(registrations) { registrations.remove(this); } }
@Override public void cancel() { if (WildFlySecurityManager.isChecking()) { doPrivileged((PrivilegedAction<Void>) () -> { SecurityDomain.unregisterClassLoader(deploymentInfo.getClassLoader()); return null; }); } else { SecurityDomain.unregisterClassLoader(deploymentInfo.getClassLoader()); } synchronized(registrations) { registrations.remove(this); } }
private void handleExtensions(final DeploymentInfo deploymentInfo, final ServletContext servletContext) { Set<Class<?>> loadedExtensions = new HashSet<>(); for (ServletExtension extension : ServiceLoader.load(ServletExtension.class, deploymentInfo.getClassLoader())) { loadedExtensions.add(extension.getClass()); extension.handleDeployment(deploymentInfo, servletContext); } if (!ServletExtension.class.getClassLoader().equals(deploymentInfo.getClassLoader())) { for (ServletExtension extension : ServiceLoader.load(ServletExtension.class)) { // Note: If the CLs are different, but can the see the same extensions and extension might get loaded // and thus instantiated twice, but the handleDeployment() is executed only once. if (!loadedExtensions.contains(extension.getClass())) { extension.handleDeployment(deploymentInfo, servletContext); } } } for(ServletExtension extension : deploymentInfo.getServletExtensions()) { extension.handleDeployment(deploymentInfo, servletContext); } }
private void handleExtensions(final DeploymentInfo deploymentInfo, final ServletContext servletContext) { Set<Class<?>> loadedExtensions = new HashSet<>(); for (ServletExtension extension : ServiceLoader.load(ServletExtension.class, deploymentInfo.getClassLoader())) { loadedExtensions.add(extension.getClass()); extension.handleDeployment(deploymentInfo, servletContext); } if (!ServletExtension.class.getClassLoader().equals(deploymentInfo.getClassLoader())) { for (ServletExtension extension : ServiceLoader.load(ServletExtension.class)) { // Note: If the CLs are different, but can the see the same extensions and extension might get loaded // and thus instantiated twice, but the handleDeployment() is executed only once. if (!loadedExtensions.contains(extension.getClass())) { extension.handleDeployment(deploymentInfo, servletContext); } } } for(ServletExtension extension : deploymentInfo.getServletExtensions()) { extension.handleDeployment(deploymentInfo, servletContext); } }
private void handleExtensions(final DeploymentInfo deploymentInfo, final ServletContextImpl servletContext) { Set<String> loadedExtensions = new HashSet<>(); for (ServletExtension extension : ServiceLoader.load(ServletExtension.class, deploymentInfo.getClassLoader())) { loadedExtensions.add(extension.getClass().getName()); extension.handleDeployment(deploymentInfo, servletContext); } if (ServletExtension.class.getClassLoader() != null && !ServletExtension.class.getClassLoader().equals(deploymentInfo.getClassLoader())) { for (ServletExtension extension : ServiceLoader.load(ServletExtension.class)) { // Note: If the CLs are different, but can the see the same extensions and extension might get loaded // and thus instantiated twice, but the handleDeployment() is executed only once. if (!loadedExtensions.contains(extension.getClass().getName())) { extension.handleDeployment(deploymentInfo, servletContext); } } } for (ServletExtension extension : ServletExtensionHolder.getServletExtensions()) { if (!loadedExtensions.contains(extension.getClass().getName())) { extension.handleDeployment(deploymentInfo, servletContext); } } for(ServletExtension extension : deploymentInfo.getServletExtensions()) { extension.handleDeployment(deploymentInfo, servletContext); } }
@Bean public WebServerFactoryCustomizer<UndertowServletWebServerFactory> jsfUndertowFactoryCustomizer() { return factory -> factory.addDeploymentInfoCustomizers(deploymentInfo -> { AccessController.doPrivileged((PrivilegedAction<Void>) () -> { deploymentInfo.setResourceManager(new CompositeResourceManager( new ClassPathResourceManager(deploymentInfo.getClassLoader(), this.undertowProperties.getClassPathResource()), deploymentInfo.getResourceManager())); return null; }); log.info("Setting Undertow classLoader to {} directory", this.undertowProperties.getClassPathResource()); }); } }
private void undeploy(DeploymentManager deploymentManager) { final Deployment deployment = deploymentManager.getDeployment(); CamelLogger.LOGGER.debug("Undeploying endpoint {}", deployment.getDeploymentInfo().getDeploymentName()); final ClassLoader old = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(deployment.getDeploymentInfo().getClassLoader()); try { try { hostSupplier.getValue().unregisterDeployment(deployment); deploymentManager.stop(); } catch (ServletException e) { throw new RuntimeException(e); } deploymentManager.undeploy(); servletContainerServiceSupplier.getValue().getServletContainer().removeDeployment(deployment.getDeploymentInfo()); } finally { Thread.currentThread().setContextClassLoader(old); } }
@Override public void handleDeployment(DeploymentInfo deploymentInfo, ServletContext servletContext) { if (servletContext.getAttribute(ATTRIBUTE_NAME) == null) { UndertowJWebMPHandlerExtension.log.fine("Registering Guice Filter in Undertow"); deploymentInfo.addFilter(new FilterInfo("GuiceFilter", GuiceFilter.class).setAsyncSupported(true)); deploymentInfo.addFilterUrlMapping("GuiceFilter", "/*", DispatcherType.REQUEST); deploymentInfo.addListener(new ListenerInfo(GuicedServletSessionManager.class)); } else { UndertowJWebMPHandlerExtension.log.fine("Requested to configure guice for web sockets - skipped. - " + deploymentInfo.getDeploymentName()); } UndertowJWebMPHandlerExtension.log.config("Configuring Resources to be found in META-INF/resources"); deploymentInfo.setResourceManager(new ClassPathResourceManager(deploymentInfo.getClassLoader(), "META-INF/resources")); UndertowJWebMPHandlerExtension.log.fine("Undertow Configured"); } }
private void undeploy(DeploymentManager deploymentManager) { final Deployment deployment = deploymentManager.getDeployment(); CamelLogger.LOGGER.debug("Undeploying endpoint {}", deployment.getDeploymentInfo().getDeploymentName()); final ClassLoader old = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(deployment.getDeploymentInfo().getClassLoader()); try { try { hostSupplier.getValue().unregisterDeployment(deployment); deploymentManager.stop(); } catch (ServletException e) { throw new RuntimeException(e); } deploymentManager.undeploy(); servletContainerServiceSupplier.getValue().getServletContainer().removeDeployment(deployment.getDeploymentInfo()); } finally { Thread.currentThread().setContextClassLoader(old); } }
public void startContext() throws ServletException { final ClassLoader old = Thread.currentThread().getContextClassLoader(); DeploymentInfo deploymentInfo = deploymentInfoInjectedValue.getValue(); Thread.currentThread().setContextClassLoader(deploymentInfo.getClassLoader()); try { StartupContext.setInjectionContainer(webInjectionContainer); try { deploymentManager = container.getValue().getServletContainer().addDeployment(deploymentInfo); deploymentManager.deploy(); HttpHandler handler = deploymentManager.start(); Deployment deployment = deploymentManager.getDeployment(); host.getValue().registerDeployment(deployment, handler); } finally { StartupContext.setInjectionContainer(null); } } finally { Thread.currentThread().setContextClassLoader(old); } }
public void startContext() throws ServletException { final ClassLoader old = Thread.currentThread().getContextClassLoader(); DeploymentInfo deploymentInfo = deploymentInfoInjectedValue.getValue(); Thread.currentThread().setContextClassLoader(deploymentInfo.getClassLoader()); try { StartupContext.setInjectionContainer(webInjectionContainer); try { deploymentManager = container.getValue().getServletContainer().addDeployment(deploymentInfo); deploymentManager.deploy(); HttpHandler handler = deploymentManager.start(); Deployment deployment = deploymentManager.getDeployment(); host.getValue().registerDeployment(deployment, handler); } finally { StartupContext.setInjectionContainer(null); } } finally { Thread.currentThread().setContextClassLoader(old); } }
public void stopContext() { final ClassLoader old = Thread.currentThread().getContextClassLoader(); DeploymentInfo deploymentInfo = deploymentInfoInjectedValue.getValue(); Thread.currentThread().setContextClassLoader(deploymentInfo.getClassLoader()); try { if (deploymentManager != null) { Deployment deployment = deploymentManager.getDeployment(); try { host.getValue().unregisterDeployment(deployment); deploymentManager.stop(); } catch (ServletException e) { throw new RuntimeException(e); } deploymentManager.undeploy(); container.getValue().getServletContainer().removeDeployment(deploymentInfoInjectedValue.getValue()); } recursiveDelete(deploymentInfoInjectedValue.getValue().getTempDir()); } finally { Thread.currentThread().setContextClassLoader(old); } }
public void stopContext() { final ClassLoader old = Thread.currentThread().getContextClassLoader(); DeploymentInfo deploymentInfo = deploymentInfoInjectedValue.getValue(); Thread.currentThread().setContextClassLoader(deploymentInfo.getClassLoader()); try { if (deploymentManager != null) { Deployment deployment = deploymentManager.getDeployment(); try { host.getValue().unregisterDeployment(deployment); deploymentManager.stop(); } catch (ServletException e) { throw new RuntimeException(e); } deploymentManager.undeploy(); container.getValue().getServletContainer().removeDeployment(deploymentInfoInjectedValue.getValue()); } recursiveDelete(deploymentInfoInjectedValue.getValue().getTempDir()); } finally { Thread.currentThread().setContextClassLoader(old); } }
@Override public FilterRegistration.Dynamic addFilter(final String filterName, final String className) { ensureNotProgramaticListener(); ensureNotInitialized(); if (deploymentInfo.getFilters().containsKey(filterName)) { return null; } try { Class<? extends Filter> filterClass=(Class<? extends Filter>) deploymentInfo.getClassLoader().loadClass(className); FilterInfo filter = new FilterInfo(filterName, filterClass, deploymentInfo.getClassIntrospecter().createInstanceFactory(filterClass)); deploymentInfo.addFilter(filter); deployment.getFilters().addFilter(filter); return new FilterRegistrationImpl(filter, deployment, this); } catch (ClassNotFoundException e) { throw UndertowServletMessages.MESSAGES.cannotLoadClass(className, e); }catch (NoSuchMethodException e) { throw UndertowServletMessages.MESSAGES.couldNotCreateFactory(className,e); } }
public ServletRegistration.Dynamic addServlet(final String servletName, final String className, List<HandlerWrapper> wrappers) { ensureNotProgramaticListener(); ensureNotInitialized(); ensureServletNameNotNull(servletName); try { if (deploymentInfo.getServlets().containsKey(servletName)) { return null; } Class<? extends Servlet> servletClass=(Class<? extends Servlet>) deploymentInfo.getClassLoader().loadClass(className); ServletInfo servlet = new ServletInfo(servletName, servletClass, deploymentInfo.getClassIntrospecter().createInstanceFactory(servletClass)); for(HandlerWrapper i : wrappers) { servlet.addHandlerChainWrapper(i); } readServletAnnotations(servlet); deploymentInfo.addServlet(servlet); ServletHandler handler = deployment.getServlets().addServlet(servlet); return new ServletRegistrationImpl(servlet, handler.getManagedServlet(), deployment); } catch (ClassNotFoundException e) { throw UndertowServletMessages.MESSAGES.cannotLoadClass(className, e); } catch (NoSuchMethodException e) { throw UndertowServletMessages.MESSAGES.couldNotCreateFactory(className,e); } }