Search in sources :

Example 56 with ContextHandler

use of org.eclipse.jetty.server.handler.ContextHandler in project i2p.i2p by i2p.

the class WebAppStarter method stopWebApp.

/**
 *  Stop it and remove the context.
 *  Throws just about anything, caller would be wise to catch Throwable
 *  @since public since 0.9.33, was package private
 */
public static void stopWebApp(RouterContext ctx, String appName) {
    ContextHandler wac = getWebApp(appName);
    if (wac == null)
        return;
    ctx.portMapper().unregister(appName);
    try {
        // not graceful is default in Jetty 6?
        wac.stop();
    } catch (Exception ie) {
    }
    ContextHandlerCollection server = getConsoleServer();
    if (server == null)
        return;
    try {
        server.removeHandler(wac);
        server.mapContexts();
    } catch (IllegalStateException ise) {
    }
}
Also used : ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) IOException(java.io.IOException)

Example 57 with ContextHandler

use of org.eclipse.jetty.server.handler.ContextHandler 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 58 with ContextHandler

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

the class JettyServer method createMangaBaseHandler.

private Handler createMangaBaseHandler() {
    ContextHandler contextHandler = new ContextHandler("j");
    contextHandler.setHandler(new MangaBaseHandler());
    return contextHandler;
}
Also used : ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) MangaBaseHandler(de.herrlock.manga.http.jetty.handlers.MangaBaseHandler)

Example 59 with ContextHandler

use of org.eclipse.jetty.server.handler.ContextHandler 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 60 with ContextHandler

use of org.eclipse.jetty.server.handler.ContextHandler in project activemq-artemis by apache.

the class WebServerComponent method configure.

@Override
public void configure(ComponentDTO config, String artemisInstance, String artemisHome) throws Exception {
    webServerConfig = (WebServerDTO) config;
    uri = new URI(webServerConfig.bind);
    server = new Server();
    String scheme = uri.getScheme();
    if ("https".equals(scheme)) {
        SslContextFactory sslFactory = new SslContextFactory();
        sslFactory.setKeyStorePath(webServerConfig.keyStorePath == null ? artemisInstance + "/etc/keystore.jks" : webServerConfig.keyStorePath);
        sslFactory.setKeyStorePassword(webServerConfig.getKeyStorePassword() == null ? "password" : webServerConfig.getKeyStorePassword());
        if (webServerConfig.clientAuth != null) {
            sslFactory.setNeedClientAuth(webServerConfig.clientAuth);
            if (webServerConfig.clientAuth) {
                sslFactory.setTrustStorePath(webServerConfig.trustStorePath);
                sslFactory.setTrustStorePassword(webServerConfig.getTrustStorePassword());
            }
        }
        SslConnectionFactory sslConnectionFactory = new SslConnectionFactory(sslFactory, "HTTP/1.1");
        HttpConfiguration https = new HttpConfiguration();
        https.addCustomizer(new SecureRequestCustomizer());
        HttpConnectionFactory httpFactory = new HttpConnectionFactory(https);
        connector = new ServerConnector(server, sslConnectionFactory, httpFactory);
    } else {
        connector = new ServerConnector(server);
    }
    connector.setPort(uri.getPort());
    connector.setHost(uri.getHost());
    server.setConnectors(new Connector[] { connector });
    handlers = new HandlerList();
    Path homeWarDir = Paths.get(artemisHome != null ? artemisHome : ".").resolve(webServerConfig.path).toAbsolutePath();
    Path instanceWarDir = Paths.get(artemisInstance != null ? artemisInstance : ".").resolve(webServerConfig.path).toAbsolutePath();
    if (webServerConfig.apps != null && webServerConfig.apps.size() > 0) {
        webContexts = new ArrayList<>();
        for (AppDTO app : webServerConfig.apps) {
            Path dirToUse = homeWarDir;
            if (new File(instanceWarDir.toFile().toString() + File.separator + app.war).exists()) {
                dirToUse = instanceWarDir;
            }
            WebAppContext webContext = deployWar(app.url, app.war, dirToUse);
            webContexts.add(webContext);
            if (app.war.startsWith("console")) {
                consoleUrl = webServerConfig.bind + "/" + app.url;
            }
        }
    }
    ResourceHandler homeResourceHandler = new ResourceHandler();
    homeResourceHandler.setResourceBase(homeWarDir.toString());
    homeResourceHandler.setDirectoriesListed(false);
    homeResourceHandler.setWelcomeFiles(new String[] { "index.html" });
    ContextHandler homeContext = new ContextHandler();
    homeContext.setContextPath("/");
    homeContext.setResourceBase(homeWarDir.toString());
    homeContext.setHandler(homeResourceHandler);
    homeContext.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
    ResourceHandler instanceResourceHandler = new ResourceHandler();
    instanceResourceHandler.setResourceBase(instanceWarDir.toString());
    instanceResourceHandler.setDirectoriesListed(false);
    instanceResourceHandler.setWelcomeFiles(new String[] { "index.html" });
    ContextHandler instanceContext = new ContextHandler();
    instanceContext.setContextPath("/");
    instanceContext.setResourceBase(instanceWarDir.toString());
    instanceContext.setHandler(instanceResourceHandler);
    homeContext.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
    DefaultHandler defaultHandler = new DefaultHandler();
    defaultHandler.setServeIcon(false);
    handlers.addHandler(homeContext);
    handlers.addHandler(instanceContext);
    handlers.addHandler(defaultHandler);
    server.setHandler(handlers);
}
Also used : HandlerList(org.eclipse.jetty.server.handler.HandlerList) Path(java.nio.file.Path) SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) ResourceHandler(org.eclipse.jetty.server.handler.ResourceHandler) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) URI(java.net.URI) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler) ServerConnector(org.eclipse.jetty.server.ServerConnector) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) AppDTO(org.apache.activemq.artemis.dto.AppDTO) File(java.io.File)

Aggregations

ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)127 Server (org.eclipse.jetty.server.Server)47 ServerConnector (org.eclipse.jetty.server.ServerConnector)27 URI (java.net.URI)21 ResourceHandler (org.eclipse.jetty.server.handler.ResourceHandler)20 Test (org.junit.Test)20 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)19 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)19 IOException (java.io.IOException)18 Handler (org.eclipse.jetty.server.Handler)14 HandlerCollection (org.eclipse.jetty.server.handler.HandlerCollection)14 SessionHandler (org.eclipse.jetty.server.session.SessionHandler)14 File (java.io.File)13 ServletException (javax.servlet.ServletException)13 DefaultHandler (org.eclipse.jetty.server.handler.DefaultHandler)13 BeforeClass (org.junit.BeforeClass)11 BaseIntegrationTest (com.ctrip.framework.apollo.BaseIntegrationTest)10 Config (com.ctrip.framework.apollo.Config)10 ApolloConfig (com.ctrip.framework.apollo.core.dto.ApolloConfig)10 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)10