use of io.undertow.server.handlers.resource.ClassPathResourceManager in project nutzboot by nutzam.
the class UndertowStarter method init.
public void init() throws Exception {
String contextPath = getContextPath();
deployment = Servlets.deployment().setDeploymentName("nb").setClassLoader(classLoader).setEagerFilterInit(true).setSecurityDisabled(true);
deployment.setContextPath(contextPath).setDefaultSessionTimeout(getSessionTimeout());
ComboResourceManager resourceManager = new ComboResourceManager();
for (String path : getResourcePaths()) {
if (new File(path).exists())
resourceManager.add(new FileResourceManager(new File(path), 1024));
try {
resourceManager.add(new ClassPathResourceManager(classLoader, path));
} catch (Throwable e) {
// 不合法的,就跳过吧
}
}
deployment.setResourceManager(resourceManager);
addNutzSupport();
addWebSocketSupport();
deployment.addWelcomePages("index.html", "index.htm", "index.do");
DeploymentManager manager = Servlets.defaultContainer().addDeployment(deployment);
manager.deploy();
HttpHandler servletHandler = manager.start();
PathHandler pathHandler;
if ("/".equals(contextPath)) {
pathHandler = Handlers.path(servletHandler);
} else {
pathHandler = Handlers.path(Handlers.redirect(contextPath)).addPrefixPath(contextPath, servletHandler);
}
builder.addHttpListener(getPort(), getHost()).setHandler(pathHandler);
server = builder.build();
}
use of io.undertow.server.handlers.resource.ClassPathResourceManager 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.server.handlers.resource.ClassPathResourceManager in project divolte-collector by divolte.
the class Server method createStaticResourceHandler.
private static HttpHandler createStaticResourceHandler() {
final ResourceManager staticResources = new ClassPathResourceManager(Server.class.getClassLoader(), "static");
// Cache tuning is copied from Undertow unit tests.
final ResourceManager cachedResources = new CachingResourceManager(100, 65536, new DirectBufferCache(1024, 10, 10480), staticResources, (int) Duration.ofDays(1).getSeconds());
final ResourceHandler resourceHandler = new ResourceHandler(cachedResources);
resourceHandler.setWelcomeFiles("index.html");
return resourceHandler;
}
use of io.undertow.server.handlers.resource.ClassPathResourceManager in project adeptj-runtime by AdeptJ.
the class ServletInitialHandlerWrapper method wrap.
/**
* Wraps the passed {@link ServletInitialHandler} with a PredicateHandler for serving static content.
*
* @param servletInitialHandler the ServletInitialHandler
* @return PredicateHandler which decides whether to invoke ResourceHandler or pass on the request to
* next handler in the chain which is ServletInitialHandler.
* @see ServletInitialHandlerWrapper class header for detailed information.
*/
@Override
public HttpHandler wrap(HttpHandler servletInitialHandler) {
Config cfg = Configs.DEFAULT.undertow();
Predicate prefix = Predicates.prefix(cfg.getString(RESOURCE_PREFIX));
Predicate suffixes = Predicates.suffixes(cfg.getStringList(RESOURCE_EXTNS).toArray(new String[0]));
ClassPathResourceManager rm = new ClassPathResourceManager(this.getClass().getClassLoader(), cfg.getString(RESOURCE_MGR_PREFIX));
return Handlers.predicate(Predicates.and(prefix, suffixes), Handlers.resource(rm), servletInitialHandler);
}
use of io.undertow.server.handlers.resource.ClassPathResourceManager 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();
}
}
Aggregations