protected int initServer() throws Exception { DeploymentInfo servletBuilder = Servlets.deployment() .setClassLoader(getClass().getClassLoader()) .setContextPath("/") .setDeploymentName("test.war"); init(servletBuilder); DeploymentManager manager = Servlets.defaultContainer().addDeployment(servletBuilder); manager.deploy(); server = Undertow.builder() .addHttpListener(0, "127.0.0.1") .setHandler(manager.start()).build(); server.start(); return ((InetSocketAddress) server.getListenerInfo().get(0).getAddress()).getPort(); }
@Override public WebDeploymentController addWebDeployment(final WebDeploymentBuilder webDeploymentBuilder) throws Exception { DeploymentInfo d = new DeploymentInfo(); d.setDeploymentName(webDeploymentBuilder.getContextRoot()); d.setContextPath(webDeploymentBuilder.getContextRoot()); d.setClassLoader(webDeploymentBuilder.getClassLoader()); d.setResourceManager(new PathResourceManager(webDeploymentBuilder.getDocumentRoot().toPath().toAbsolutePath(), 1024 * 1024)); d.setIgnoreFlush(false); for (ServletBuilder servlet : webDeploymentBuilder.getServlets()) { ServletInfo s; if (servlet.getServlet() == null) { s = new ServletInfo(servlet.getServletName(), (Class<? extends Servlet>) servlet.getServletClass()); } else { s = new ServletInfo(servlet.getServletName(), (Class<? extends Servlet>) servlet.getServletClass(), new ImmediateInstanceFactory<>(servlet.getServlet())); } if (servlet.isForceInit()) { s.setLoadOnStartup(1); } s.addMappings(servlet.getUrlMappings()); for (Map.Entry<String, String> param : servlet.getInitParams().entrySet()) { s.addInitParam(param.getKey(), param.getValue()); } d.addServlet(s); } if (controlPoint != null) { d.addOuterHandlerChainWrapper(GlobalRequestControllerHandler.wrapper(controlPoint, webDeploymentBuilder.getAllowRequestPredicates())); } return new WebDeploymentControllerImpl(d); }
.addMapping("/").setAsyncSupported(true); DeploymentInfo servletBuilder = deployment() .setClassLoader(UndertowTestServer.class.getClassLoader()) .setDeploymentName("undertow-websocket-test") .setContextPath("/")
/** * Creates a web deployment for the jaxrs Application. Will ignore any @ApplicationPath annotation. * * @param application * @param mapping resteasy.servlet.mapping.prefix * @return */ public DeploymentInfo undertowDeployment(Class<? extends Application> application, String mapping) { ResteasyDeployment deployment = new ResteasyDeploymentImpl(); deployment.setApplicationClass(application.getName()); DeploymentInfo di = undertowDeployment(deployment, mapping); di.setClassLoader(application.getClassLoader()); return di; }
d.setClassLoader(module.getClassLoader()); final String servletVersion = mergedMetaData.getServletVersion(); if (servletVersion != null) {
registerServletContainerInitializerToDriveServletContextInitializers(deployment, initializers); deployment.setClassLoader(getServletClassLoader()); deployment.setContextPath(getContextPath()); deployment.setDisplayName(getDisplayName());
public UndertowJaxrsServer deploy(ResteasyDeployment deployment, String contextPath, Map<String, String> contextParams, Map<String, String> initParams) { if (contextPath == null) contextPath = "/"; if (!contextPath.startsWith("/")) contextPath = "/" + contextPath; DeploymentInfo builder = undertowDeployment(deployment); builder.setContextPath(contextPath); builder.setDeploymentName("Resteasy" + contextPath); builder.setClassLoader(deployment.getApplication().getClass().getClassLoader()); if (contextParams != null) { for (Entry<String, String> e : contextParams.entrySet()) { builder.addInitParameter(e.getKey(), e.getValue()); } } if (initParams != null) { ServletInfo servletInfo = builder.getServlets().get("ResteasyServlet"); for (Entry<String, String> e : initParams.entrySet()) { servletInfo.addInitParam(e.getKey(), e.getValue()); } } return deploy(builder); }
public UndertowJaxrsServer deployToServer(UndertowJaxrsServer server, Class<? extends Application> application, String contextPath) { ResteasyDeployment deployment = new ResteasyDeploymentImpl(); deployment.setApplicationClass(application.getName()); DeploymentInfo di = server.undertowDeployment(deployment); di.setClassLoader(application.getClassLoader()); di.setContextPath(contextPath); di.setDeploymentName("Resteasy" + contextPath); return server.deploy(di); } }
/** * Creates a web deployment for the jaxrs Application. Will ignore any @ApplicationPath annotation. * * @param application * @param contextPath * @return */ public UndertowJaxrsServer deploy(Class<? extends Application> application, String contextPath) { if (contextPath == null) contextPath = "/"; if (!contextPath.startsWith("/")) contextPath = "/" + contextPath; ResteasyDeployment deployment = new ResteasyDeploymentImpl(); deployment.setApplicationClass(application.getName()); DeploymentInfo di = undertowDeployment(deployment); di.setClassLoader(application.getClassLoader()); di.setContextPath(contextPath); di.setDeploymentName("Resteasy" + contextPath); return deploy(di); }
/** * Creates a web deployment for the jaxrs Application. Will ignore any @ApplicationPath annotation. * * @param application * @param contextPath * @return */ public UndertowJaxrsServer deploy(Application application, String contextPath) { if (contextPath == null) contextPath = "/"; if (!contextPath.startsWith("/")) contextPath = "/" + contextPath; ResteasyDeployment deployment = new ResteasyDeploymentImpl(); deployment.setApplication(application); DeploymentInfo di = undertowDeployment(deployment); di.setClassLoader(application.getClass().getClassLoader()); di.setContextPath(contextPath); di.setDeploymentName("Resteasy" + contextPath); return deploy(di); }
protected DeploymentManager createPippoDeploymentManager() { DeploymentInfo info = Servlets.deployment(); info.setDeploymentName("Pippo"); info.setClassLoader(this.getClass().getClassLoader()); info.setContextPath(getSettings().getContextPath()); info.setIgnoreFlush(true); // inject application as context attribute info.addServletContextAttribute(PIPPO_APPLICATION, getApplication()); // add pippo filter addPippoFilter(info); // add initializers info.addListener(new ListenerInfo(PippoServletContextListener.class)); // add listeners listeners.forEach(listener -> info.addListener(new ListenerInfo(listener))); ServletInfo defaultServlet = new ServletInfo("DefaultServlet", DefaultServlet.class); defaultServlet.addMapping("/"); MultipartConfigElement multipartConfig = createMultipartConfigElement(); defaultServlet.setMultipartConfig(multipartConfig); info.addServlets(defaultServlet); DeploymentManager deploymentManager = Servlets.defaultContainer().addDeployment(info); deploymentManager.deploy(); return deploymentManager; }
@Override public Void run() { ClassLoader jsfClassLoader = new URLClassLoader(new URL[0], this.getClass().getClassLoader()); di.setClassLoader(jsfClassLoader); di.setResourceManager(new ClassPathResourceManager( jsfClassLoader, JsfUndertowDeploymentInfoCustomizer.this.undertowProperties.getClassPathResource())); return null; } });
@Override public Void run() { ClassLoader jsfClassLoader = new URLClassLoader(new URL[0], this.getClass().getClassLoader()); di.setClassLoader(jsfClassLoader); di.setResourceManager(new ClassPathResourceManager( jsfClassLoader, JsfUndertowDeploymentInfoCustomizer.this.undertowProperties.getClassPathResource())); return null; } });
@Override public Void run() { ClassLoader jsfClassLoader = new URLClassLoader(new URL[0], this.getClass().getClassLoader()); di.setClassLoader(jsfClassLoader); di.setResourceManager(new ClassPathResourceManager( jsfClassLoader, undertowProperties.getClassPathResource())); return null; } });
private void configureDeployment(DeploymentInfo deploymentInfo, String name, String contextPath) { deploymentInfo.setClassLoader(getClass().getClassLoader()); deploymentInfo.setDeploymentName(name); deploymentInfo.setContextPath(contextPath); deploymentInfo.addFilter(Servlets.filter(name + "LoggingFilter", LoggingFilter.class)); deploymentInfo.addFilterUrlMapping(name + "LoggingFilter", "/*", DispatcherType.REQUEST); }
protected DeploymentInfo getDeploymentInfo(final String name, final String contextPath, final Map<String, String> initialParameters) { final DeploymentInfo deploymentInfo = new DeploymentInfo(); deploymentInfo.setClassLoader(ParticipantService.class.getClassLoader()); deploymentInfo.setContextPath(contextPath); deploymentInfo.setDeploymentName(name); deploymentInfo.addServlets(getResteasyServlet()); deploymentInfo.addListener(getResteasyListener()); deploymentInfo.addListener(getRestATListener()); for (Entry<String, String> entry : initialParameters.entrySet()) { deploymentInfo.addInitParameter(entry.getKey(), entry.getValue()); } return deploymentInfo; }
public static void main(String[] args) throws ServletException { MyServer myServer = new MyServer(8080, "0.0.0.0"); DeploymentInfo di = myServer.deployApplication("/rest", MyApplication.class) .setClassLoader(MyServer.class.getClassLoader()) .setContextPath("/myApp") .setDeploymentName("My Application") .addServlets(Servlets.servlet("helloServlet", org.viddu.poc.HelloServlet.class).addMapping("/hello")) .addListeners(Servlets.listener(org.jboss.weld.environment.servlet.Listener.class)); myServer.deploy(di); } }
@Test public void customize() throws IOException { UndertowServletWebServerFactory factory = new UndertowServletWebServerFactory(); this.undertowAutoConfiguration.jsfUndertowFactoryCustomizer().customize(factory); UndertowDeploymentInfoCustomizer undertowDeploymentInfoCustomizer = factory.getDeploymentInfoCustomizers().iterator().next(); DeploymentInfo deploymentInfo = new DeploymentInfo(); deploymentInfo.setClassLoader(this.getClass().getClassLoader()); undertowDeploymentInfoCustomizer.customize(deploymentInfo); assertThat(deploymentInfo.getResourceManager().getResource("testUndertow.txt")) .isNotNull(); } }
private ServletContext buildServletContext(String contextName) throws ServletException { ServletContainer servletContainer = new ServletContainerImpl(); DeploymentInfo deploymentInfo = new DeploymentInfo(); deploymentInfo.setClassLoader(Thread.currentThread().getContextClassLoader()); deploymentInfo.setDeploymentName("cxf-undertow"); deploymentInfo.setContextPath(contextName); ServletInfo asyncServlet = new ServletInfo(ServletPathMatches.DEFAULT_SERVLET_NAME, CxfUndertowServlet.class); deploymentInfo.addServlet(asyncServlet); servletContainer.addDeployment(deploymentInfo); DeploymentManager deploymentManager = servletContainer.getDeployment(deploymentInfo.getDeploymentName()); deploymentManager.deploy(); deploymentManager.start(); return deploymentManager.getDeployment().getServletContext(); }
private ServletContext buildServletContext(String contextName) throws ServletException { ServletContainer servletContainer = new ServletContainerImpl(); DeploymentInfo deploymentInfo = new DeploymentInfo(); deploymentInfo.setClassLoader(Thread.currentThread().getContextClassLoader()); deploymentInfo.setDeploymentName("cxf-undertow"); deploymentInfo.setContextPath(contextName); ServletInfo asyncServlet = new ServletInfo(ServletPathMatches.DEFAULT_SERVLET_NAME, CxfUndertowServlet.class); deploymentInfo.addServlet(asyncServlet); servletContainer.addDeployment(deploymentInfo); DeploymentManager deploymentManager = servletContainer.getDeployment(deploymentInfo.getDeploymentName()); deploymentManager.deploy(); deploymentManager.start(); return deploymentManager.getDeployment().getServletContext(); }