Java Code Examples for io.undertow.Handlers#path()

The following examples show how to use io.undertow.Handlers#path() . 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: RangeRequestTestCase.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setup() throws URISyntaxException {
    Path rootPath = Paths.get(RangeRequestTestCase.class.getResource("range.txt").toURI()).getParent();
    PathHandler path = Handlers.path();
    path.addPrefixPath("/path", new ByteRangeHandler(new HttpHandler() {
        @Override
        public void handleRequest(HttpServerExchange exchange) throws Exception {
            exchange.setResponseHeader(HttpHeaderNames.LAST_MODIFIED, DateUtils.toDateString(new Date(10000)));
            exchange.setResponseHeader(HttpHeaderNames.ETAG, "\"someetag\"");
            exchange.setResponseContentLength("0123456789".length());
            exchange.writeAsync(Unpooled.copiedBuffer("0123456789", StandardCharsets.UTF_8), true, IoCallback.END_EXCHANGE, null);
        }
    }, true));
    path.addPrefixPath("/resource",  new ResourceHandler( new PathResourceManager(rootPath, 10485760))
            .setDirectoryListingEnabled(true));
    path.addPrefixPath("/cachedresource",  new ResourceHandler(new CachingResourceManager(1000, 1000000, new DirectBufferCache(1000, 10, 10000), new PathResourceManager(rootPath, 10485760), -1))
            .setDirectoryListingEnabled(true));
    path.addPrefixPath("/resource-blocking",  new BlockingHandler(new ResourceHandler( new PathResourceManager(rootPath, 10485760))
            .setDirectoryListingEnabled(true)));
    path.addPrefixPath("/cachedresource-blocking",  new BlockingHandler(new ResourceHandler(new CachingResourceManager(1000, 1000000, new DirectBufferCache(1000, 10, 10000), new PathResourceManager(rootPath, 10485760), -1))
            .setDirectoryListingEnabled(true)));
    DefaultServer.setRootHandler(path);
}
 
Example 2
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 3
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 4
Source File: WSSharedServer.java    From greycat with Apache License 2.0 5 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();
    server.start();
    this.graph.storage().listen(this);//stop
}
 
Example 5
Source File: WSServer.java    From greycat with Apache License 2.0 5 votes vote down vote up
public void start() {
    final PathHandler 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();
    server.start();
    if (builder.storage != null) {
        builder.storage.listen(this);
    } else if (builder.storageFactory != null) {
        builder.storageFactory.listen(this);
    }
}
 
Example 6
Source File: UndertowHTTPServerEngine.java    From cxf with Apache License 2.0 5 votes vote down vote up
private Undertow createServer(URL url, UndertowHTTPHandler undertowHTTPHandler) throws Exception {
    Undertow.Builder result = Undertow.builder();
    result.setServerOption(UndertowOptions.IDLE_TIMEOUT, getMaxIdleTime());
    if (this.shouldEnableHttp2(undertowHTTPHandler.getBus())) {
        result.setServerOption(UndertowOptions.ENABLE_HTTP2, Boolean.TRUE);
    }
    if (tlsServerParameters != null) {
        if (this.sslContext == null) {
            this.sslContext = createSSLContext();
        }
        result = result.addHttpsListener(getPort(), getHost(), this.sslContext);
    } else {
        result = result.addHttpListener(getPort(), getHost());
    }
    path = Handlers.path(new NotFoundHandler());

    if (url.getPath().length() == 0) {
        result = result.setHandler(Handlers.trace(undertowHTTPHandler));
    } else {
        if (undertowHTTPHandler.isContextMatchExact()) {
            path.addExactPath(url.getPath(), undertowHTTPHandler);
        } else {
            path.addPrefixPath(url.getPath(), undertowHTTPHandler);
        }

        result = result.setHandler(wrapHandler(new HttpContinueReadHandler(path)));
    }

    result = decorateUndertowSocketConnection(result);
    result = disableSSLv3(result);
    result = configureThreads(result);
    return result.build();
}
 
Example 7
Source File: UndertowServer.java    From pippo with Apache License 2.0 5 votes vote down vote up
protected HttpHandler createContextHandler(HttpHandler pippoHandler) {
    String contextPath = getSettings().getContextPath();

    // create a handler than redirects non-contact requests to the context
    PathHandler contextHandler = Handlers.path(Handlers.redirect(contextPath));

    // add the handler with the context prefix
    contextHandler.addPrefixPath(contextPath, pippoHandler);

    return contextHandler;
}
 
Example 8
Source File: Application.java    From jersey-jwt with MIT License 4 votes vote down vote up
/**
 * Start server on the given port.
 *
 * @param port
 */
public static void startServer(int port) {

    LOGGER.info(String.format("Starting server on port %d", port));

    PathHandler path = Handlers.path();

    server = Undertow.builder()
            .addHttpListener(port, "localhost")
            .setHandler(path)
            .build();

    server.start();

    LOGGER.info(String.format("Server started on port %d", port));

    DeploymentInfo servletBuilder = Servlets.deployment()
            .setClassLoader(Application.class.getClassLoader())
            .setContextPath("/")
            .addListeners(listener(Listener.class))
            .setResourceManager(new ClassPathResourceManager(Application.class.getClassLoader()))
            .addServlets(
                    Servlets.servlet("jerseyServlet", ServletContainer.class)
                            .setLoadOnStartup(1)
                            .addInitParam("javax.ws.rs.Application", JerseyConfig.class.getName())
                            .addMapping("/api/*"))
            .setDeploymentName("application.war");

    LOGGER.info("Starting application deployment");

    deploymentManager = Servlets.defaultContainer().addDeployment(servletBuilder);
    deploymentManager.deploy();

    try {
        path.addPrefixPath("/", deploymentManager.start());
    } catch (ServletException e) {
        throw new RuntimeException(e);
    }

    LOGGER.info("Application deployed");
}