io.undertow.servlet.Servlets Java Examples
The following examples show how to use
io.undertow.servlet.Servlets.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HttpServerBenchmarks.java From brave with Apache License 2.0 | 6 votes |
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(); }
Example #2
Source File: ResponseWriterTestCase.java From quarkus-http with Apache License 2.0 | 6 votes |
@BeforeClass public static void setup() throws ServletException { final PathHandler root = new PathHandler(); final ServletContainer container = ServletContainer.Factory.newInstance(); DeploymentInfo builder = new DeploymentInfo() .setClassIntrospecter(TestClassIntrospector.INSTANCE) .setClassLoader(ResponseWriterTestCase.class.getClassLoader()) .setContextPath("/servletContext") .setDeploymentName("servletContext.war") .addServlet(Servlets.servlet("resp", ResponseWriterServlet.class) .addMapping("/resp")) .addServlet(Servlets.servlet("respLArget", LargeResponseWriterServlet.class) .addMapping("/large")); DeploymentManager manager = container.addDeployment(builder); manager.deploy(); root.addPrefixPath(builder.getContextPath(), manager.start()); DefaultServer.setRootHandler(root); }
Example #3
Source File: MultiPartTestCase.java From quarkus-http with Apache License 2.0 | 6 votes |
@BeforeClass public static void setup() throws ServletException { DeploymentUtils.setupServlet(new ServletExtension() { @Override public void handleDeployment(DeploymentInfo deploymentInfo, ServletContext servletContext) { deploymentInfo.addListener(Servlets.listener(AddMultipartServetListener.class)); deploymentInfo.setExceptionHandler(LoggingExceptionHandler.builder().add(RuntimeException.class, "io.undertow", Logger.Level.DEBUG).build()); } }, servlet("mp0", MultiPartServlet.class) .addMapping("/0"), servlet("mp1", MultiPartServlet.class) .addMapping("/1") .setMultipartConfig(multipartConfig(null, 0, 0, 0)), servlet("mp2", MultiPartServlet.class) .addMapping("/2") .setMultipartConfig(multipartConfig(null, 0, 3, 0)), servlet("mp3", MultiPartServlet.class) .addMapping("/3") .setMultipartConfig(multipartConfig(null, 3, 0, 0))); }
Example #4
Source File: EndToEndBenchmarks.java From brave with Apache License 2.0 | 6 votes |
@Override protected void init(DeploymentInfo servletBuilder) { servletBuilder.addFilter(new FilterInfo("Unsampled", Unsampled.class)) .addFilterUrlMapping("Unsampled", "/unsampled", REQUEST) .addFilterUrlMapping("Unsampled", "/unsampled/api", REQUEST) .addFilter(new FilterInfo("OnlySampledLocal", OnlySampledLocal.class)) .addFilterUrlMapping("OnlySampledLocal", "/onlysampledlocal", REQUEST) .addFilterUrlMapping("OnlySampledLocal", "/onlysampledlocal/api", REQUEST) .addFilter(new FilterInfo("Traced", Traced.class)) .addFilterUrlMapping("Traced", "/traced", REQUEST) .addFilterUrlMapping("Traced", "/traced/api", REQUEST) .addFilter(new FilterInfo("TracedBaggage", TracedBaggage.class)) .addFilterUrlMapping("TracedBaggage", "/tracedBaggage", REQUEST) .addFilterUrlMapping("TracedBaggage", "/tracedBaggage/api", REQUEST) .addFilter(new FilterInfo("TracedCorrelated", TracedCorrelated.class)) .addFilterUrlMapping("TracedCorrelated", "/tracedcorrelated", REQUEST) .addFilterUrlMapping("TracedCorrelated", "/tracedcorrelated/api", REQUEST) .addFilter(new FilterInfo("Traced128", Traced128.class)) .addFilterUrlMapping("Traced128", "/traced128", REQUEST) .addFilterUrlMapping("Traced128", "/traced128/api", REQUEST) .addServlets(Servlets.servlet("HelloServlet", HelloServlet.class).addMapping("/*")); }
Example #5
Source File: DefaultServletCachingTestCase.java From quarkus-http with Apache License 2.0 | 6 votes |
@BeforeClass public static void setup() throws ServletException, IOException { tmpDir = Files.createTempDirectory(DIR_NAME); final PathHandler root = new PathHandler(); final ServletContainer container = ServletContainer.Factory.newInstance(); DeploymentInfo builder = new DeploymentInfo() .setClassIntrospecter(TestClassIntrospector.INSTANCE) .setClassLoader(ServletPathMappingTestCase.class.getClassLoader()) .setContextPath("/servletContext") .setDeploymentName("servletContext.war") .setResourceManager(new CachingResourceManager(100, 10000, dataCache, new PathResourceManager(tmpDir, 10485760, false, false, false), METADATA_MAX_AGE)); builder.addServlet(new ServletInfo("DefaultTestServlet", PathTestServlet.class) .addMapping("/path/default")) .addFilter(Servlets.filter("message", MessageFilter.class).addInitParam(MessageFilter.MESSAGE, "FILTER_TEXT ")) .addFilterUrlMapping("message", "*.txt", DispatcherType.REQUEST); DeploymentManager manager = container.addDeployment(builder); manager.deploy(); root.addPrefixPath(builder.getContextPath(), manager.start()); DefaultServer.setRootHandler(root); }
Example #6
Source File: SimpleServletServer.java From wildfly-samples with MIT License | 6 votes |
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); } }
Example #7
Source File: TestHttpServer.java From pnc with Apache License 2.0 | 6 votes |
@Override public void before() throws Exception { final ServletInfo si = Servlets.servlet("TEST", ExpectationServlet.class) .addMapping("*") .addMapping("/*") .setLoadOnStartup(1); si.setInstanceFactory(new ImmediateInstanceFactory<Servlet>(servlet)); final DeploymentInfo di = new DeploymentInfo().addServlet(si) .setDeploymentName("TEST") .setContextPath("/") .setClassLoader(Thread.currentThread().getContextClassLoader()); final DeploymentManager dm = Servlets.defaultContainer().addDeployment(di); dm.deploy(); server = Undertow.builder().setHandler(dm.start()).addHttpListener(port, "127.0.0.1").build(); server.start(); }
Example #8
Source File: RestEasyUndertowServletRule.java From jax-rs-pac4j with Apache License 2.0 | 6 votes |
@Override protected void before() throws Throwable { // Used by Jersey Client to store cookies CookieHandler.setDefault(new CookieManager()); // we don't need a resteasy client, and the jersey one works better with redirect client = new JerseyClientBuilder().build(); // TODO use an autogenerated port... System.setProperty("org.jboss.resteasy.port", "24257"); server = new UndertowJaxrsServer().start(); ResteasyDeployment deployment = new ResteasyDeployment(); deployment.setInjectorFactoryClass(CdiInjectorFactory.class.getName()); deployment.setApplication(new MyApp()); DeploymentInfo di = server.undertowDeployment(deployment) .setContextPath("/") .setDeploymentName("DI") .setClassLoader(getClass().getClassLoader()) .addListeners(Servlets.listener(Listener.class)); server.deploy(di); }
Example #9
Source File: ArquillianTest.java From jersey-jwt with MIT License | 5 votes |
@Deployment(testable = false) public static Archive<WebArchive> createDeployment() { return ShrinkWrap.create(UndertowWebArchive.class).from( deployment() .setClassLoader(Application.class.getClassLoader()) .setContextPath("/") .addListeners(listener(Listener.class)) .addServlets( Servlets.servlet("jerseyServlet", ServletContainer.class) .setLoadOnStartup(1) .addInitParam("javax.ws.rs.Application", JerseyConfig.class.getName()) .addMapping("/api/*")) .setDeploymentName("application.war")); }
Example #10
Source File: KeycloakOnUndertow.java From keycloak with Apache License 2.0 | 5 votes |
private DeploymentInfo createAuthServerDeploymentInfo() { ResteasyDeployment deployment = new ResteasyDeployment(); deployment.setApplicationClass(KeycloakApplication.class.getName()); // RESTEASY-2034 deployment.setProperty(ResteasyContextParameters.RESTEASY_DISABLE_HTML_SANITIZER, true); DeploymentInfo di = undertow.undertowDeployment(deployment); di.setClassLoader(getClass().getClassLoader()); di.setContextPath("/auth"); di.setDeploymentName("Keycloak"); if (configuration.getKeycloakConfigPropertyOverridesMap() != null) { try { di.addInitParameter(JsonConfigProviderFactory.SERVER_CONTEXT_CONFIG_PROPERTY_OVERRIDES, JsonSerialization.writeValueAsString(configuration.getKeycloakConfigPropertyOverridesMap())); } catch (IOException ex) { throw new RuntimeException(ex); } } di.setDefaultServletConfig(new DefaultServletConfig(true)); di.addWelcomePage("theme/keycloak/welcome/resources/index.html"); FilterInfo filter = Servlets.filter("SessionFilter", TestKeycloakSessionServletFilter.class); di.addFilter(filter); di.addFilterUrlMapping("SessionFilter", "/*", DispatcherType.REQUEST); filter.setAsyncSupported(true); return di; }
Example #11
Source File: CamelEndpointDeployerService.java From wildfly-camel with Apache License 2.0 | 5 votes |
/** * The stuff common for {@link #deploy(URI, EndpointHttpHandler)} and {@link #deploy(URI, HttpHandler)}. * * @param uri * @param endpointServletConsumer customize the {@link EndpointServlet} * @param deploymentInfoConsumer customize the {@link DeploymentInfo} * @param deploymentConsumer customize the {@link DeploymentImpl} */ void doDeploy(URI uri, Consumer<EndpointServlet> endpointServletConsumer, Consumer<DeploymentInfo> deploymentInfoConsumer, Consumer<DeploymentImpl> deploymentConsumer) { final ServletInfo servletInfo = Servlets.servlet(EndpointServlet.NAME, EndpointServlet.class).addMapping("/*") .setAsyncSupported(true); final DeploymentInfo mainDeploymentInfo = deploymentInfoSupplier.getValue(); DeploymentInfo endPointDeplyomentInfo = adaptDeploymentInfo(mainDeploymentInfo, uri, servletInfo); deploymentInfoConsumer.accept(endPointDeplyomentInfo); CamelLogger.LOGGER.debug("Deploying endpoint {}", endPointDeplyomentInfo.getDeploymentName()); final ClassLoader old = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(endPointDeplyomentInfo.getClassLoader()); try { final DeploymentManager manager = servletContainerServiceSupplier.getValue().getServletContainer() .addDeployment(endPointDeplyomentInfo); manager.deploy(); final Deployment deployment = manager.getDeployment(); try { deploymentConsumer.accept((DeploymentImpl) deployment); manager.start(); hostSupplier.getValue().registerDeployment(deployment, deployment.getHandler()); ManagedServlet managedServlet = deployment.getServlets().getManagedServlet(EndpointServlet.NAME); EndpointServlet servletInstance = (EndpointServlet) managedServlet.getServlet().getInstance(); endpointServletConsumer.accept(servletInstance); } catch (ServletException ex) { throw new IllegalStateException(ex); } synchronized (deployments) { deployments.put(uri, manager); } } finally { Thread.currentThread().setContextClassLoader(old); } }
Example #12
Source File: UndertowServletMapper.java From hammock with Apache License 2.0 | 5 votes |
@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; }
Example #13
Source File: UndertowServer.java From pippo with Apache License 2.0 | 5 votes |
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; }
Example #14
Source File: ClassProviderStarter.java From websocket-classloader with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws IOException, ServletException { final Xnio xnio = Xnio.getInstance("nio", Undertow.class.getClassLoader()); final XnioWorker xnioWorker = xnio.createWorker(OptionMap.builder().getMap()); final WebSocketDeploymentInfo webSockets = new WebSocketDeploymentInfo() .addEndpoint(ClassProvider.class) .setWorker(xnioWorker); final DeploymentManager deploymentManager = Servlets.defaultContainer() .addDeployment(Servlets.deployment() .setClassLoader(ClassProviderStarter.class.getClassLoader()) .setContextPath("/") .setDeploymentName("class-provider") .addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, webSockets)); deploymentManager.deploy(); //noinspection deprecation Undertow.builder() .addListener(5000, "localhost") .setHandler(deploymentManager.start()) .build() .start(); }
Example #15
Source File: Main.java From zooadmin with MIT License | 5 votes |
public static void main(String[] args) throws Exception { DeploymentInfo servletBuilder = Servlets.deployment() .setContextPath("/") .setClassLoader(Main.class.getClassLoader()) .setDeploymentName("zooadmin.war") ; Integer port= PropUtil.getInt("port"); String host=PropUtil.getString("host"); String resource=PropUtil.getString("resource"); FilterInfo jfinalFilter=new FilterInfo("jfinal",JFinalFilter.class); jfinalFilter.addInitParam("configClass","com.baicai.core.Config"); servletBuilder.addFilter(jfinalFilter); servletBuilder.addFilterUrlMapping("jfinal","/*", DispatcherType.REQUEST); servletBuilder.addFilterUrlMapping("jfinal","/*", DispatcherType.FORWARD); servletBuilder.setResourceManager(new FileResourceManager(new File(resource), 1024)); DeploymentManager manager = Servlets.defaultContainer().addDeployment(servletBuilder); manager.deploy(); PathHandler path = Handlers.path(Handlers.redirect("/")) .addPrefixPath("/", manager.start()); Undertow server = Undertow.builder() .addHttpListener(port, host) .setHandler(path) .build(); // start server server.start(); log.info("http://"+host+":"+port); }
Example #16
Source File: KeycloakPlaygroundServer.java From keycloak-extension-playground with Apache License 2.0 | 5 votes |
private static void deployMetricsServlet(KeycloakServer keycloakServer) { DeploymentInfo di = Servlets.deployment() .setClassLoader(KeycloakServer.class.getClassLoader()) .setContextPath("/") .setDeploymentName("Metrics") .addServlets(Servlets.servlet("smallrye-metrics-servlet", MetricsServlet.class) .addMapping("/metrics")); keycloakServer.getServer().deploy(di); }
Example #17
Source File: WebServer.java From metamodel-membrane with Apache License 2.0 | 5 votes |
public static void startServer(int port, boolean enableCors) throws Exception { final DeploymentInfo deployment = Servlets.deployment().setClassLoader(WebServer.class.getClassLoader()); deployment.setContextPath(""); deployment.setDeploymentName("membrane"); deployment.addInitParameter("contextConfigLocation", "classpath:context/application-context.xml"); deployment.setResourceManager(new FileResourceManager(new File("."), 0)); deployment.addListener(Servlets.listener(ContextLoaderListener.class)); deployment.addListener(Servlets.listener(RequestContextListener.class)); deployment.addServlet(Servlets.servlet("dispatcher", DispatcherServlet.class).addMapping("/*") .addInitParam("contextConfigLocation", "classpath:context/dispatcher-servlet.xml")); deployment.addFilter(Servlets.filter(CharacterEncodingFilter.class).addInitParam("forceEncoding", "true") .addInitParam("encoding", "UTF-8")); final DeploymentManager manager = Servlets.defaultContainer().addDeployment(deployment); manager.deploy(); final HttpHandler handler; if (enableCors) { CorsHandlers corsHandlers = new CorsHandlers(); handler = corsHandlers.allowOrigin(manager.start()); } else { handler = manager.start(); } final Undertow server = Undertow.builder().addHttpListener(port, "0.0.0.0").setHandler(handler).build(); server.start(); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { // graceful shutdown of everything server.stop(); try { manager.stop(); } catch (ServletException e) { } manager.undeploy(); } }); }
Example #18
Source File: Main.java From zooadmin with MIT License | 5 votes |
public static void main(String[] args) throws Exception { DeploymentInfo servletBuilder = Servlets.deployment() .setContextPath("/") .setClassLoader(Main.class.getClassLoader()) .setDeploymentName("zooadmin.war") ; Integer port= PropUtil.getInt("port"); String host=PropUtil.getString("host"); String resource=PropUtil.getString("resource"); FilterInfo jfinalFilter=new FilterInfo("jfinal",JFinalFilter.class); jfinalFilter.addInitParam("configClass","com.baicai.core.Config"); servletBuilder.addFilter(jfinalFilter); servletBuilder.addFilterUrlMapping("jfinal","/*", DispatcherType.REQUEST); servletBuilder.addFilterUrlMapping("jfinal","/*", DispatcherType.FORWARD); servletBuilder.setResourceManager(new FileResourceManager(new File(resource), 1024)); DeploymentManager manager = Servlets.defaultContainer().addDeployment(servletBuilder); manager.deploy(); PathHandler path = Handlers.path(Handlers.redirect("/")) .addPrefixPath("/", manager.start()); Undertow server = Undertow.builder() .addHttpListener(port, host) .setHandler(path) .build(); // start server server.start(); log.info("http://"+host+":"+port); }
Example #19
Source File: UndertowWebServer.java From oxygen with Apache License 2.0 | 5 votes |
private DeploymentManager deployment() { Set<Class<?>> handlesTypes = new HashSet<>(2); return Servlets.defaultContainer().addDeployment( Servlets.deployment().setClassLoader(ClassUtils.getDefaultClassLoader()) .setContextPath(contextPath).setDeploymentName("oxygen") .addServletContainerInitializer( new ServletContainerInitializerInfo(ServletWebInitializer.class, handlesTypes))); }
Example #20
Source File: UndertowStartFilter.java From spring-cloud-formula with Apache License 2.0 | 5 votes |
@Override public boolean process(ApplicationExchange application, LauncherFilterChain filterChain) { int port = application.getServerPort(); ClassLoader classLoader = new LaunchedURLClassLoader(application.getClassPathUrls(), deduceParentClassLoader()); DeploymentInfo servletBuilder = Servlets.deployment() .setClassLoader(classLoader) .setContextPath(application.getContextPath()) .setDeploymentName(application.getApplication().getPath()); DeploymentManager manager = Servlets.defaultContainer().addDeployment(servletBuilder); manager.deploy(); Undertow server = null; try { server = Undertow.builder() .addHttpListener(port, "localhost") .setHandler(manager.start()).build(); server.start(); } catch (ServletException e) { e.printStackTrace(); } return false; }
Example #21
Source File: SecurityErrorPageTestCase.java From quarkus-http with Apache License 2.0 | 5 votes |
@BeforeClass public static void setup() throws IOException, ServletException { final ServletContainer container = ServletContainer.Factory.newInstance(); final PathHandler root = new PathHandler(); DefaultServer.setRootHandler(root); DeploymentInfo builder = new DeploymentInfo(); builder.addServlet(new ServletInfo("secure", SecureServlet.class) .addMapping("/secure")) .addSecurityConstraint(Servlets.securityConstraint().addRoleAllowed("user").addWebResourceCollection(Servlets.webResourceCollection().addUrlPattern("/*"))); builder.addServlet(new ServletInfo("path", PathServlet.class) .addMapping("/*")); builder.addErrorPage(new ErrorPage("/401", StatusCodes.UNAUTHORIZED)); ServletIdentityManager identityManager = new ServletIdentityManager(); identityManager.addUser("user1", "password1"); // Just one role less user. builder.setClassIntrospecter(TestClassIntrospector.INSTANCE) .setClassLoader(ErrorPageTestCase.class.getClassLoader()) .setContextPath("/servletContext") .setServletStackTraces(ServletStackTraces.NONE) .setIdentityManager(identityManager) .setLoginConfig(Servlets.loginConfig("BASIC", "Test Realm")) .setDeploymentName("servletContext.war"); final DeploymentManager manager1 = container.addDeployment(builder); manager1.deploy(); root.addPrefixPath(builder.getContextPath(), manager1.start()); }
Example #22
Source File: DefaultCharacterEncodingTestCase.java From quarkus-http with Apache License 2.0 | 5 votes |
private void setup(final String defaultEncoding) throws ServletException { DeploymentUtils.setupServlet(new ServletExtension() { @Override public void handleDeployment(DeploymentInfo deploymentInfo, ServletContext servletContext) { if (defaultEncoding != null) { deploymentInfo.setDefaultEncoding(defaultEncoding); } } }, Servlets.servlet("servlet", DefaultCharacterEncodingServlet.class) .addMapping("/")); }
Example #23
Source File: MultiPartForwardTestCase.java From quarkus-http with Apache License 2.0 | 5 votes |
@BeforeClass public static void setup() throws ServletException { DeploymentUtils.setupServlet( Servlets.servlet("MultiPartCapableServlet", MultiPartCapableServlet.class) .addMapping("/multipart") .setMultipartConfig(multipartConfig(null, 0, 0, 0)), Servlets.servlet("ForwardingServlet", ForwardingServlet.class) .addMapping("/forward")); }
Example #24
Source File: ServletURLRewritingSessionTestCase.java From quarkus-http with Apache License 2.0 | 5 votes |
@BeforeClass public static void setup() { DeploymentUtils.setupServlet(new ServletExtension() { @Override public void handleDeployment(DeploymentInfo deploymentInfo, ServletContext servletContext) { deploymentInfo.setServletSessionConfig(new ServletSessionConfig().setSessionTrackingModes(Collections.singleton(SessionTrackingMode.URL))); } }, Servlets.servlet(URLRewritingServlet.class).addMapping("/foo")); }
Example #25
Source File: Application.java From jersey-jwt with MIT License | 4 votes |
/** * Start server on the given port. * * @param port */ public static void startServer(int port) { LOGGER.info(String.format("Starting server on port %d", port)); PathHandler path = Handlers.path(); server = Undertow.builder() .addHttpListener(port, "localhost") .setHandler(path) .build(); server.start(); LOGGER.info(String.format("Server started on port %d", port)); DeploymentInfo servletBuilder = Servlets.deployment() .setClassLoader(Application.class.getClassLoader()) .setContextPath("/") .addListeners(listener(Listener.class)) .setResourceManager(new ClassPathResourceManager(Application.class.getClassLoader())) .addServlets( Servlets.servlet("jerseyServlet", ServletContainer.class) .setLoadOnStartup(1) .addInitParam("javax.ws.rs.Application", JerseyConfig.class.getName()) .addMapping("/api/*")) .setDeploymentName("application.war"); LOGGER.info("Starting application deployment"); deploymentManager = Servlets.defaultContainer().addDeployment(servletBuilder); deploymentManager.deploy(); try { path.addPrefixPath("/", deploymentManager.start()); } catch (ServletException e) { throw new RuntimeException(e); } LOGGER.info("Application deployed"); }
Example #26
Source File: DeploymentManagerFactory.java From seed with Mozilla Public License 2.0 | 4 votes |
DeploymentManager createDeploymentManager() { DeploymentInfo servletBuilder = configureDeploymentInfo(); return Servlets.defaultContainer().addDeployment(servletBuilder); }
Example #27
Source File: DeploymentManagerFactory.java From seed with Mozilla Public License 2.0 | 4 votes |
@SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST_OF_RETURN_VALUE", justification = "False positive") private DeploymentInfo configureDeploymentInfo() { // Basic deployment attributes DeploymentInfo deploymentInfo = Servlets.deployment() .setEagerFilterInit(true) .setClassLoader(mostCompleteClassLoader) .setDeploymentName(applicationConfig.getId()) .setDisplayName(applicationConfig.getName()) .setDefaultSessionTimeout(serverConfig.getDefaultSessionTimeout()) .setResourceManager(new ClassPathResourceManager(mostCompleteClassLoader, META_INF_RESOURCES)) .addWelcomePages(serverConfig.getWelcomeFiles()) .addErrorPages(buildUndertowErrorPages(serverConfig.getErrorPages())) .setContextPath(serverConfig.getContextPath()); // Configure WebSockets if enabled if (serverConfig.webSocket().isEnabled()) { LOGGER.info("WebSocket support is enabled"); deploymentInfo.addServletContextAttribute( WebSocketDeploymentInfo.ATTRIBUTE_NAME, new WebSocketDeploymentInfo() .setBuffers(new DefaultByteBufferPool( undertowConfig.isDirectBuffers(), undertowConfig.getBufferSize())) .setWorker(xnioWorker) ); } // Redirect to HTTPS if configured if (serverConfig.isHttp() && serverConfig.isHttps() && serverConfig.isPreferHttps()) { LOGGER.info("Automatic redirection to HTTPS is enabled"); deploymentInfo .addSecurityConstraint(new SecurityConstraint() .addWebResourceCollection(new WebResourceCollection().addUrlPattern("/*")) .setTransportGuaranteeType(TransportGuaranteeType.CONFIDENTIAL) .setEmptyRoleSemantic(SecurityInfo.EmptyRoleSemantic.PERMIT)) .setConfidentialPortManager(ex -> serverConfig.getSecurePort()); } // Add custom init parameters for (Map.Entry<String, String> initParameter : initParameters.entrySet()) { LOGGER.debug("Servlet init parameter {} = {}", initParameter.getKey(), initParameter.getValue()); deploymentInfo.addInitParameter(initParameter.getKey(), initParameter.getValue()); } // Register ServletContainerInitializers for (ServletContainerInitializer sci : loadServletContainerInitializers()) { LOGGER.debug("Registering ServletContainerInitializer {}", sci.getClass().getName()); deploymentInfo.addServletContainerInitializer(createServletContainerInitializerInfo(sci)); } return deploymentInfo; }
Example #28
Source File: UndertowWebServer.java From hammock with Apache License 2.0 | 4 votes |
@Override public void start() { DeploymentInfo di = new DeploymentInfo() .setContextPath("/") .setDeploymentName("Undertow") .setResourceManager(new ClassPathResourceManager(getClass().getClassLoader())) .setClassLoader(ClassLoader.getSystemClassLoader()); super.getListeners().forEach(c ->di.addListener(listener(c))); Collection<Class<?>> endpoints = extension.getEndpointClasses(); if(!endpoints.isEmpty()) { WebSocketDeploymentInfo webSocketDeploymentInfo = new WebSocketDeploymentInfo(); endpoints.forEach(webSocketDeploymentInfo::addEndpoint); di.addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, webSocketDeploymentInfo); } getServletContextAttributes().forEach(di::addServletContextAttribute); servlets.forEach(di::addServlet); getFilterDescriptors().forEach(filterDescriptor -> { FilterInfo filterInfo = filter(filterDescriptor.displayName(), filterDescriptor.getClazz()).setAsyncSupported(filterDescriptor.asyncSupported()); if(filterDescriptor.initParams() != null) { for (WebInitParam param : filterDescriptor.initParams()) { filterInfo.addInitParam(param.name(), param.value()); } } di.addFilter(filterInfo); for(String url : filterDescriptor.urlPatterns()) { for(DispatcherType dispatcherType : filterDescriptor.dispatcherTypes()) { di.addFilterUrlMapping(filterDescriptor.displayName(), url, dispatcherType); } } }); getInitParams().forEach(di::addInitParameter); DeploymentManager deploymentManager = Servlets.defaultContainer().addDeployment(di); deploymentManager.deploy(); try { HttpHandler servletHandler = deploymentManager.start(); PathHandler path = path(Handlers.redirect("/")) .addPrefixPath("/", servletHandler); Builder undertowBuilder = Undertow.builder() .addHttpListener(webServerConfiguration.getPort(), webServerConfiguration.getAddress()) .setHandler(path); if (hammockRuntime.isSecuredConfigured()){ KeyManager[] keyManagers = loadKeyManager(); TrustManager[] trustManagers = loadTrustManager(); SSLContext sslContext = SSLContext.getInstance("TLS"); sslContext.init(keyManagers, trustManagers, null); undertowBuilder = undertowBuilder.addHttpsListener(webServerConfiguration.getSecuredPort(), webServerConfiguration.getAddress(), sslContext); } this.undertow = undertowBuilder.build(); this.undertow.start(); } catch (ServletException | GeneralSecurityException | IOException e) { throw new RuntimeException("Unable to start server", e); } }
Example #29
Source File: UnmappableCharacterTestCase.java From quarkus-http with Apache License 2.0 | 4 votes |
@BeforeClass public static void setup() throws ServletException { DeploymentUtils.setupServlet(Servlets.servlet("servlet", EchoServlet.class) .addMapping("/")); }
Example #30
Source File: ParameterCharacterEncodingTestCase.java From quarkus-http with Apache License 2.0 | 4 votes |
@BeforeClass public static void setup() throws ServletException { DeploymentUtils.setupServlet(Servlets.servlet("servlet", EchoServlet.class) .addMapping("/") .setMultipartConfig(multipartConfig(null, 0, 0, 0))); }