Search in sources :

Example 1 with ClassPathResourceManager

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();
}
Also used : HttpHandler(io.undertow.server.HttpHandler) FileResourceManager(io.undertow.server.handlers.resource.FileResourceManager) DeploymentManager(io.undertow.servlet.api.DeploymentManager) PathHandler(io.undertow.server.handlers.PathHandler) ClassPathResourceManager(io.undertow.server.handlers.resource.ClassPathResourceManager) File(java.io.File)

Example 2 with ClassPathResourceManager

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();
}
Also used : ClassPathResourceManager(io.undertow.server.handlers.resource.ClassPathResourceManager) Undertow(io.undertow.Undertow)

Example 3 with ClassPathResourceManager

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;
}
Also used : DirectBufferCache(io.undertow.server.handlers.cache.DirectBufferCache) CachingResourceManager(io.undertow.server.handlers.resource.CachingResourceManager) ResourceHandler(io.undertow.server.handlers.resource.ResourceHandler) ClassPathResourceManager(io.undertow.server.handlers.resource.ClassPathResourceManager) ResourceManager(io.undertow.server.handlers.resource.ResourceManager) CachingResourceManager(io.undertow.server.handlers.resource.CachingResourceManager) ClassPathResourceManager(io.undertow.server.handlers.resource.ClassPathResourceManager)

Example 4 with ClassPathResourceManager

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);
}
Also used : Config(com.typesafe.config.Config) ClassPathResourceManager(io.undertow.server.handlers.resource.ClassPathResourceManager) Predicate(io.undertow.predicate.Predicate)

Example 5 with ClassPathResourceManager

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();
    }
}
Also used : PathHandler(io.undertow.server.handlers.PathHandler) HttpString(io.undertow.util.HttpString) ClassPathResourceManager(io.undertow.server.handlers.resource.ClassPathResourceManager) URI(java.net.URI) Undertow(io.undertow.Undertow) ReturnException(org.matheclipse.core.eval.exception.ReturnException)

Aggregations

ClassPathResourceManager (io.undertow.server.handlers.resource.ClassPathResourceManager)13 Undertow (io.undertow.Undertow)10 PathHandler (io.undertow.server.handlers.PathHandler)5 HttpHandler (io.undertow.server.HttpHandler)4 DeploymentManager (io.undertow.servlet.api.DeploymentManager)4 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)3 WebSocketConnectionCallback (io.undertow.websockets.WebSocketConnectionCallback)3 AbstractReceiveListener (io.undertow.websockets.core.AbstractReceiveListener)3 BufferedTextMessage (io.undertow.websockets.core.BufferedTextMessage)3 WebSocketChannel (io.undertow.websockets.core.WebSocketChannel)3 WebSocketHttpExchange (io.undertow.websockets.spi.WebSocketHttpExchange)3 URI (java.net.URI)2 ReturnException (org.matheclipse.core.eval.exception.ReturnException)2 ConfigureListener (com.sun.faces.config.ConfigureListener)1 Config (com.typesafe.config.Config)1 Predicate (io.undertow.predicate.Predicate)1 DefaultByteBufferPool (io.undertow.server.DefaultByteBufferPool)1 HttpServerExchange (io.undertow.server.HttpServerExchange)1 DirectBufferCache (io.undertow.server.handlers.cache.DirectBufferCache)1 CachingResourceManager (io.undertow.server.handlers.resource.CachingResourceManager)1