Search in sources :

Example 16 with ResourceHandler

use of org.eclipse.jetty.server.handler.ResourceHandler in project incubator-pulsar by apache.

the class WebService method addStaticResources.

public void addStaticResources(String basePath, String resourcePath) {
    ContextHandler capHandler = new ContextHandler();
    capHandler.setContextPath(basePath);
    ResourceHandler resHandler = new ResourceHandler();
    resHandler.setBaseResource(Resource.newClassPathResource(resourcePath));
    resHandler.setEtags(true);
    resHandler.setCacheControl(WebService.HANDLER_CACHE_CONTROL);
    capHandler.setHandler(resHandler);
    handlers.add(capHandler);
}
Also used : ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) ResourceHandler(org.eclipse.jetty.server.handler.ResourceHandler)

Example 17 with ResourceHandler

use of org.eclipse.jetty.server.handler.ResourceHandler in project nifi-registry by apache.

the class JettyServer method createDocsWebApp.

private ContextHandler createDocsWebApp(final String contextPath) throws IOException {
    final ResourceHandler resourceHandler = new ResourceHandler();
    resourceHandler.setDirectoriesListed(false);
    // load the docs directory
    final File docsDir = Paths.get("docs").toRealPath().toFile();
    final Resource docsResource = Resource.newResource(docsDir);
    // load the rest documentation
    final File webApiDocsDir = new File(webApiContext.getTempDirectory(), "webapp/docs");
    if (!webApiDocsDir.exists()) {
        final boolean made = webApiDocsDir.mkdirs();
        if (!made) {
            throw new RuntimeException(webApiDocsDir.getAbsolutePath() + " could not be created");
        }
    }
    final Resource webApiDocsResource = Resource.newResource(webApiDocsDir);
    // create resources for both docs locations
    final ResourceCollection resources = new ResourceCollection(docsResource, webApiDocsResource);
    resourceHandler.setBaseResource(resources);
    // create the context handler
    final ContextHandler handler = new ContextHandler(contextPath);
    handler.setHandler(resourceHandler);
    logger.info("Loading documents web app with context path set to " + contextPath);
    return handler;
}
Also used : ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) Resource(org.eclipse.jetty.util.resource.Resource) ResourceHandler(org.eclipse.jetty.server.handler.ResourceHandler) File(java.io.File) ResourceCollection(org.eclipse.jetty.util.resource.ResourceCollection)

Example 18 with ResourceHandler

use of org.eclipse.jetty.server.handler.ResourceHandler in project Manga by herrlock.

the class JettyServer method createResourceHandler.

private Handler createResourceHandler() {
    ResourceHandler resourceHandler = new ResourceHandler();
    // load from the jetty-folder
    resourceHandler.setResourceBase("jetty");
    // enable caching via etags
    resourceHandler.setEtags(true);
    // prevent locked files
    resourceHandler.setMinMemoryMappedContentLength(-1);
    return resourceHandler;
}
Also used : ResourceHandler(org.eclipse.jetty.server.handler.ResourceHandler)

Example 19 with ResourceHandler

use of org.eclipse.jetty.server.handler.ResourceHandler in project structr by structr.

the class HttpService method collectResourceHandlers.

// ----- private methods -----
private List<ContextHandler> collectResourceHandlers() throws ClassNotFoundException, InstantiationException, IllegalAccessException {
    final List<ContextHandler> resourceHandlers = new LinkedList<>();
    final String resourceHandlerList = Settings.ResourceHandlers.getValue();
    if (resourceHandlerList != null) {
        for (String resourceHandlerName : resourceHandlerList.split("[ \\t]+")) {
            if (StringUtils.isNotBlank(resourceHandlerName)) {
                final String contextPath = Settings.getOrCreateStringSetting(resourceHandlerName, "contextPath").getValue();
                if (contextPath != null) {
                    final String resourceBase = Settings.getOrCreateStringSetting(resourceHandlerName, "resourceBase").getValue();
                    if (resourceBase != null) {
                        final ResourceHandler resourceHandler = new ResourceHandler();
                        resourceHandler.setDirectoriesListed(Settings.getBooleanSetting(resourceHandlerName, "directoriesListed").getValue());
                        final String welcomeFiles = Settings.getOrCreateStringSetting(resourceHandlerName, "welcomeFiles").getValue();
                        if (welcomeFiles != null) {
                            resourceHandler.setWelcomeFiles(StringUtils.split(welcomeFiles));
                        }
                        resourceHandler.setResourceBase(resourceBase);
                        resourceHandler.setCacheControl("max-age=0");
                        // resourceHandler.setEtags(true);
                        final ContextHandler staticResourceHandler = new ContextHandler();
                        staticResourceHandler.setContextPath(contextPath);
                        staticResourceHandler.setHandler(resourceHandler);
                        resourceHandlers.add(staticResourceHandler);
                    } else {
                        logger.warn("Unable to register resource handler {}, missing {}.resourceBase", resourceHandlerName, resourceHandlerName);
                    }
                } else {
                    logger.warn("Unable to register resource handler {}, missing {}.contextPath", resourceHandlerName, resourceHandlerName);
                }
            }
        }
    } else {
        logger.warn("No resource handlers configured for HttpService.");
    }
    return resourceHandlers;
}
Also used : ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) BasicAuthCallContextHandler(org.apache.chemistry.opencmis.server.shared.BasicAuthCallContextHandler) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) ResourceHandler(org.eclipse.jetty.server.handler.ResourceHandler) LinkedList(java.util.LinkedList)

Example 20 with ResourceHandler

use of org.eclipse.jetty.server.handler.ResourceHandler in project calcite by apache.

the class HttpServer method start.

void start() {
    if (server != null) {
        throw new RuntimeException("Server is already started");
    } else {
        QueuedThreadPool threadPool = new QueuedThreadPool();
        threadPool.setDaemon(true);
        server = new Server(threadPool);
        server.manage(threadPool);
        final ServerConnector connector = new ServerConnector(server);
        connector.setIdleTimeout(60 * 1000);
        connector.setSoLingerTime(-1);
        connector.setPort(0);
        server.setConnectors(new Connector[] { connector });
        final ResourceHandler resHandler = new ResourceHandler();
        resHandler.setResourceBase(resourceBase.getAbsolutePath());
        final HandlerList handlerList = new HandlerList();
        handlerList.setHandlers(new Handler[] { resHandler, new DefaultHandler() });
        server.setHandler(handlerList);
        try {
            server.start();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        port = connector.getLocalPort();
    }
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) HandlerList(org.eclipse.jetty.server.handler.HandlerList) Server(org.eclipse.jetty.server.Server) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) ResourceHandler(org.eclipse.jetty.server.handler.ResourceHandler) IOException(java.io.IOException) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler)

Aggregations

ResourceHandler (org.eclipse.jetty.server.handler.ResourceHandler)53 Server (org.eclipse.jetty.server.Server)31 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)20 HandlerList (org.eclipse.jetty.server.handler.HandlerList)20 DefaultHandler (org.eclipse.jetty.server.handler.DefaultHandler)16 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)15 ServerConnector (org.eclipse.jetty.server.ServerConnector)14 File (java.io.File)13 IOException (java.io.IOException)8 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)7 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)7 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)6 HashLoginService (org.eclipse.jetty.security.HashLoginService)5 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)5 Constraint (org.eclipse.jetty.util.security.Constraint)5 ConstraintMapping (org.eclipse.jetty.security.ConstraintMapping)4 ConstraintSecurityHandler (org.eclipse.jetty.security.ConstraintSecurityHandler)4 Handler (org.eclipse.jetty.server.Handler)4 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)4 Path (java.nio.file.Path)3