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); }
.setClassLoader(UndertowTestServer.class.getClassLoader()) .setDeploymentName("undertow-websocket-test") .setContextPath("/") .addServlet(servletInfo) .addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, info);
d.setContextPath(resolveContextPath()); if (mergedMetaData.getDescriptionGroup() != null) { d.setDisplayName(mergedMetaData.getDescriptionGroup().getDisplayName());
initializers); deployment.setClassLoader(getServletClassLoader()); deployment.setContextPath(getContextPath()); deployment.setDisplayName(getDisplayName()); deployment.setDeploymentName("spring-boot");
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(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); }
/** * 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); }
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; }
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; }
@Override public DeploymentInfo getDeploymentInfo( String contextRoot, Application application ) { if ( !config.isMetricsEnabled() ) { return null; } final ServletInfo servlet = Servlets.servlet( "healthcheck", HealthCheckServlet.class ).addMapping( "/healthcheck" ); final DeploymentInfo di = new DeploymentInfo().addListener( Servlets.listener( IndyHealthCheckServletContextListener.class ) ) .setContextPath( contextRoot ) .addServlet( servlet ) .setDeploymentName( "HealthCheck Deployment" ) .setClassLoader( ClassLoader.getSystemClassLoader() ); logger.info( "Returning deployment info for health check" ); return di; } }
private DeploymentInfo deploymentInfo() throws InterruptedException { final ResteasyDeployment resteasyDeployment = new ResteasyDeployment(); Utils.waitForCDIProvider(context); resteasyDeployment.setResourceFactories(resourceFactories()); final DeploymentInfo deploymentInfo = this.server.undertowDeployment(resteasyDeployment, String.valueOf(this.context.getProperties().get(HTTP_SERVER_REST_SERVLET_MAPPING_PREFIX))) .setContextPath(String.valueOf(this.context.getProperties().get(HTTP_SERVER_REST_CONTEXT_PATH))) .setClassLoader(this.getClass().getClassLoader()) .setDeploymentName("Silverware rest deployment"); if (this.sslEnabled) { deploymentInfo .addSecurityConstraint(new SecurityConstraint().addWebResourceCollection(new WebResourceCollection() .addUrlPattern("/*")) .setTransportGuaranteeType(TransportGuaranteeType.CONFIDENTIAL) .setEmptyRoleSemantic(SecurityInfo.EmptyRoleSemantic.PERMIT)) .setConfidentialPortManager(exchange -> sslPort()); } return deploymentInfo; }
/** * 启动服务器 * @param appName 部署的应用名称 * @param rootPath 根路径 * @param appPath 应用路径 */ public void start(String appName, String rootPath, String appPath) { Undertow.Builder serverBuilder = Undertow.builder().addHttpListener(port, host); UndertowJaxrsServer server = new UndertowJaxrsServer(); server.start(serverBuilder); DeploymentInfo di = server.undertowDeployment(ApplicationClass.class, appPath) .setClassLoader(UndertowServer.class.getClassLoader()) .setContextPath(rootPath) .setDeploymentName(appName); server.deploy(di); }
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); } }
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(); }
@Override @SuppressWarnings("unchecked") public void deployServlet(final String contextPath, final String deploymentName, final List<ServletDescriptor> servletDescriptors) throws SilverWareException { final DeploymentInfo servletBuilder = Servlets .deployment() .setClassLoader(this.getClass().getClassLoader()) .setContextPath(contextPath) .setDeploymentName(deploymentName); if (servletDescriptors != null) { servletDescriptors.forEach(servletDescriptor -> { final ServletInfo servletInfo = Servlets .servlet(servletDescriptor.getName(), (Class<Servlet>) servletDescriptor.getServletClass()); servletInfo.addMapping(servletDescriptor.getMapping()); servletDescriptor .getProperties() .forEach((key, value) -> servletInfo.addInitParam((String) key, (String) value)); servletBuilder.addServlet(servletInfo); }); } this.server.deploy(servletBuilder); }
private Undertow configureUndertow(MockitoSpringWebApplicationContext context, URL url) throws ServletException { // https://github.com/yarosla/spring-undertow/blob/master/src/main/java/ys/undertow/UndertowMain.java DeploymentInfo servletBuilder = Servlets.deployment() .setClassLoader(Undertow.class.getClassLoader()) .setContextPath(url.getPath()) .setDeploymentName("mock") .addServlet(createDispatcherServlet(context)) .addListener(createContextLoaderListener(context)); DeploymentManager manager = Servlets.defaultContainer().addDeployment(servletBuilder); manager.deploy(); PathHandler path = Handlers.path(Handlers.redirect("/")) .addPrefixPath(CONTEXT_PATH, manager.start()); return Undertow.builder() .addHttpListener(url.getPort(), url.getHost()) .setHandler(path) .build(); }
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(); }