io.undertow.servlet.api.DeploymentInfo Java Examples
The following examples show how to use
io.undertow.servlet.api.DeploymentInfo.
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: ProgrammaticWebSocketServer.java From wildfly-samples with MIT License | 9 votes |
public ProgrammaticWebSocketServer() throws IOException { final Xnio xnio = Xnio.getInstance("nio", Undertow.class.getClassLoader()); final XnioWorker xnioWorker = xnio.createWorker(OptionMap.builder().getMap()); WebSocketDeploymentInfo websocket = new WebSocketDeploymentInfo() .addEndpoint(MyAnnotatedEndpoint.class) .setWorker(xnioWorker); DeploymentInfo deploymentInfo = deployment() .setClassLoader(MyAnnotatedEndpoint.class.getClassLoader()) .setContextPath("/myapp") .setDeploymentName("websockets") .addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, websocket); manager = defaultContainer().addDeployment(deploymentInfo); manager.deploy(); }
Example #2
Source File: AnnotatedWebSocketServer.java From wildfly-samples with MIT License | 7 votes |
public AnnotatedWebSocketServer() throws IOException { final Xnio xnio = Xnio.getInstance("nio", Undertow.class.getClassLoader()); final XnioWorker xnioWorker = xnio.createWorker(OptionMap.builder().getMap()); WebSocketDeploymentInfo websocket = new WebSocketDeploymentInfo() .addEndpoint(MyAnnotatedEndpoint.class) .setWorker(xnioWorker); DeploymentInfo deploymentInfo = deployment() .setClassLoader(MyAnnotatedEndpoint.class.getClassLoader()) .setContextPath("/myapp") .setDeploymentName("websockets") .addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, websocket); manager = defaultContainer().addDeployment(deploymentInfo); manager.deploy(); }
Example #3
Source File: NestedListenerInvocationTestCase.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(); ServletInfo a = new ServletInfo("asyncServlet", AsyncServlet.class) .setAsyncSupported(true) .addMapping("/async"); DeploymentInfo builder = new DeploymentInfo() .setClassLoader(NestedListenerInvocationTestCase.class.getClassLoader()) .setContextPath("/servletContext") .setClassIntrospecter(TestClassIntrospector.INSTANCE) .setDeploymentName("servletContext.war") .addServlets(a) .addListener(new ListenerInfo(SimpleRequestListener.class)); DeploymentManager manager = container.addDeployment(builder); manager.deploy(); root.addPrefixPath(builder.getContextPath(), manager.start()); DefaultServer.setRootHandler(root); }
Example #4
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 #5
Source File: EventBusToWebSocket.java From syndesis with Apache License 2.0 | 6 votes |
@Override public void customize(DeploymentInfo deploymentInfo) { deploymentInfo.addInitialHandlerChainWrapper(handler -> { return Handlers.path() .addPrefixPath("/", handler) .addPrefixPath(path, new WebSocketProtocolHandshakeHandler(new WSHandler()) { @Override @SuppressWarnings("PMD.SignatureDeclareThrowsException") public void handleRequest(HttpServerExchange exchange) throws Exception { if (reservationCheck(exchange)) { super.handleRequest(exchange); } } }); } ); }
Example #6
Source File: ParameterEchoTestCase.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(); ServletInfo s = new ServletInfo("servlet", ParameterEchoServlet.class) .addMapping("/aaa"); DeploymentInfo builder = new DeploymentInfo() .setClassLoader(ParameterEchoTestCase.class.getClassLoader()) .setContextPath("/servletContext") .setClassIntrospecter(TestClassIntrospector.INSTANCE) .setDeploymentName("servletContext.war") .addServlet(s); DeploymentManager manager = container.addDeployment(builder); manager.deploy(); root.addPrefixPath(builder.getContextPath(), manager.start()); DefaultServer.setRootHandler(root); }
Example #7
Source File: UndertowDeploymentRecorder.java From quarkus with Apache License 2.0 | 6 votes |
public RuntimeValue<ServletInfo> registerServlet(RuntimeValue<DeploymentInfo> deploymentInfo, String name, Class<?> servletClass, boolean asyncSupported, int loadOnStartup, BeanContainer beanContainer, InstanceFactory<? extends Servlet> instanceFactory) throws Exception { InstanceFactory<? extends Servlet> factory = instanceFactory != null ? instanceFactory : new QuarkusInstanceFactory(beanContainer.instanceFactory(servletClass)); ServletInfo servletInfo = new ServletInfo(name, (Class<? extends Servlet>) servletClass, factory); deploymentInfo.getValue().addServlet(servletInfo); servletInfo.setAsyncSupported(asyncSupported); if (loadOnStartup > 0) { servletInfo.setLoadOnStartup(loadOnStartup); } return new RuntimeValue<>(servletInfo); }
Example #8
Source File: CamelUndertowHostService.java From wildfly-camel with Apache License 2.0 | 6 votes |
private void validateEndpointContextPath(URI httpURI) { String undertowEndpointPath = getContextPath(httpURI); Set<Deployment> deployments = defaultHost.getDeployments(); for (Deployment deployment : deployments) { DeploymentInfo depInfo = deployment.getDeploymentInfo(); String contextPath = depInfo.getContextPath(); if (contextPath.equals(undertowEndpointPath)) { final HttpHandler handler = deployment.getHandler(); if (handler instanceof CamelEndpointDeployerHandler && ((CamelEndpointDeployerHandler)handler).getRoutingHandler() instanceof DelegatingRoutingHandler) { final ModuleClassLoader oldCl = ((DelegatingRoutingHandler)((CamelEndpointDeployerHandler)handler).getRoutingHandler()).classLoader; final ModuleClassLoader tccl = checkTccl(); if (tccl != oldCl) { // Avoid allowing handlers from distinct apps to handle the same path throw new IllegalStateException("Cannot add "+ HttpHandler.class.getName() +" for path " + contextPath + " defined in " + tccl.getName() + " because that path is already served by "+ oldCl.getName()); } } else { // Another application already serves this path throw new IllegalStateException("Cannot overwrite context path " + contextPath + " owned by " + depInfo.getDeploymentName()); } } } }
Example #9
Source File: ServletAndResourceWelcomeFileTestCase.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(ServletPathMappingTestCase.class.getClassLoader()) .setContextPath("/servletContext") .setDeploymentName("servletContext.war") .setResourceManager(new TestResourceLoader(ServletAndResourceWelcomeFileTestCase.class)) .addWelcomePages("doesnotexist.html", "index.html", "default"); builder.addServlet(new ServletInfo("DefaultTestServlet", PathTestServlet.class) .addMapping("*.html")); DeploymentManager manager = container.addDeployment(builder); manager.deploy(); root.addPrefixPath(builder.getContextPath(), manager.start()); DefaultServer.setRootHandler(root); }
Example #10
Source File: ServletOutputStreamTestCase.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.setIgnoreFlush(false); } }, new ServletInfo(BLOCKING_SERVLET, BlockingOutputStreamServlet.class) .addMapping("/" + BLOCKING_SERVLET), new ServletInfo(ASYNC_SERVLET, AsyncOutputStreamServlet.class) .addMapping("/" + ASYNC_SERVLET) .setAsyncSupported(true), new ServletInfo(CONTENT_LENGTH_SERVLET, ContentLengthCloseFlushServlet.class) .addMapping("/" + CONTENT_LENGTH_SERVLET), new ServletInfo(RESET, ResetBufferServlet.class).addMapping("/" + RESET)); }
Example #11
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 #12
Source File: UndertowHandlersConfServletExtension.java From quarkus with Apache License 2.0 | 6 votes |
@Override public void handleDeployment(DeploymentInfo deploymentInfo, ServletContext servletContext) { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); try (InputStream handlers = classLoader.getResourceAsStream(META_INF_UNDERTOW_HANDLERS_CONF)) { if (handlers != null) { // From Stuart Douglas: Ideally these would be parsed at deployment time and passed into a recorder, // however they are likely not bytecode serialisable. Even though this approach // does not 100% align with the Quarkus ethos I think it is ok in this case as // the gains would be marginal compared to the cost of attempting to make // every predicate bytecode serialisable. List<PredicatedHandler> handlerList = PredicatedHandlersParser.parse(handlers, classLoader); if (!handlerList.isEmpty()) { deploymentInfo.addOuterHandlerChainWrapper(new RewriteCorrectingHandlerWrappers.PostWrapper()); deploymentInfo.addOuterHandlerChainWrapper(new HandlerWrapper() { @Override public HttpHandler wrap(HttpHandler handler) { return Handlers.predicates(handlerList, handler); } }); deploymentInfo.addOuterHandlerChainWrapper(new RewriteCorrectingHandlerWrappers.PreWrapper()); } } } catch (IOException e) { throw new UncheckedIOException(e); } }
Example #13
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 #14
Source File: ServletSamlAuthMech.java From keycloak with Apache License 2.0 | 6 votes |
public void addTokenStoreUpdaters(DeploymentInfo deploymentInfo) { deploymentInfo.addSessionListener(new IdMapperUpdaterSessionListener(idMapper)); // This takes care of HTTP sessions manipulated locally SessionIdMapperUpdater updater = SessionIdMapperUpdater.EXTERNAL; try { Map<String, String> initParameters = deploymentInfo.getInitParameters(); String idMapperSessionUpdaterClasses = initParameters == null ? null : initParameters.get("keycloak.sessionIdMapperUpdater.classes"); if (idMapperSessionUpdaterClasses == null) { return; } for (String clazz : idMapperSessionUpdaterClasses.split("\\s*,\\s*")) { if (! clazz.isEmpty()) { updater = invokeAddTokenStoreUpdaterMethod(clazz, deploymentInfo, updater); } } } finally { setIdMapperUpdater(updater); } }
Example #15
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 #16
Source File: RewriteTestCase.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.addOuterHandlerChainWrapper(new HandlerWrapper() { @Override public HttpHandler wrap(HttpHandler handler) { byte[] data = "RewriteRule /foo1 /bar1".getBytes(StandardCharsets.UTF_8); RewriteConfig config = RewriteConfigFactory.build(new ByteArrayInputStream(data)); return new RewriteHandler(config, handler); } }); } }, new ServletInfo("servlet", PathTestServlet.class) .addMapping("/")); }
Example #17
Source File: DeploymentManagerImpl.java From quarkus-http with Apache License 2.0 | 6 votes |
private void initializeErrorPages(final DeploymentImpl deployment, final DeploymentInfo deploymentInfo) { final Map<Integer, String> codes = new HashMap<>(); final Map<Class<? extends Throwable>, String> exceptions = new HashMap<>(); String defaultErrorPage = null; for (final ErrorPage page : deploymentInfo.getErrorPages()) { if (page.getExceptionType() != null) { exceptions.put(page.getExceptionType(), page.getLocation()); } else if (page.getErrorCode() != null) { codes.put(page.getErrorCode(), page.getLocation()); } else { if (defaultErrorPage != null) { throw UndertowServletMessages.MESSAGES.moreThanOneDefaultErrorPage(defaultErrorPage, page.getLocation()); } else { defaultErrorPage = page.getLocation(); } } } deployment.setErrorPages(new ErrorPages(codes, exceptions, defaultErrorPage)); }
Example #18
Source File: EagerServletLifecycleTestCase.java From quarkus-http with Apache License 2.0 | 6 votes |
@Test public void testServletLifecycle() throws Exception { final PathHandler root = new PathHandler(); final ServletContainer container = ServletContainer.Factory.newInstance(); FilterInfo f = new FilterInfo("filter", LifecycleFilter.class); DeploymentInfo builder = new DeploymentInfo() .setClassLoader(EagerServletLifecycleTestCase.class.getClassLoader()) .setContextPath("/servletContext") .setClassIntrospecter(TestClassIntrospector.INSTANCE) .setDeploymentName("servletContext.war") .setEagerFilterInit(true) .addFilter(f) .addFilterUrlMapping("filter", "/aa", DispatcherType.REQUEST); DeploymentManager manager = container.addDeployment(builder); manager.deploy(); root.addPrefixPath(builder.getContextPath(), manager.start()); DefaultServer.setRootHandler(root); Assert.assertTrue(LifecycleFilter.initCalled); }
Example #19
Source File: DeploymentUtils.java From quarkus-http with Apache License 2.0 | 6 votes |
/** * Sets up a simple servlet deployment with the provided servlets. * * This is just a convenience method for simple deployments * * @param servlets The servlets to add */ public static Deployment setupServlet(final ServletExtension servletExtension, final ServletInfo... servlets) { final PathHandler pathHandler = new PathHandler(); final ServletContainer container = ServletContainer.Factory.newInstance(); DeploymentInfo builder = new DeploymentInfo() .setClassLoader(SimpleServletTestCase.class.getClassLoader()) .setContextPath("/servletContext") .setClassIntrospecter(TestClassIntrospector.INSTANCE) .setDeploymentName("servletContext.war") .addServlets(servlets); if(servletExtension != null) { builder.addServletExtension(servletExtension); } DeploymentManager manager = container.addDeployment(builder); manager.deploy(); try { pathHandler.addPrefixPath(builder.getContextPath(), manager.start()); } catch (ServletException e) { throw new RuntimeException(e); } DefaultServer.setRootHandler(pathHandler); return manager.getDeployment(); }
Example #20
Source File: GetResourceTestCase.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(GetResourceTestCase.class.getClassLoader()) .setContextPath("/servletContext") .setDeploymentName("servletContext.war") .setResourceManager(new TestResourceLoader(GetResourceTestCase.class)); builder.addServlet(new ServletInfo("ReadFileServlet", ReadFileServlet.class) .addMapping("/file")); DeploymentManager manager = container.addDeployment(builder); manager.deploy(); root.addPrefixPath(builder.getContextPath(), manager.start()); DefaultServer.setRootHandler(root); }
Example #21
Source File: ServletSessionListenerOrderingTestCase.java From quarkus-http with Apache License 2.0 | 6 votes |
@BeforeClass public static void setup() throws ServletException { final PathHandler path = new PathHandler(); final ServletContainer container = ServletContainer.Factory.newInstance(); DeploymentInfo builder = new DeploymentInfo() .setClassLoader(SimpleServletTestCase.class.getClassLoader()) .setContextPath("/listener") .setClassIntrospecter(TestClassIntrospector.INSTANCE) .setDeploymentName("listener.war") .addListener(new ListenerInfo(FirstListener.class)) .addListener(new ListenerInfo(SecondListener.class)) .addServlet(new ServletInfo("message", EmptyServlet.class) .addMapping("/*")); DeploymentManager manager = container.addDeployment(builder); manager.deploy(); path.addPrefixPath(builder.getContextPath(), manager.start()); DefaultServer.setRootHandler(path); }
Example #22
Source File: UndertowAutoConfigurationIT.java From joinfaces with Apache License 2.0 | 6 votes |
@Test void customize() throws IOException { UndertowServletWebServerFactory factory = new UndertowServletWebServerFactory(); this.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(); }
Example #23
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 #24
Source File: ProgramaticAutobahnServer.java From quarkus-http with Apache License 2.0 | 5 votes |
public void run() { try { final ServletContainer container = ServletContainer.Factory.newInstance(); DeploymentInfo builder = new DeploymentInfo() .setClassLoader(ProgramaticAutobahnServer.class.getClassLoader()) .setContextPath("/") .setClassIntrospecter(TestClassIntrospector.INSTANCE) .setDeploymentName("servletContext.war") .addFilter(new FilterInfo("filter", JsrWebSocketFilter.class)) .addFilterUrlMapping("filter", "/*", DispatcherType.REQUEST) .addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, new WebSocketDeploymentInfo() .setDispatchToWorkerThread(true) .addEndpoint(new ServerEndpointConfigImpl(ProgramaticAutobahnEndpoint.class, "/")) ); DeploymentManager manager = container.addDeployment(builder); manager.deploy(); Undertow.builder().addHttpListener(port, "localhost") .setHandler(manager.start()) .build(); } catch (Exception e) { throw new RuntimeException(e); } }
Example #25
Source File: UndertowHTTPServerEngine.java From cxf with Apache License 2.0 | 5 votes |
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(); }
Example #26
Source File: AbstractUndertowServer.java From cxf with Apache License 2.0 | 5 votes |
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", String.join(",", JacksonJsonProvider.class.getName(), BookStoreResponseFilter.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()); } }
Example #27
Source File: BypassServletTestCase.java From quarkus-http with Apache License 2.0 | 5 votes |
@BeforeClass public static void setup() throws ServletException { final PathHandler root = new PathHandler(); final ServletContainer container = ServletContainer.Factory.newInstance(); DeploymentInfo builder = new DeploymentInfo() .setClassLoader(SimpleServletTestCase.class.getClassLoader()) .setContextPath("/servletContext") .setClassIntrospecter(TestClassIntrospector.INSTANCE) .setDeploymentName("servletContext.war") .addServlet( new ServletInfo("servlet", MessageServlet.class) .addMapping("/") .addInitParam(MessageServlet.MESSAGE, "This is a servlet") ) .addListener(new ListenerInfo(TestListener.class)) .addInitialHandlerChainWrapper(new HandlerWrapper() { @Override public HttpHandler wrap(final HttpHandler handler) { return new HttpHandler() { @Override public void handleRequest(final HttpServerExchange exchange) throws Exception { if (exchange.getRelativePath().equals("/async")) { exchange.writeAsync("This is not a servlet"); } else { handler.handleRequest(exchange); } } }; } }); DeploymentManager manager = container.addDeployment(builder); manager.deploy(); root.addPrefixPath(builder.getContextPath(), manager.start()); DefaultServer.setRootHandler(root); }
Example #28
Source File: AsyncListenerExceptionTest.java From quarkus-http with Apache License 2.0 | 5 votes |
@BeforeClass public static void setup() throws ServletException { final PathHandler root = new PathHandler(); final ServletContainer container = ServletContainer.Factory.newInstance(); ServletInfo runtime = new ServletInfo("runtime", RuntimeExceptionServlet.class) .addMapping("/runtime") .setAsyncSupported(true); ServletInfo io = new ServletInfo("io", IOExceptionServlet.class) .addMapping("/io") .setAsyncSupported(true); ServletInfo error = new ServletInfo("error", ErrorServlet.class) .addMapping("/error") .setAsyncSupported(true); DeploymentInfo builder = new DeploymentInfo() .setClassLoader(AsyncListenerExceptionTest.class.getClassLoader()) .setContextPath("/servletContext") .setClassIntrospecter(TestClassIntrospector.INSTANCE) .setDeploymentName("servletContext.war") .addServlets(runtime, io, error); DeploymentManager manager = container.addDeployment(builder); manager.deploy(); root.addPrefixPath(builder.getContextPath(), manager.start()); DefaultServer.setRootHandler(root); }
Example #29
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 #30
Source File: TimerLoggerServletExtension.java From hawkular-metrics with Apache License 2.0 | 5 votes |
@Override public void handleDeployment(DeploymentInfo deploymentInfo, ServletContext servletContext) { long timeThreshold = DEFAULT_THRESHOLD_VALUE; String thresholdValue; thresholdValue = System.getProperty(THRESHOLD_PROPERTY_KEY); if ( thresholdValue == null){ thresholdValue = System.getenv(THRESHOLD_ENV_VAR); } if ( thresholdValue != null && !thresholdValue.isEmpty()) { try { timeThreshold = Long.parseLong(thresholdValue); } catch (Exception e) { throw new RuntimeException(e); } } final long cTimeThreshold = timeThreshold; deploymentInfo.addInitialHandlerChainWrapper(containerHandler -> { requestTimeLogger = new RequestTimeLogger(containerHandler, cTimeThreshold); return requestTimeLogger; }); }