Search in sources :

Example 16 with ContextHandlerCollection

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

the class JettyHttpServer method createContext.

@Override
public HttpContext createContext(String path, HttpHandler httpHandler) {
    checkIfContextIsFree(path);
    JettyHttpContext context = new JettyHttpContext(this, path, httpHandler);
    HttpSpiContextHandler jettyContextHandler = context.getJettyContextHandler();
    ContextHandlerCollection chc = findContextHandlerCollection(_server.getHandlers());
    if (chc == null)
        throw new RuntimeException("could not find ContextHandlerCollection, you must configure one");
    chc.addHandler(jettyContextHandler);
    _contexts.put(path, context);
    return context;
}
Also used : ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection)

Example 17 with ContextHandlerCollection

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

the class JettyHttpServer method findContextHandlerCollection.

private ContextHandlerCollection findContextHandlerCollection(Handler[] handlers) {
    if (handlers == null)
        return null;
    for (Handler handler : handlers) {
        if (handler instanceof ContextHandlerCollection) {
            return (ContextHandlerCollection) handler;
        }
        if (handler instanceof HandlerCollection) {
            HandlerCollection hc = (HandlerCollection) handler;
            ContextHandlerCollection chc = findContextHandlerCollection(hc.getHandlers());
            if (chc != null)
                return chc;
        }
    }
    return null;
}
Also used : Handler(org.eclipse.jetty.server.Handler) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) HttpHandler(com.sun.net.httpserver.HttpHandler) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection)

Example 18 with ContextHandlerCollection

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

the class JettyHttpServerProvider method createHttpServer.

@Override
public HttpServer createHttpServer(InetSocketAddress addr, int backlog) throws IOException {
    Server server = _server;
    boolean shared = true;
    if (server == null) {
        ThreadPool threadPool = new DelegatingThreadPool(new QueuedThreadPool());
        server = new Server(threadPool);
        HandlerCollection handlerCollection = new HandlerCollection();
        handlerCollection.setHandlers(new Handler[] { new ContextHandlerCollection(), new DefaultHandler() });
        server.setHandler(handlerCollection);
        shared = false;
    }
    JettyHttpServer jettyHttpServer = new JettyHttpServer(server, shared);
    jettyHttpServer.bind(addr, backlog);
    return jettyHttpServer;
}
Also used : HttpServer(com.sun.net.httpserver.HttpServer) HttpsServer(com.sun.net.httpserver.HttpsServer) Server(org.eclipse.jetty.server.Server) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) ThreadPool(org.eclipse.jetty.util.thread.ThreadPool) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler)

Example 19 with ContextHandlerCollection

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

the class WebSocketPlugin method destroyPlugin.

@Override
public void destroyPlugin() {
    // terminate any active websocket sessions
    SessionManager sm = XMPPServer.getInstance().getSessionManager();
    for (ClientSession session : sm.getSessions()) {
        if (session instanceof LocalSession) {
            Object ws = ((LocalSession) session).getSessionData("ws");
            if (ws != null && (Boolean) ws) {
                session.close();
            }
        }
    }
    ContextHandlerCollection contexts = HttpBindManager.getInstance().getContexts();
    contexts.removeHandler(contextHandler);
    contextHandler = null;
    pluginClassLoader = null;
}
Also used : SessionManager(org.jivesoftware.openfire.SessionManager) ClientSession(org.jivesoftware.openfire.session.ClientSession) LocalSession(org.jivesoftware.openfire.session.LocalSession) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection)

Example 20 with ContextHandlerCollection

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

the class WebSocketPlugin method initializePlugin.

@Override
public void initializePlugin(final PluginManager manager, final File pluginDirectory) {
    if (Boolean.valueOf(JiveGlobals.getBooleanProperty(HttpBindManager.HTTP_BIND_ENABLED, true))) {
        Log.info(String.format("Initializing websocket plugin"));
        try {
            ContextHandlerCollection contexts = HttpBindManager.getInstance().getContexts();
            contextHandler = new ServletContextHandler(contexts, "/ws", ServletContextHandler.SESSIONS);
            contextHandler.addServlet(new ServletHolder(this), "/*");
        } catch (Exception e) {
            Log.error("Failed to start websocket plugin", e);
        }
    } else {
        Log.warn("Failed to start websocket plugin; http-bind is disabled");
    }
}
Also used : 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