io.undertow.server.handlers.PathHandler Java Examples

The following examples show how to use io.undertow.server.handlers.PathHandler. 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: CRLRule.java    From keycloak with 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 #2
Source File: HelloWebServer.java    From FrameworkBenchmarks with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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 #3
Source File: MockRequestTestCase.java    From quarkus-http with 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 #4
Source File: GetResourceTestCase.java    From quarkus-http with 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 #5
Source File: ServerFactory.java    From seed with 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 #6
Source File: ServletContextListenerTestCase.java    From quarkus-http with 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()
            .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
Source File: NestedListenerInvocationTestCase.java    From quarkus-http with 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 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
Source File: ServletSessionInvalidateWithListenerTestCase.java    From quarkus-http with 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();

    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
Source File: ServletSessionListenerOrderingTestCase.java    From quarkus-http with 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();

    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 File: SimpleServletTestCase.java    From quarkus-http with 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 File: ChangeSessionIdTestCase.java    From quarkus-http with 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 File: ServletSessionTestCase.java    From quarkus-http with 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 File: SessionIdHandlingTestCase.java    From quarkus-http with 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 File: ResponseWriterTestCase.java    From quarkus-http with 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 File: ContentTypeFilesTestCase.java    From quarkus-http with 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
Source File: DefaultServletCachingTestCase.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
@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
Source File: ServletAndResourceWelcomeFileTestCase.java    From quarkus-http with 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(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 File: ParameterEchoTestCase.java    From quarkus-http with 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 File: GetCookiesTestCase.java    From quarkus-http with 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 File: DeploymentUtils.java    From quarkus-http with 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 File: RealPathTestCase.java    From quarkus-http with 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 File: JsrWebSocketServerTest.java    From quarkus-http with 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 File: ExampleServer.java    From metrics with 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 File: IndexController.java    From leafserver with 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 File: WSServerWithWorkers.java    From greycat with 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 File: WSServer.java    From greycat with 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 File: EagerServletLifecycleTestCase.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
@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 #28
Source File: KeycloakOnUndertow.java    From keycloak with 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 #29
Source File: SecurityErrorPageTestCase.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
@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 #30
Source File: DerefMiddlewareHandlerTest.java    From light-4j with Apache License 2.0 5 votes vote down vote up
static PathHandler getTestHandler() {
    return Handlers.path()
            .addPrefixPath("/api", (exchange) -> {
                // check if the Authorization header contains JWT token here.
                String authHeader = exchange.getRequestHeaders().getFirst(Headers.AUTHORIZATION);
                Assert.assertEquals("Bearer " + token, authHeader);
                exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "application/json");
                exchange.getResponseSender().send("OK");
            });
}