Search in sources :

Example 51 with ContextHandlerCollection

use of org.eclipse.jetty.server.handler.ContextHandlerCollection in project pulsar by yahoo.

the class WebService method start.

public void start() throws PulsarServerException {
    try {
        RequestLogHandler requestLogHandler = new RequestLogHandler();
        Slf4jRequestLog requestLog = new Slf4jRequestLog();
        requestLog.setExtended(true);
        requestLog.setLogTimeZone(WebService.HANDLER_REQUEST_LOG_TZ);
        requestLog.setLogLatency(true);
        requestLogHandler.setRequestLog(requestLog);
        handlers.add(0, new ContextHandlerCollection());
        handlers.add(requestLogHandler);
        ContextHandlerCollection contexts = new ContextHandlerCollection();
        contexts.setHandlers(handlers.toArray(new Handler[handlers.size()]));
        HandlerCollection handlerCollection = new HandlerCollection();
        handlerCollection.setHandlers(new Handler[] { contexts, new DefaultHandler(), requestLogHandler });
        server.setHandler(handlerCollection);
        server.start();
        log.info("Web Service started at {}", pulsar.getWebServiceAddress());
    } catch (Exception e) {
        throw new PulsarServerException(e);
    }
}
Also used : Slf4jRequestLog(org.eclipse.jetty.server.Slf4jRequestLog) PulsarServerException(com.yahoo.pulsar.broker.PulsarServerException) RequestLogHandler(org.eclipse.jetty.server.handler.RequestLogHandler) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) Handler(org.eclipse.jetty.server.Handler) ResourceHandler(org.eclipse.jetty.server.handler.ResourceHandler) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) RequestLogHandler(org.eclipse.jetty.server.handler.RequestLogHandler) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection) GeneralSecurityException(java.security.GeneralSecurityException) PulsarServerException(com.yahoo.pulsar.broker.PulsarServerException) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler)

Example 52 with ContextHandlerCollection

use of org.eclipse.jetty.server.handler.ContextHandlerCollection in project gitiles by GerritCodeReview.

the class DevServer method handler.

private Handler handler() throws IOException {
    ContextHandlerCollection handlers = new ContextHandlerCollection();
    handlers.addHandler(staticHandler());
    handlers.addHandler(appHandler());
    return handlers;
}
Also used : ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection)

Example 53 with ContextHandlerCollection

use of org.eclipse.jetty.server.handler.ContextHandlerCollection in project JMRI by JMRI.

the class WebServer method start.

/**
     * Start the web server.
     */
@Override
public void start() {
    if (!server.isRunning()) {
        ServerConnector connector = new ServerConnector(server);
        // 5 minutes
        connector.setIdleTimeout(5 * 60 * 1000);
        connector.setSoLingerTime(-1);
        connector.setPort(preferences.getPort());
        server.setConnectors(new Connector[] { connector });
        server.setHandler(new ContextHandlerCollection());
        // Load all path handlers
        ServiceLoader.load(WebServerConfiguration.class).forEach((configuration) -> {
            configuration.getFilePaths().entrySet().forEach((resource) -> {
                this.registerResource(resource.getKey(), resource.getValue());
            });
            configuration.getRedirectedPaths().entrySet().forEach((redirection) -> {
                this.registerRedirection(redirection.getKey(), redirection.getValue());
            });
            configuration.getForbiddenPaths().forEach((denial) -> {
                this.registerDenial(denial);
            });
        });
        // Load all classes that provide the HttpServlet service.
        ServiceLoader.load(HttpServlet.class).forEach((servlet) -> {
            this.registerServlet(servlet.getClass(), servlet);
        });
        server.addLifeCycleListener(this);
        Thread serverThread = new ServerThread(server);
        // NOI18N
        serverThread.setName("WebServer");
        serverThread.start();
    }
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) HttpServlet(javax.servlet.http.HttpServlet) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) WebServerConfiguration(jmri.server.web.spi.WebServerConfiguration)

Example 54 with ContextHandlerCollection

use of org.eclipse.jetty.server.handler.ContextHandlerCollection in project JMRI by JMRI.

the class WebServer method registerRedirection.

/**
     * Register a URL pattern to be redirected to another resource.
     *
     * @param urlPattern  the pattern to be redirected
     * @param redirection the path to which the pattern is redirected
     * @throws IllegalArgumentException if urlPattern is already registered for
     *                                  any other purpose
     */
public void registerRedirection(String urlPattern, String redirection) throws IllegalArgumentException {
    Registration registered = this.registeredUrls.get(urlPattern);
    if (registered != null && registered != Registration.REDIRECTION) {
        throw new IllegalArgumentException("\"" + urlPattern + "\" registered to " + registered);
    }
    this.registeredUrls.put(urlPattern, Registration.REDIRECTION);
    ServletContextHandler servletContext = new ServletContextHandler(ServletContextHandler.NO_SECURITY);
    servletContext.setContextPath(urlPattern);
    RedirectionServlet servlet = new RedirectionServlet(urlPattern, redirection);
    // NOI18N
    servletContext.addServlet(new ServletHolder(servlet), "");
    ((ContextHandlerCollection) this.server.getHandler()).addHandler(servletContext);
}
Also used : RedirectionServlet(jmri.web.servlet.RedirectionServlet) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Aggregations

ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)54 Server (org.eclipse.jetty.server.Server)25 HandlerCollection (org.eclipse.jetty.server.handler.HandlerCollection)21 DefaultHandler (org.eclipse.jetty.server.handler.DefaultHandler)17 RequestLogHandler (org.eclipse.jetty.server.handler.RequestLogHandler)16 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)14 ServerConnector (org.eclipse.jetty.server.ServerConnector)13 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)13 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)10 Test (org.junit.Test)10 Handler (org.eclipse.jetty.server.Handler)9 URI (java.net.URI)7 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)7 ResourceHandler (org.eclipse.jetty.server.handler.ResourceHandler)6 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)6 File (java.io.File)5 ArrayList (java.util.ArrayList)5 MBeanContainer (org.eclipse.jetty.jmx.MBeanContainer)5 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)5 HttpURLConnection (java.net.HttpURLConnection)4