Java Code Examples for io.undertow.server.handlers.PathHandler

The following examples show how to use io.undertow.server.handlers.PathHandler. These examples are extracted from open source projects. 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
@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 2
Source Project: quarkus-http   Source File: GetResourceTestCase.java    License: Apache License 2.0 6 votes vote down vote up
@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 3
Source Project: seed   Source File: ServerFactory.java    License: Mozilla Public License 2.0 6 votes vote down vote up
Undertow createServer(HttpHandler httpHandler, SSLProvider sslProvider) {
    PathHandler path = Handlers
            .path(Handlers.redirect(serverConfig.getContextPath()))
            .addPrefixPath(serverConfig.getContextPath(), httpHandler);

    Undertow.Builder builder = Undertow.builder().setWorker(xnioWorker);

    if (!serverConfig.isHttp() && !serverConfig.isHttps()) {
        throw SeedException.createNew(UndertowErrorCode.NO_LISTENER_CONFIGURED);
    } else {
        if (serverConfig.isHttp()) {
            builder = configureHttp(builder);
        }
        if (serverConfig.isHttps()) {
            builder = configureHttps(builder, sslProvider);
            if (serverConfig.isHttp2()) {
                LOGGER.info("HTTP/2 support is enabled");
                builder.setServerOption(UndertowOptions.ENABLE_HTTP2, serverConfig.isHttp2());
            }
        }
    }

    return builder.setHandler(path).build();
}
 
Example 4
Source Project: quarkus-http   Source File: MockRequestTestCase.java    License: Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setup() throws ServletException {

    final PathHandler root = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();

    ServletInfo s = new ServletInfo("servlet", HelloServlet.class).addMapping("/aa");

    DeploymentInfo builder = new DeploymentInfo()
            .setClassLoader(MockRequestTestCase.class.getClassLoader())
            .setContextPath("/servletContext")
            .setClassIntrospecter(TestClassIntrospector.INSTANCE)
            .setDeploymentName("servletContext.war")
            .addServlet(s);

    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    deployment = manager.getDeployment();
    root.addPrefixPath(builder.getContextPath(), manager.start());

    DefaultServer.setRootHandler(root);
}
 
Example 5
static HttpHandler postgresqlPathHandler() {
  var config = new HikariConfig();
  config.setJdbcUrl("jdbc:postgresql://tfb-database:5432/hello_world");
  config.setUsername("benchmarkdbuser");
  config.setPassword("benchmarkdbpass");
  config.setMaximumPoolSize(48);

  var db = new HikariDataSource(config);

  return new BlockingHandler(
      new PathHandler()
          .addExactPath("/db", dbHandler(db))
          .addExactPath("/queries", queriesHandler(db))
          .addExactPath("/fortunes", fortunesHandler(db))
          .addExactPath("/updates", updatesHandler(db)));
}
 
Example 6
@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")
            .addServletContainerInitializer(new ServletContainerInitializerInfo(TestSci.class, Collections.<Class<?>>emptySet()))
            .addServlet(
                    new ServletInfo("servlet", MessageServlet.class)
                            .addMapping("/aa")
            )
            .addListener(new ListenerInfo(ServletContextTestListener.class));


    manager = container.addDeployment(builder);
    manager.deploy();
    root.addPrefixPath(builder.getContextPath(), manager.start());

    DefaultServer.setRootHandler(root);
}
 
Example 7
@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 8
@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(SimpleSessionListener.class))
            .addServlet(new ServletInfo("servlet", SessionServlet.class)
                .addMapping("/test"));

    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    path.addPrefixPath(builder.getContextPath(), manager.start());

    DefaultServer.setRootHandler(path);
}
 
Example 9
@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 10
Source Project: quarkus-http   Source File: SimpleServletTestCase.java    License: Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setup() throws ServletException {

    final PathHandler root = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();

    ServletInfo s = new ServletInfo("servlet", MessageServlet.class)
            .addInitParam(MessageServlet.MESSAGE, HELLO_WORLD)
            .addMapping("/aa");

    DeploymentInfo builder = new DeploymentInfo()
            .setClassLoader(SimpleServletTestCase.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 11
Source Project: quarkus-http   Source File: ChangeSessionIdTestCase.java    License: Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setup() throws ServletException {

    final PathHandler path = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();

    ServletInfo s = new ServletInfo("servlet", ChangeSessionIdServlet.class)
            .addMapping("/aa");
    DeploymentInfo builder = new DeploymentInfo()
            .setClassLoader(SimpleServletTestCase.class.getClassLoader())
            .setContextPath("/servletContext")
            .setClassIntrospecter(TestClassIntrospector.INSTANCE)
            .setDeploymentName("servletContext.war")
            .addListener(new ListenerInfo(ChangeSessionIdListener.class))
            .addServlet(s);

    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    path.addPrefixPath(builder.getContextPath(), manager.start());
    DefaultServer.setRootHandler(path);
}
 
Example 12
Source Project: quarkus-http   Source File: ServletSessionTestCase.java    License: Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setup() throws ServletException {


    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")
            .addListener(new ListenerInfo(SessionCookieConfigListener.class))
            .addServlets(new ServletInfo("servlet", SessionServlet.class)
                    .addMapping("/aa/b"));
    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    try {
        pathHandler.addPrefixPath(builder.getContextPath(), manager.start());
    } catch (ServletException e) {
        throw new RuntimeException(e);
    }
    DefaultServer.setRootHandler(pathHandler);
}
 
Example 13
Source Project: quarkus-http   Source File: SessionIdHandlingTestCase.java    License: Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setup() throws ServletException {


    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(new ServletInfo("servlet", RequestedSessionIdServlet.class)
                    .addMapping("/session"));
    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    try {
        pathHandler.addPrefixPath(builder.getContextPath(), manager.start());
    } catch (ServletException e) {
        throw new RuntimeException(e);
    }
    DefaultServer.setRootHandler(pathHandler);
}
 
Example 14
Source Project: quarkus-http   Source File: ResponseWriterTestCase.java    License: Apache License 2.0 6 votes vote down vote up
@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 15
Source Project: quarkus-http   Source File: ContentTypeFilesTestCase.java    License: Apache License 2.0 6 votes vote down vote up
@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(ContentTypeFilesTestCase.class.getClassLoader())
            .setContextPath("/app")
            .setDeploymentName("servletContext.war")
            .setResourceManager(new TestResourceLoader(ContentTypeServlet.class))
            .setDefaultServletConfig(new DefaultServletConfig(true))
            .addMimeMapping(new MimeMapping("jnlp", "application/x-java-jnlp-file"));

    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    root.addPrefixPath(builder.getContextPath(), manager.start());
    DefaultServer.setRootHandler(root);
}
 
Example 16
@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 17
@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 18
Source Project: quarkus-http   Source File: ParameterEchoTestCase.java    License: Apache License 2.0 6 votes vote down vote up
@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 19
Source Project: quarkus-http   Source File: GetCookiesTestCase.java    License: Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setup() throws ServletException {

    final PathHandler root = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();

    ServletInfo s = new ServletInfo("servlet", ValidCookieEchoServlet.class)
            .addMapping("/aaa");

    DeploymentInfo builder = new DeploymentInfo()
            .setClassLoader(GetCookiesTestCase.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 20
Source Project: quarkus-http   Source File: DeploymentUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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 21
Source Project: quarkus-http   Source File: RealPathTestCase.java    License: Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setup() throws ServletException {

    final PathHandler root = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();

    ServletInfo realPathServlet = new ServletInfo("real path servlet", RealPathServlet.class)
            .addMapping("/path/*");

    DeploymentInfo builder = new DeploymentInfo()
            .setClassIntrospecter(TestClassIntrospector.INSTANCE)
            .setClassLoader(RealPathTestCase.class.getClassLoader())
            .setContextPath("/servletContext")
            .setDeploymentName("servletContext.war")
            .setResourceManager(new TestResourceLoader(RealPathTestCase.class))
            .addServlets(realPathServlet);

    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    root.addPrefixPath(builder.getContextPath(), manager.start());

    DefaultServer.setRootHandler(root);

}
 
Example 22
Source Project: quarkus-http   Source File: JsrWebSocketServerTest.java    License: Apache License 2.0 6 votes vote down vote up
private ServletContext deployServlet(final ServerWebSocketContainer deployment) throws ServletException {

        final DeploymentInfo builder;
        builder = new DeploymentInfo()
                .setClassLoader(getClass().getClassLoader())
                .setContextPath("/")
                .setClassIntrospecter(TestClassIntrospector.INSTANCE)
                .setDeploymentName("websocket.war")
                .addFilter(new FilterInfo("filter", JsrWebSocketFilter.class))
                .addFilterUrlMapping("filter", "/*", DispatcherType.REQUEST)
                .addServletContextAttribute(javax.websocket.server.ServerContainer.class.getName(), deployment);

        final PathHandler root = new PathHandler();
        final ServletContainer container = ServletContainer.Factory.newInstance();
        DeploymentManager manager = container.addDeployment(builder);
        manager.deploy();
        root.addPrefixPath(builder.getContextPath(), manager.start());

        DefaultServer.setRootHandler(root);
        return manager.getDeployment().getServletContext();
    }
 
Example 23
Source Project: metrics   Source File: ExampleServer.java    License: Apache License 2.0 6 votes vote down vote up
public static void main(String... args) {
  // Create a reporter and add it to the registry.
  // For demo purposes we use SLF4JReporter which should not be used for production systems
  Reporter reporter = SLF4JReporter.builder().withName("example").withStepSize(10).build();
  metricRegistry.addReporter(reporter);

  // Create the handler chain
  // MetricsHandler -> PathHandler -> HelloWorldHandler / 404
  HttpHandler helloHandler = new HelloWorldHandler();
  PathHandler pathHandler = new PathHandler();
  pathHandler.addExactPath("/hello", helloHandler);
  HttpHandler metricsHandler = new MetricsHandler(pathHandler);

  // Build the server instance
  Undertow server = Undertow.builder()
      .addHttpListener(8080, "localhost")
      .setHandler(metricsHandler)
      .build();

  // And start it
  server.start();
}
 
Example 24
Source Project: leafserver   Source File: IndexController.java    License: Apache License 2.0 6 votes vote down vote up
@PostConstruct
public void init() {
    Undertow server = Undertow.builder()
            .addHttpListener(9999, "localhost").setHandler(new PathHandler() {
                {
                    addExactPath("/id", exchange -> {
                        Map<String, Deque<String>> pathParameters = exchange.getQueryParameters();
                        Result result = sequenceCore.nextValue(pathParameters.get("app").getFirst(), pathParameters.get("key").getFirst());
                        exchange.getResponseSender().send(JSON.toJSONString(result));
                    });
                }

            })
            .build();
    server.start();
}
 
Example 25
Source Project: greycat   Source File: WSServerWithWorkers.java    License: Apache License 2.0 6 votes vote down vote up
public void start() {

        logger.debug("WSServer starting");
        PathHandler pathHandler;
        if (this.defaultHandler != null) {
            pathHandler = Handlers.path(defaultHandler);
        } else {
            pathHandler = Handlers.path();
        }
        for (String name : handlers.keySet()) {
            pathHandler.addPrefixPath(name, handlers.get(name));
        }

        String serverPath = "ws://" + SERVER_IP + ":" + port + SERVER_PREFIX;
        this.server = Undertow.builder()
                .addHttpListener(port, SERVER_IP, pathHandler)
                .setServerOption(UndertowOptions.NO_REQUEST_TIMEOUT, wsMaxIdle)
                .setServerOption(UndertowOptions.IDLE_TIMEOUT, wsMaxIdle)
                .setServerOption(UndertowOptions.ALWAYS_SET_KEEP_ALIVE, true)
                .build();

        server.start();
        logger.info("WSServer started on " + serverPath);
    }
 
Example 26
Source Project: greycat   Source File: WSServer.java    License: Apache License 2.0 6 votes vote down vote up
public void start() {
    PathHandler pathHandler;
    if (this.defaultHandler != null) {
        pathHandler = Handlers.path(defaultHandler);
    } else {
        pathHandler = Handlers.path();
    }
    for (String name : handlers.keySet()) {
        pathHandler.addPrefixPath(name, handlers.get(name));
    }
    this.server = Undertow.builder().addHttpListener(port, "0.0.0.0", pathHandler).build();
    DeferCounterSync deferCounterSync = new CoreDeferCounterSync(1);
    executorService = Executors.newFixedThreadPool(Math.max(1, thread));
    this.resolver = new ResolverWorker(resultsToResolve, peers);
    this.graphExec = new GraphExecutor(builder, graphInput, deferCounterSync, resultsToResolve);
    server.start();
    resolver.start();
    graphExec.start();
    deferCounterSync.waitResult();
}
 
Example 27
Source Project: keycloak   Source File: CRLRule.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void before() throws Throwable {
    log.info("Starting CRL Responder");

    PathHandler pathHandler = new PathHandler();
    pathHandler.addExactPath(AbstractX509AuthenticationTest.EMPTY_CRL_PATH, new CRLHandler(AbstractX509AuthenticationTest.EMPTY_CRL_PATH));
    pathHandler.addExactPath(AbstractX509AuthenticationTest.INTERMEDIATE_CA_CRL_PATH, new CRLHandler(AbstractX509AuthenticationTest.INTERMEDIATE_CA_CRL_PATH));
    pathHandler.addExactPath(AbstractX509AuthenticationTest.INTERMEDIATE_CA_INVALID_SIGNATURE_CRL_PATH, new CRLHandler(AbstractX509AuthenticationTest.INTERMEDIATE_CA_INVALID_SIGNATURE_CRL_PATH));
    pathHandler.addExactPath(AbstractX509AuthenticationTest.INTERMEDIATE_CA_3_CRL_PATH, new CRLHandler(AbstractX509AuthenticationTest.INTERMEDIATE_CA_3_CRL_PATH));

    crlResponder = Undertow.builder().addHttpListener(CRL_RESPONDER_PORT, CRL_RESPONDER_HOST)
            .setHandler(
                    new BlockingHandler(pathHandler)
            ).build();

    crlResponder.start();
}
 
Example 28
Source Project: quarkus-http   Source File: ServletServer.java    License: Apache License 2.0 5 votes vote down vote up
public static void main(final String[] args) {
    try {

        DeploymentInfo servletBuilder = deployment()
                .setClassLoader(ServletServer.class.getClassLoader())
                .setContextPath(MYAPP)
                .setDeploymentName("test.war")
                .addServlets(
                        servlet("MessageServlet", MessageServlet.class)
                                .addInitParam("message", "Hello World")
                                .addMapping("/*"),
                        servlet("MyServlet", MessageServlet.class)
                                .addInitParam("message", "MyServlet")
                                .addMapping("/myservlet"));

        DeploymentManager manager = defaultContainer().addDeployment(servletBuilder);
        manager.deploy();

        HttpHandler servletHandler = manager.start();
        PathHandler path = Handlers.path(Handlers.redirect(MYAPP))
                .addPrefixPath(MYAPP, servletHandler);
        Undertow server = Undertow.builder()
                .addHttpListener(8080, "localhost")
                .setHandler(path)
                .build();
        server.start();
    } catch (ServletException e) {
        throw new RuntimeException(e);
    }
}
 
Example 29
Source Project: keycloak   Source File: KeycloakOnUndertow.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void undeploy(Archive<?> archive) throws DeploymentException {
    if (isRemoteMode()) {
        log.infof("Skipped undeployment of '%s' as we are in remote mode!", archive.getName());
        return;
    }

    Field containerField = Reflections.findDeclaredField(UndertowJaxrsServer.class, "container");
    Reflections.setAccessible(containerField);
    ServletContainer container = (ServletContainer) Reflections.getFieldValue(containerField, undertow);

    DeploymentManager deploymentMgr = container.getDeployment(archive.getName());
    if (deploymentMgr != null) {
        DeploymentInfo deployment = deploymentMgr.getDeployment().getDeploymentInfo();

        try {
            deploymentMgr.stop();
        } catch (ServletException se) {
            throw new DeploymentException(se.getMessage(), se);
        }

        deploymentMgr.undeploy();

        Field rootField = Reflections.findDeclaredField(UndertowJaxrsServer.class, "root");
        Reflections.setAccessible(rootField);
        PathHandler root = (PathHandler) Reflections.getFieldValue(rootField, undertow);

        String path = deployedArchivesToContextPath.get(archive.getName());
        root.removePrefixPath(path);

        container.removeDeployment(deployment);
    } else {
        log.warnf("Deployment '%s' not found", archive.getName());
    }
}
 
Example 30
private ExtensionHandlers(PathHandler extensionPathHandler, HttpHandler managementHandler,
        Function<HttpServerExchange, Boolean> readyFunction, ResourceHandlerDefinition consoleHandler) {
    this.extensionPathHandler = extensionPathHandler;
    this.managementHandler = managementHandler;
    this.readyFunction = readyFunction;
    if (consoleHandler == null) {
        this.reservedContexts = RESERVED_CONTEXTS;
    } else {
        Set<String> set = new HashSet<>(RESERVED_CONTEXTS);
        set.add(consoleHandler.getContext());
        this.reservedContexts = Collections.unmodifiableSet(set);
    }
}