Search in sources :

Example 96 with Handler

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

the class JettyHTTPServerEngine method removeServant.

/**
 * Remove a previously registered servant.
 *
 * @param url the URL the servant was registered against.
 */
public synchronized void removeServant(URL url) {
    final String contextName = HttpUriMapper.getContextName(url.getPath());
    final String smap = HttpUriMapper.getResourceBase(url.getPath());
    boolean found = false;
    if (server != null && server.isRunning()) {
        for (Handler handler : contexts.getChildHandlersByClass(ContextHandler.class)) {
            if (handler instanceof ContextHandler) {
                ContextHandler contextHandler = (ContextHandler) handler;
                Handler jh = contextHandler.getHandler();
                if (jh instanceof JettyHTTPHandler && (contextName.equals(contextHandler.getContextPath()) || (StringUtils.isEmpty(contextName) && "/".equals(contextHandler.getContextPath()))) && ((JettyHTTPHandler) jh).getName().equals(smap)) {
                    try {
                        contexts.removeHandler(handler);
                        handler.stop();
                        handler.destroy();
                    } catch (Exception ex) {
                        LOG.log(Level.WARNING, "REMOVE_HANDLER_FAILED_MSG", new Object[] { ex.getMessage() });
                    }
                    found = true;
                    break;
                }
            }
        }
    }
    if (!found) {
        LOG.log(Level.WARNING, "CAN_NOT_FIND_HANDLER_MSG", new Object[] { url });
    }
    registedPaths.remove(url.getPath());
    --servantCount;
}
Also used : ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler) ErrorHandler(org.eclipse.jetty.server.handler.ErrorHandler) SecurityHandler(org.eclipse.jetty.security.SecurityHandler) Handler(org.eclipse.jetty.server.Handler) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) SessionHandler(org.eclipse.jetty.server.session.SessionHandler) ServletException(javax.servlet.ServletException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException)

Example 97 with Handler

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

the class JettyHTTPServerEngine method getContextHandler.

/**
 * Get a registered context handler.
 *
 * @param url the associated URL
 * @return the HttpHandler if registered
 */
public synchronized ContextHandler getContextHandler(URL url) {
    String contextName = HttpUriMapper.getContextName(url.getPath());
    ContextHandler ret = null;
    // operation should return null.
    if (server != null) {
        for (Handler handler : server.getChildHandlersByClass(ContextHandler.class)) {
            if (handler instanceof ContextHandler) {
                ContextHandler contextHandler = (ContextHandler) handler;
                if (contextName.equals(contextHandler.getContextPath())) {
                    ret = contextHandler;
                    break;
                }
            }
        }
    }
    return ret;
}
Also used : ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler) ErrorHandler(org.eclipse.jetty.server.handler.ErrorHandler) SecurityHandler(org.eclipse.jetty.security.SecurityHandler) Handler(org.eclipse.jetty.server.Handler) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) SessionHandler(org.eclipse.jetty.server.session.SessionHandler)

Example 98 with Handler

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

the class JettyHTTPServerEngine method getServant.

/**
 * Get a registered servant.
 *
 * @param url the associated URL
 * @return the HttpHandler if registered
 */
public synchronized Handler getServant(URL url) {
    String contextName = HttpUriMapper.getContextName(url.getPath());
    // final String smap = HttpUriMapper.getResourceBase(url.getPath());
    Handler ret = null;
    // operation should return null.
    if (server != null) {
        for (Handler handler : server.getChildHandlersByClass(ContextHandler.class)) {
            if (handler instanceof ContextHandler) {
                ContextHandler contextHandler = (ContextHandler) handler;
                if (contextName.equals(contextHandler.getContextPath())) {
                    ret = contextHandler.getHandler();
                    break;
                }
            }
        }
    }
    return ret;
}
Also used : ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler) ErrorHandler(org.eclipse.jetty.server.handler.ErrorHandler) SecurityHandler(org.eclipse.jetty.security.SecurityHandler) Handler(org.eclipse.jetty.server.Handler) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) SessionHandler(org.eclipse.jetty.server.session.SessionHandler)

Example 99 with Handler

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

the class JettyHTTPServerEngineTest method testSetHandlers.

@Test
public void testSetHandlers() throws Exception {
    URL url = new URL("http://localhost:" + PORT2 + "/hello/test");
    JettyHTTPTestHandler handler1 = new JettyHTTPTestHandler("string1", true);
    JettyHTTPTestHandler handler2 = new JettyHTTPTestHandler("string2", true);
    JettyHTTPServerEngine engine = new JettyHTTPServerEngine();
    engine.setPort(PORT2);
    List<Handler> handlers = new ArrayList<>();
    handlers.add(handler1);
    engine.setHandlers(handlers);
    engine.finalizeConfig();
    engine.addServant(url, handler2);
    String response = getResponse(url.toString());
    assertEquals("the jetty http handler1 did not take effect", response, "string1string2");
    engine.stop();
    JettyHTTPServerEngineFactory.destroyForPort(PORT2);
}
Also used : ArrayList(java.util.ArrayList) Handler(org.eclipse.jetty.server.Handler) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) URL(java.net.URL) Test(org.junit.Test)

Example 100 with Handler

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

the class EngineLifecycleTest method testUpDownWithServlets.

@Test
public void testUpDownWithServlets() throws Exception {
    setUpBus();
    Bus bus = (Bus) applicationContext.getBean("cxf");
    ServerRegistry sr = bus.getExtension(ServerRegistry.class);
    ServerImpl si = (ServerImpl) sr.getServers().get(0);
    JettyHTTPDestination jhd = (JettyHTTPDestination) si.getDestination();
    JettyHTTPServerEngine e = (JettyHTTPServerEngine) jhd.getEngine();
    org.eclipse.jetty.server.Server jettyServer = e.getServer();
    for (Handler h : jettyServer.getChildHandlersByClass(WebAppContext.class)) {
        WebAppContext wac = (WebAppContext) h;
        if ("/jsunit".equals(wac.getContextPath())) {
            wac.addServlet("org.eclipse.jetty.servlet.DefaultServlet", "/bloop");
            break;
        }
    }
    try {
        verifyStaticHtml();
        invokeService();
    } finally {
        shutdownService();
    }
}
Also used : Bus(org.apache.cxf.Bus) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) ServerImpl(org.apache.cxf.endpoint.ServerImpl) JettyHTTPServerEngine(org.apache.cxf.transport.http_jetty.JettyHTTPServerEngine) ServerRegistry(org.apache.cxf.endpoint.ServerRegistry) Handler(org.eclipse.jetty.server.Handler) JettyHTTPDestination(org.apache.cxf.transport.http_jetty.JettyHTTPDestination) Test(org.junit.Test)

Aggregations

Handler (org.eclipse.jetty.server.Handler)119 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)37 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)37 Server (org.eclipse.jetty.server.Server)35 HandlerCollection (org.eclipse.jetty.server.handler.HandlerCollection)26 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)25 RequestLogHandler (org.eclipse.jetty.server.handler.RequestLogHandler)23 DefaultHandler (org.eclipse.jetty.server.handler.DefaultHandler)22 ArrayList (java.util.ArrayList)21 SessionHandler (org.eclipse.jetty.server.session.SessionHandler)18 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)18 IOException (java.io.IOException)15 Test (org.junit.Test)15 HttpServletResponse (javax.servlet.http.HttpServletResponse)14 ServerConnector (org.eclipse.jetty.server.ServerConnector)13 ErrorHandler (org.eclipse.jetty.server.handler.ErrorHandler)13 HttpServletRequest (javax.servlet.http.HttpServletRequest)12 Request (org.eclipse.jetty.server.Request)12 URI (java.net.URI)11 SecurityHandler (org.eclipse.jetty.security.SecurityHandler)11