jspServlet.setRequireWelcomeFileMapping(true); jspServlet.addInitParam("development", Boolean.toString(developmentMode)); jspServlet.addInitParam("keepgenerated", Boolean.toString(keepGenerated)); jspServlet.addInitParam("trimSpaces", Boolean.toString(trimSpaces)); jspServlet.addInitParam("enablePooling", Boolean.toString(tagPooling)); jspServlet.addInitParam("mappedfile", Boolean.toString(mappedFile)); jspServlet.addInitParam("checkInterval", Integer.toString(checkInterval)); jspServlet.addInitParam("modificationTestInterval", Integer.toString(modificationTestInterval)); jspServlet.addInitParam("recompileOnFail", Boolean.toString(recompileOnFail)); jspServlet.addInitParam("suppressSmap", Boolean.toString(!smap)); jspServlet.addInitParam("dumpSmap", Boolean.toString(dumpSmap)); jspServlet.addInitParam("genStringAsCharArray", Boolean.toString(genStringAsCharArray)); jspServlet.addInitParam("errorOnUseBeanInvalidClassAttribute", Boolean.toString(errorOnUseBeanInvalidClassAttribute)); jspServlet.addInitParam("optimizeScriptlets", Boolean.toString(optimizeScriptlets)); if (scratchDir != null) { jspServlet.addInitParam("scratchdir", scratchDir); jspServlet.addInitParam("compilerSourceVM", sourceVm); jspServlet.addInitParam("compilerTargetVM", targetVm); jspServlet.addInitParam("javaEncoding", javaEncoding); jspServlet.addInitParam("xpoweredBy", Boolean.toString(xPoweredBy)); jspServlet.addInitParam("displaySourceFragment", Boolean.toString(displaySourceFragment)); this.servletInfo = jspServlet;
@Override protected void init(DeploymentInfo servletBuilder) { servletBuilder.addServlets( servlet("Unsampled", ServletContainer.class) .setLoadOnStartup(1) .addInitParam("javax.ws.rs.Application", Unsampled.class.getName()) .addMapping("/unsampled"), servlet("Traced", ServletContainer.class) .setLoadOnStartup(1) .addInitParam("javax.ws.rs.Application", TracedApp.class.getName()) .addMapping("/traced"), servlet("TracedExtra", ServletContainer.class) .setLoadOnStartup(1) .addInitParam("javax.ws.rs.Application", TracedExtraApp.class.getName()) .addMapping("/tracedextra"), servlet("Traced128", ServletContainer.class) .setLoadOnStartup(1) .addInitParam("javax.ws.rs.Application", Traced128App.class.getName()) .addMapping("/traced128"), servlet("App", ServletContainer.class) .setLoadOnStartup(1) .addInitParam("javax.ws.rs.Application", App.class.getName()) .addMapping("/*") ); }
@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); }
for (ParamValueMetaData initParam : servlet.getInitParam()) { if (!s.getInitParams().containsKey(initParam.getParamName())) { s.addInitParam(initParam.getParamName(), initParam.getParamValue()); defaultServlet.addInitParam(DefaultServlet.DIRECTORY_LISTING, servletContainer.getDirectoryListingEnabled().toString());
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); }
.setLoadOnStartup(1) .addMapping(mapping); if (prefix != null) resteasyServlet.addInitParam("resteasy.servlet.mapping.prefix", prefix);
private ServletInfo addSwaggerContext(String urlPath, final ServletInfo servletInfo) { final String contextId = ServletContainer.class.getName() + '@' + urlPath; urlPath = StringUtils.removeEnd(urlPath, "*"); urlPath = StringUtils.removeEnd(urlPath, "/"); return servletInfo.addInitParam(SwaggerContextService.SCANNER_ID_KEY, contextId) .addInitParam(SwaggerContextService.CONFIG_ID_KEY, contextId) .addInitParam(SwaggerContextService.CONTEXT_ID_KEY, contextId) .addInitParam("swagger.api.basepath", urlPath); }
@Override public boolean setInitParameter(final String name, final String value) { if (servletInfo.getInitParams().containsKey(name)) { return false; } servletInfo.addInitParam(name, value); return true; }
jspServlet.setRequireWelcomeFileMapping(true); jspServlet.addInitParam("development", Boolean.toString(developmentMode)); jspServlet.addInitParam("keepgenerated", Boolean.toString(keepGenerated)); jspServlet.addInitParam("trimSpaces", Boolean.toString(trimSpaces)); jspServlet.addInitParam("enablePooling", Boolean.toString(tagPooling)); jspServlet.addInitParam("mappedfile", Boolean.toString(mappedFile)); jspServlet.addInitParam("checkInterval", Integer.toString(checkInterval)); jspServlet.addInitParam("modificationTestInterval", Integer.toString(modificationTestInterval)); jspServlet.addInitParam("recompileOnFail", Boolean.toString(recompileOnFail)); jspServlet.addInitParam("suppressSmap", Boolean.toString(!smap)); jspServlet.addInitParam("dumpSmap", Boolean.toString(dumpSmap)); jspServlet.addInitParam("genStringAsCharArray", Boolean.toString(genStringAsCharArray)); jspServlet.addInitParam("errorOnUseBeanInvalidClassAttribute", Boolean.toString(errorOnUseBeanInvalidClassAttribute)); jspServlet.addInitParam("optimizeScriptlets", Boolean.toString(optimizeScriptlets)); if (scratchDir != null) { jspServlet.addInitParam("scratchdir", scratchDir); jspServlet.addInitParam("compilerSourceVM", sourceVm); jspServlet.addInitParam("compilerTargetVM", targetVm); jspServlet.addInitParam("javaEncoding", javaEncoding); jspServlet.addInitParam("xpoweredBy", Boolean.toString(xPoweredBy)); jspServlet.addInitParam("displaySourceFragment", Boolean.toString(displaySourceFragment)); this.servletInfo = jspServlet;
public Builder registerWebjars(final boolean disableCache, final String... urlMappings) { ServletInfo servletInfo = new ServletInfo("WebjarsServlet", WebjarsServlet.class).setLoadOnStartup(2) .addMappings(urlMappings); if (disableCache) servletInfo = servletInfo.addInitParam("disableCache", Boolean.toString(disableCache)); context.addServlet(servletInfo); return this; }
public ServletContextBuilder jaxrs(final String name, final Class<? extends Application> applicationClass, final Consumer<ServletInfo> servletInfoHook) { final ServletInfo servletInfo = new ServletInfo(StringUtils.isEmpty(name) ? applicationClass.getName() : name, ServletContainer.class).addInitParam(ServletProperties.JAXRS_APPLICATION_CLASS, applicationClass.getName()); final ApplicationPath path = AnnotationsUtils.getFirstAnnotation(applicationClass, ApplicationPath.class); if (path != null) servletInfo.addMapping(path.value()); servletInfo.setAsyncSupported(true).setLoadOnStartup(1); addServlet(servletInfo, servletInfoHook); return this; }
@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); }
Servlets.servlet("jerseyServlet", ServletContainer.class) .setLoadOnStartup(1) .addInitParam("javax.ws.rs.Application", JerseyConfig.class.getName()) .addMapping("/api/*")) .setDeploymentName("application.war");
public SimpleServletServer() { DeploymentInfo deploymentInfo = deployment() .setClassLoader(SimpleServletServer.class.getClassLoader()) .setContextPath("/helloworld") .setDeploymentName("helloworld.war") .addServlets( Servlets.servlet("MyServlet", MyServlet.class) .addInitParam("message", "Hello World") .addMapping("/MyServlet"), Servlets.servlet("MyAnotherServlet", MyAnotherServlet.class) .addMapping("/MyAnotherServlet") ); DeploymentManager manager = defaultContainer().addDeployment(deploymentInfo); manager.deploy (); try { server = Undertow.builder() .addListener(8080, "localhost") .setHandler(manager.start()) .build(); } catch (ServletException ex) { Logger.getLogger(SimpleServletServer.class.getName()).log(Level.SEVERE, null, ex); } }
@Override public ServletInfo apply(ServletDescriptor servletDescriptor) { ServletInfo servletInfo = Servlets.servlet(servletDescriptor.name(), servletDescriptor.servletClass()) .setAsyncSupported(servletDescriptor.asyncSupported()) .setLoadOnStartup(servletDescriptor.loadOnStartup()) .addMappings(servletDescriptor.urlPatterns()); if(servletDescriptor.initParams() != null) { for(WebInitParam param : servletDescriptor.initParams()) { servletInfo.addInitParam(param.name(), param.value()); } } return servletInfo; } }
@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); }
@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); }
@Override public ServletInfo apply(ServletDescriptor servletDescriptor) { ServletInfo servletInfo = Servlets.servlet(servletDescriptor.name(), servletDescriptor.servletClass()) .setAsyncSupported(servletDescriptor.asyncSupported()) .setLoadOnStartup(servletDescriptor.loadOnStartup()) .addMappings(servletDescriptor.urlPatterns()); if(servletDescriptor.initParams() != null) { for(WebInitParam param : servletDescriptor.initParams()) { servletInfo.addInitParam(param.name(), param.value()); } } return servletInfo; } }
protected void run() { try { final DeploymentInfo servletBuilder = deployment() .setClassLoader(AbstractUndertowServer.class.getClassLoader()) .setContextPath(contextPath) .setDeploymentName("sse-test") .addServlets( servlet("MessageServlet", CXFNonSpringJaxrsServlet.class) .addInitParam("jaxrs.providers", JacksonJsonProvider.class.getName()) .addInitParam("jaxrs.serviceClasses", BookStore.class.getName()) .setAsyncSupported(true) .setLoadOnStartup(1) .addMapping("/rest/*") ); final DeploymentManager manager = defaultContainer().addDeployment(servletBuilder); manager.deploy(); PathHandler path = Handlers .path(Handlers.redirect("/")) .addPrefixPath("/", manager.start()); server = Undertow.builder() .addHttpListener(port, "localhost") .setHandler(path) .build(); server.start(); } catch (final Exception ex) { ex.printStackTrace(); fail(ex.getMessage()); } }
public static void main(final String[] args) throws Exception { assertJavaVersion8(); DeploymentInfo servletBuilder = deployment() .setClassLoader(HelloWorldServlet.class.getClassLoader()) .setContextPath(MYAPP) .setDeploymentName("hello-world.war") .addServlets( servlet("HelloWorldServlet", HelloWorldServlet.class) .addInitParam("message", "Hello World") .addMapping("/api/hello-world")); DeploymentManager manager = defaultContainer().addDeployment(servletBuilder); manager.deploy(); HttpHandler servletHandler = manager.start(); PathHandler path = Handlers.path(Handlers.redirect(MYAPP)) .addPrefixPath(MYAPP, servletHandler); String bindAddress = System.getProperty("bind.address", "localhost"); SSLContext sslContext = createSSLContext(loadKeyStore("server.keystore"), loadKeyStore("server.truststore")); Undertow server = Undertow.builder() .setServerOption(UndertowOptions.ENABLE_HTTP2, true) .addHttpsListener(8443, bindAddress, sslContext) .setHandler(path) .build(); server.start(); }