use of io.undertow.Undertow in project tutorials by eugenp.
the class SocketServer method main.
public static void main(String[] args) {
Undertow server = Undertow.builder().addHttpListener(8080, "localhost").setHandler(path().addPrefixPath("/baeldungApp", websocket((exchange, channel) -> {
channel.getReceiveSetter().set(getListener());
channel.resumeReceives();
})).addPrefixPath("/", resource(new ClassPathResourceManager(SocketServer.class.getClassLoader(), SocketServer.class.getPackage())).addWelcomeFiles("index.html"))).build();
server.start();
}
use of io.undertow.Undertow in project adeptj-runtime by AdeptJ.
the class Server method rootHandler.
/**
* Chaining of Undertow {@link HttpHandler} instances as follows.
* <p>
* 1. GracefulShutdownHandler
* 2. RequestLimitingHandler
* 3. AllowedMethodsHandler
* 4. PredicateHandler which resolves to either RedirectHandler or SetHeadersHandler
* 5. RequestBufferingHandler if request buffering is enabled, wrapped in SetHeadersHandler
* 5. And Finally ServletInitialHandler
*
* @param servletInitialHandler the {@link io.undertow.servlet.handlers.ServletInitialHandler}
* @return GracefulShutdownHandler as the root handler
*/
private GracefulShutdownHandler rootHandler(HttpHandler servletInitialHandler) {
Config cfg = Objects.requireNonNull(this.cfgReference.get());
Map<HttpString, String> headers = new HashMap<>();
headers.put(HttpString.tryFromString(HEADER_SERVER), cfg.getString(KEY_HEADER_SERVER));
if (Environment.isDev()) {
headers.put(HttpString.tryFromString(HEADER_X_POWERED_BY), Version.getFullVersionString());
}
HttpHandler headersHandler = Boolean.getBoolean(SYS_PROP_ENABLE_REQ_BUFF) ? new SetHeadersHandler(new RequestBufferingHandler(servletInitialHandler, Integer.getInteger(SYS_PROP_REQ_BUFF_MAX_BUFFERS, cfg.getInt(KEY_REQ_BUFF_MAX_BUFFERS))), headers) : new SetHeadersHandler(servletInitialHandler, headers);
return Handlers.gracefulShutdown(new RequestLimitingHandler(Integer.getInteger(SYS_PROP_MAX_CONCUR_REQ, cfg.getInt(KEY_MAX_CONCURRENT_REQS)), new AllowedMethodsHandler(Handlers.predicate(exchange -> CONTEXT_PATH.equals(exchange.getRequestURI()), Handlers.redirect(TOOLS_DASHBOARD_URI), headersHandler), this.allowedMethods(cfg))));
}
use of io.undertow.Undertow in project ice by JBEI.
the class DevelopmentServer method main.
public static void main(String[] args) throws Exception {
DeploymentInfo servletBuilder = Servlets.deployment().setClassLoader(ClassLoader.getSystemClassLoader()).addListener(Servlets.listener(IceServletContextListener.class)).setContextPath("/").setDeploymentName("Inventory for Composable Elements").setResourceManager(new FileResourceManager(new File("src/main/webapp"), 10)).addWelcomePage("index.htm").addServlets(Servlets.servlet("Jersey REST Servlet", ServletContainer.class).addInitParam("jersey.config.server.provider.packages", "org.jbei.ice.services.rest").addInitParam("jersey.config.server.provider.scanning.recursive", "false").addInitParam("javax.ws.rs.Application", "org.jbei.ice.services.rest.multipart.IceApplication").setAsyncSupported(true).setEnabled(true).addMapping("/rest/*"));
// deploy servlet
DeploymentManager manager = Servlets.defaultContainer().addDeployment(servletBuilder);
manager.deploy();
HttpHandler servletHandler = manager.start();
PredicatesHandler handler = Handlers.predicates(PredicatedHandlersParser.parse("path-prefix('search') or " + "path-prefix('folders') or " + "path-prefix('upload') or " + "path-prefix('download') or " + "path-prefix('entry') or path-prefix('admin') and regex('/.+') -> rewrite('/')", ClassLoader.getSystemClassLoader()), servletHandler);
PathHandler path = Handlers.path(Handlers.redirect("/")).addPrefixPath("/", handler);
Undertow server = Undertow.builder().addHttpListener(8080, "localhost").setHandler(path).build();
server.start();
}
use of io.undertow.Undertow in project symja_android_library by axkr.
the class SymjaServer method main.
public static void main(final String[] args) {
try {
if (setArgs("SymjaServer", args) < 0) {
return;
}
} catch (RuntimeException rex) {
return;
}
try {
ToggleFeature.COMPILE = false;
Config.FUZZY_PARSER = true;
Config.UNPROTECT_ALLOWED = false;
Config.USE_MANIPULATE_JS = true;
Config.JAS_NO_THREADS = false;
// Config.THREAD_FACTORY =
// com.google.appengine.api.ThreadManager.currentRequestThreadFactory();
Config.MATHML_TRIG_LOWERCASE = false;
Config.MAX_AST_SIZE = 10000;
Config.MAX_OUTPUT_SIZE = 10000;
Config.MAX_BIT_LENGTH = 200000;
Config.MAX_POLYNOMIAL_DEGREE = 100;
Config.FILESYSTEM_ENABLED = false;
Config.MAX_INPUT_LEAVES = 100L;
Config.MAX_MATRIX_DIMENSION_SIZE = 100;
EvalEngine.get().setPackageMode(true);
F.initSymbols();
FuzzyParserFactory.initialize();
final APIHandler apiHandler = new APIHandler();
PathHandler path = new PathHandler().addPrefixPath("/", resource(new ClassPathResourceManager(SymjaServer.class.getClassLoader(), SymjaServer.class.getPackage())).addWelcomeFiles("indexapi.html")).addExactPath("/v1/api", apiHandler);
// https://stackoverflow.com/a/41652378/24819
String host = LOCALHOST_STRING ? "localhost" : InetAddress.getLocalHost().getHostAddress();
Undertow server = Undertow.builder().addHttpListener(PORT, host).setHandler(path).build();
server.start();
System.out.println("\n>>> JSON API server started. <<<");
System.out.println("Waiting for API calls at http://" + host + ":" + PORT + "/v1/api");
System.out.println("Example client call:");
System.out.println("http://" + host + ":" + PORT + "/v1/api?i=D(Sin(x)%2Cx)&f=latex&f=plaintext&f=sinput&appid=DEMO");
URI uri = new URI("http://" + host + ":" + PORT + "/indexapi.html");
System.out.println();
System.out.println("To test the JSON API open page: " + uri.toString() + " in your browser.");
if (TEST && Desktop.isDesktopSupported()) {
Desktop.getDesktop().browse(uri);
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
use of io.undertow.Undertow 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();
}
}
Aggregations