Search in sources :

Example 86 with HandlerCollection

use of org.eclipse.jetty.server.handler.HandlerCollection in project cxf by apache.

the class AtomBookServer method run.

protected void run() {
    server = new org.eclipse.jetty.server.Server(Integer.parseInt(PORT));
    WebAppContext webappcontext = new WebAppContext();
    String contextPath = null;
    try {
        contextPath = getClass().getResource("/jaxrs_atom").toURI().getPath();
    } catch (URISyntaxException e1) {
        e1.printStackTrace();
    }
    webappcontext.setContextPath("/");
    webappcontext.setWar(contextPath);
    HandlerCollection handlers = new HandlerCollection();
    handlers.setHandlers(new Handler[] { webappcontext, new DefaultHandler() });
    server.setHandler(handlers);
    try {
        server.start();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection) URISyntaxException(java.net.URISyntaxException) URISyntaxException(java.net.URISyntaxException) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler)

Example 87 with HandlerCollection

use of org.eclipse.jetty.server.handler.HandlerCollection in project cxf by apache.

the class NioBookStoreServer method run.

protected void run() {
    server = new org.eclipse.jetty.server.Server(Integer.parseInt(PORT));
    WebAppContext webappcontext = new WebAppContext();
    String contextPath = null;
    try {
        contextPath = getClass().getResource("/jaxrs_nio").toURI().getPath();
    } catch (URISyntaxException e1) {
        e1.printStackTrace();
    }
    webappcontext.setContextPath("/");
    webappcontext.setWar(contextPath);
    HandlerCollection handlers = new HandlerCollection();
    handlers.setHandlers(new Handler[] { webappcontext, new DefaultHandler() });
    server.setHandler(handlers);
    try {
        server.start();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection) URISyntaxException(java.net.URISyntaxException) URISyntaxException(java.net.URISyntaxException) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler)

Example 88 with HandlerCollection

use of org.eclipse.jetty.server.handler.HandlerCollection in project camel by apache.

the class JettyHttpComponent method addJettyHandlers.

protected void addJettyHandlers(Server server, List<Handler> handlers) {
    if (handlers != null && !handlers.isEmpty()) {
        for (Handler handler : handlers) {
            if (handler instanceof HandlerWrapper) {
                // avoid setting a handler more than once
                if (!isHandlerInChain(server.getHandler(), handler)) {
                    ((HandlerWrapper) handler).setHandler(server.getHandler());
                    server.setHandler(handler);
                }
            } else {
                HandlerCollection handlerCollection = new HandlerCollection();
                handlerCollection.addHandler(server.getHandler());
                handlerCollection.addHandler(handler);
                server.setHandler(handlerCollection);
            }
        }
    }
}
Also used : ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) ErrorHandler(org.eclipse.jetty.server.handler.ErrorHandler) Handler(org.eclipse.jetty.server.Handler) SessionHandler(org.eclipse.jetty.server.session.SessionHandler) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection) HandlerWrapper(org.eclipse.jetty.server.handler.HandlerWrapper)

Example 89 with HandlerCollection

use of org.eclipse.jetty.server.handler.HandlerCollection in project core by weld.

the class EclipseWeldServletHandler method findWAC.

protected static WebAppContext findWAC(ServletContext context) {
    if (context instanceof ContextHandler.Context) {
        ContextHandler.Context sContext = (ContextHandler.Context) context;
        ContextHandler contextHandler = sContext.getContextHandler();
        Handler handler = contextHandler.getHandler();
        if (handler instanceof ServletHandler) {
            ServletHandler servletHandler = (ServletHandler) handler;
            Server server = servletHandler.getServer();
            Handler serverHandler = server.getHandler();
            if (serverHandler instanceof HandlerCollection) {
                HandlerCollection hc = (HandlerCollection) serverHandler;
                for (Handler h : hc.getHandlers()) {
                    if (h instanceof WebAppContext) {
                        WebAppContext wac = (WebAppContext) h;
                        if (wac.getServletHandler() == servletHandler) {
                            return wac;
                        }
                    }
                }
            }
        }
    }
    return null;
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) ServletContext(javax.servlet.ServletContext) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) ServletHandler(org.eclipse.jetty.servlet.ServletHandler) Server(org.eclipse.jetty.server.Server) Handler(org.eclipse.jetty.server.Handler) ServletHandler(org.eclipse.jetty.servlet.ServletHandler) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection)

Example 90 with HandlerCollection

use of org.eclipse.jetty.server.handler.HandlerCollection in project vespa by vespa-engine.

the class JettyHttpServer method getHandlerCollection.

private HandlerCollection getHandlerCollection(ServerConfig serverConfig, ServletPathsConfig servletPathsConfig, ServletHolder jdiscServlet, ComponentRegistry<ServletHolder> servletHolders, FilterHolder jDiscFilterInvokerFilter, RequestLog requestLog) {
    ServletContextHandler servletContextHandler = createServletContextHandler();
    servletHolders.allComponentsById().forEach((id, servlet) -> {
        String path = getServletPath(servletPathsConfig, id);
        servletContextHandler.addServlet(servlet, path);
        servletContextHandler.addFilter(jDiscFilterInvokerFilter, path, EnumSet.allOf(DispatcherType.class));
    });
    servletContextHandler.addServlet(jdiscServlet, "/*");
    GzipHandler gzipHandler = newGzipHandler(serverConfig);
    gzipHandler.setHandler(servletContextHandler);
    StatisticsHandler statisticsHandler = newStatisticsHandler();
    statisticsHandler.setHandler(gzipHandler);
    RequestLogHandler requestLogHandler = new RequestLogHandler();
    requestLogHandler.setRequestLog(requestLog);
    HandlerCollection handlerCollection = new HandlerCollection();
    handlerCollection.setHandlers(new Handler[] { statisticsHandler, requestLogHandler });
    return handlerCollection;
}
Also used : GzipHandler(org.eclipse.jetty.server.handler.gzip.GzipHandler) RequestLogHandler(org.eclipse.jetty.server.handler.RequestLogHandler) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) DispatcherType(javax.servlet.DispatcherType) StatisticsHandler(org.eclipse.jetty.server.handler.StatisticsHandler)

Aggregations

HandlerCollection (org.eclipse.jetty.server.handler.HandlerCollection)115 DefaultHandler (org.eclipse.jetty.server.handler.DefaultHandler)57 Server (org.eclipse.jetty.server.Server)50 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)40 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)39 ServerConnector (org.eclipse.jetty.server.ServerConnector)34 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)31 RequestLogHandler (org.eclipse.jetty.server.handler.RequestLogHandler)30 Handler (org.eclipse.jetty.server.Handler)26 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)18 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)17 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)17 URISyntaxException (java.net.URISyntaxException)16 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)16 URI (java.net.URI)14 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)13 File (java.io.File)12 IOException (java.io.IOException)11 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)11 Slf4jRequestLog (org.eclipse.jetty.server.Slf4jRequestLog)10