Search in sources :

Example 26 with Undertow

use of io.undertow.Undertow in project kontraktor by RuedigerMoeller.

the class Http4K method publishFileSystem.

/**
 * publishes given file root
 * @param hostName
 * @param urlPath - prefixPath (e.g. /myapp/resource)
 * @param port
 * @param root - directory to be published
 */
public Http4K publishFileSystem(String hostName, String urlPath, int port, File root) {
    if (!root.isDirectory()) {
        throw new RuntimeException("root must be an existing direcory:" + root.getAbsolutePath());
    }
    Pair<PathHandler, Undertow> server = getServer(port, hostName);
    server.car().addPrefixPath(urlPath, new ResourceHandler(new FileResourceManager(root, 100)));
    return this;
}
Also used : FileResourceManager(io.undertow.server.handlers.resource.FileResourceManager) PathHandler(io.undertow.server.handlers.PathHandler) ResourceHandler(io.undertow.server.handlers.resource.ResourceHandler) Undertow(io.undertow.Undertow)

Example 27 with Undertow

use of io.undertow.Undertow in project kontraktor by RuedigerMoeller.

the class Http4K method publishFileSystem.

// FIXME: exposes Undertow class
public Http4K publishFileSystem(String hostName, String urlPath, int port, FileResourceManager man) {
    if (!man.getBase().isDirectory()) {
        throw new RuntimeException("root must be an existing direcory:" + man.getBase().getAbsolutePath());
    }
    Pair<PathHandler, Undertow> server = getServer(port, hostName);
    server.car().addPrefixPath(urlPath, new ResourceHandler(man));
    return this;
}
Also used : PathHandler(io.undertow.server.handlers.PathHandler) ResourceHandler(io.undertow.server.handlers.resource.ResourceHandler) Undertow(io.undertow.Undertow)

Example 28 with Undertow

use of io.undertow.Undertow in project kontraktor by RuedigerMoeller.

the class Http4K method getServer.

public synchronized Pair<PathHandler, Undertow> getServer(int port, String hostName, SSLContext context) {
    Pair<PathHandler, Undertow> pair = serverMap.get(port);
    if (pair == null) {
        PathHandler pathHandler = new PathHandler();
        Undertow.Builder builder = Undertow.builder().setIoThreads(UNDERTOW_IO_THREADS).setWorkerThreads(UNDERTOW_WORKER_THREADS);
        Undertow server = customize(builder, pathHandler, port, hostName, context).build();
        server.start();
        pair = new Pair<>(pathHandler, server);
        serverMap.put(port, pair);
    }
    return pair;
}
Also used : PathHandler(io.undertow.server.handlers.PathHandler) Undertow(io.undertow.Undertow)

Example 29 with Undertow

use of io.undertow.Undertow in project kontraktor by RuedigerMoeller.

the class HttpPublisher method publish.

@Override
public IPromise<ActorServer> publish(Consumer<Actor> disconnectCallback) {
    ActorServer actorServer;
    try {
        Pair<PathHandler, Undertow> serverPair = Http4K.get().getServer(port, hostName);
        UndertowHttpServerConnector con = new UndertowHttpServerConnector(facade);
        con.setConnectionVerifier(connectionVerifier);
        con.setSessionTimeout(sessionTimeout);
        actorServer = new ActorServer(con, facade, coding == null ? new Coding(SerializerType.FSTSer) : coding);
        con.setActorServer(actorServer);
        actorServer.start(disconnectCallback);
        serverPair.getFirst().addPrefixPath(urlPath, con);
    } catch (Exception e) {
        Log.Warn(null, e);
        return new Promise<>(null, e);
    }
    return new Promise<>(actorServer);
}
Also used : Promise(org.nustaq.kontraktor.Promise) IPromise(org.nustaq.kontraktor.IPromise) ActorServer(org.nustaq.kontraktor.remoting.base.ActorServer) Coding(org.nustaq.kontraktor.remoting.encoding.Coding) PathHandler(io.undertow.server.handlers.PathHandler) Undertow(io.undertow.Undertow)

Example 30 with Undertow

use of io.undertow.Undertow in project core by weld.

the class UndertowSmokeTest method testUndertow.

@Test
public void testUndertow() throws ServletException, InterruptedException {
    DeploymentInfo servletBuilder = Servlets.deployment().setClassLoader(UndertowSmokeTest.class.getClassLoader()).setResourceManager(new ClassPathResourceManager(UndertowSmokeTest.class.getClassLoader())).setContextPath("/").setDeploymentName("test.war").addListener(Servlets.listener(Listener.class)).addServlet(Servlets.servlet(InjectedServlet.class).addMapping("/*").setLoadOnStartup(1)).addListener(Servlets.listener(InjectedListener.class)).addFilter(Servlets.filter(InjectedFilter.class)).setEagerFilterInit(true).addInitParameter(Container.CONTEXT_PARAM_CONTAINER_CLASS, UndertowContainer.class.getName());
    DeploymentManager manager = Servlets.defaultContainer().addDeployment(servletBuilder);
    manager.deploy();
    HttpHandler servletHandler = manager.start();
    PathHandler path = Handlers.path(Handlers.redirect("/")).addPrefixPath("/", servletHandler);
    Undertow server = Undertow.builder().addHttpListener(8080, "localhost").setHandler(path).build();
    server.start();
    try {
        assertTrue(SYNC.await(5, TimeUnit.SECONDS));
    } finally {
        server.stop();
    }
}
Also used : HttpHandler(io.undertow.server.HttpHandler) DeploymentManager(io.undertow.servlet.api.DeploymentManager) PathHandler(io.undertow.server.handlers.PathHandler) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) ClassPathResourceManager(io.undertow.server.handlers.resource.ClassPathResourceManager) Undertow(io.undertow.Undertow) UndertowContainer(org.jboss.weld.environment.undertow.UndertowContainer) Test(org.junit.Test)

Aggregations

Undertow (io.undertow.Undertow)55 HttpHandler (io.undertow.server.HttpHandler)27 HttpServerExchange (io.undertow.server.HttpServerExchange)22 PathHandler (io.undertow.server.handlers.PathHandler)16 IOException (java.io.IOException)13 Test (org.junit.Test)11 ClassPathResourceManager (io.undertow.server.handlers.resource.ClassPathResourceManager)10 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)10 DeploymentManager (io.undertow.servlet.api.DeploymentManager)9 URI (java.net.URI)9 TestHttpClient (io.undertow.testutils.TestHttpClient)6 ServletException (javax.servlet.ServletException)6 HttpGet (org.apache.http.client.methods.HttpGet)6 LoadBalancingProxyClient (io.undertow.server.handlers.proxy.LoadBalancingProxyClient)5 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)5 XnioWorker (org.xnio.XnioWorker)5 PathResourceManager (io.undertow.server.handlers.resource.PathResourceManager)4 InMemorySessionManager (io.undertow.server.session.InMemorySessionManager)4 SessionAttachmentHandler (io.undertow.server.session.SessionAttachmentHandler)4 SessionCookieConfig (io.undertow.server.session.SessionCookieConfig)4