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;
}
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;
}
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;
}
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);
}
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();
}
}
Aggregations