use of io.undertow.server.handlers.resource.ClassPathResourceManager in project symja_android_library by axkr.
the class ServletServer method runServer.
/**
* @param deploymentName the <code>*.war</code> deployment name.
* @param classLoader the current class loader
* @param ajaxServlet the name of the AJAX servlet class
* @param port typical port <code>8080</code>
* @param welcomeFile TODO
*/
protected static void runServer(String deploymentName, ClassLoader classLoader, Class<? extends Servlet> ajaxServlet, int port, String welcomeFile) {
try {
// https://stackoverflow.com/a/41652378/24819
String host = LOCALHOST_STRING ? "localhost" : InetAddress.getLocalHost().getHostAddress();
DeploymentInfo servletBuilder = deployment().setClassLoader(classLoader).setContextPath(MMAServletServer.MYAPP).setDeploymentName(deploymentName).addServlets(servlet("query", ajaxServlet).setLoadOnStartup(1).addMapping("/query/"), servlet("doc", AJAXDocServlet.class).addMapping("/doc/*"), servlet("search", AJAXSearchServlet.class).addMapping("/doc/search/"));
DeploymentManager manager = defaultContainer().addDeployment(servletBuilder);
manager.deploy();
HttpHandler servletHandler = manager.start();
PathHandler path = // Handlers.redirect(MYAPP)
Handlers.path().addPrefixPath("/ajax", servletHandler).addPrefixPath("/", resource(new ClassPathResourceManager(classLoader, "public/")).addWelcomeFiles(welcomeFile));
Undertow server = Undertow.builder().addHttpListener(port, host).setHandler(path).build();
server.start();
URI uri = new URI("http://" + host + ":" + port + "/" + welcomeFile);
if (Desktop.isDesktopSupported()) {
Desktop.getDesktop().browse(uri);
}
LOGGER.info("Open browser URL: {}", uri);
} catch (Exception ex) {
ex.printStackTrace();
}
}
use of io.undertow.server.handlers.resource.ClassPathResourceManager in project undertow by undertow-io.
the class WebSocketServer method main.
public static void main(final String[] args) {
Undertow server = Undertow.builder().addHttpListener(8080, "localhost").setHandler(path().addPrefixPath("/myapp", websocket(new WebSocketConnectionCallback() {
@Override
public void onConnect(WebSocketHttpExchange exchange, WebSocketChannel channel) {
channel.getReceiveSetter().set(new AbstractReceiveListener() {
@Override
protected void onFullTextMessage(WebSocketChannel channel, BufferedTextMessage message) {
WebSockets.sendText(message.getData(), channel, null);
}
});
channel.resumeReceives();
}
})).addPrefixPath("/", resource(new ClassPathResourceManager(WebSocketServer.class.getClassLoader(), WebSocketServer.class.getPackage())).addWelcomeFiles("index.html"))).build();
server.start();
}
use of io.undertow.server.handlers.resource.ClassPathResourceManager in project undertow by undertow-io.
the class JSRWebSocketServer method main.
public static void main(final String[] args) {
PathHandler path = Handlers.path();
Undertow server = Undertow.builder().addHttpListener(8080, "localhost").setHandler(path).build();
server.start();
final ServletContainer container = ServletContainer.Factory.newInstance();
DeploymentInfo builder = new DeploymentInfo().setClassLoader(JSRWebSocketServer.class.getClassLoader()).setContextPath("/").addWelcomePage("index.html").setResourceManager(new ClassPathResourceManager(JSRWebSocketServer.class.getClassLoader(), JSRWebSocketServer.class.getPackage())).addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, new WebSocketDeploymentInfo().setBuffers(new DefaultByteBufferPool(true, 100)).addEndpoint(JsrChatWebSocketEndpoint.class)).setDeploymentName("chat.war");
DeploymentManager manager = container.addDeployment(builder);
manager.deploy();
try {
path.addPrefixPath("/", manager.start());
} catch (ServletException e) {
throw new RuntimeException(e);
}
}
use of io.undertow.server.handlers.resource.ClassPathResourceManager 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();
}
}
use of io.undertow.server.handlers.resource.ClassPathResourceManager in project joinfaces by joinfaces.
the class UndertowAutoConfiguration method jsfUndertowFactoryCustomizer.
@Bean
public WebServerFactoryCustomizer<UndertowServletWebServerFactory> jsfUndertowFactoryCustomizer() {
return factory -> factory.addDeploymentInfoCustomizers(deploymentInfo -> {
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
ClassLoader jsfClassLoader = new URLClassLoader(new URL[0], this.getClass().getClassLoader());
deploymentInfo.setClassLoader(jsfClassLoader);
deploymentInfo.setResourceManager(new ClassPathResourceManager(jsfClassLoader, this.undertowProperties.getClassPathResource()));
return null;
});
log.info("Setting Undertow classLoader to {} directory", this.undertowProperties.getClassPathResource());
});
}
Aggregations