Search in sources :

Example 11 with HandlerWrapper

use of org.eclipse.jetty.server.handler.HandlerWrapper in project spring-boot by spring-projects.

the class JettyServletWebServerFactoryTests method wrappedHandlers.

@Test
public void wrappedHandlers() throws Exception {
    JettyServletWebServerFactory factory = getFactory();
    factory.setServerCustomizers(Arrays.asList(new JettyServerCustomizer() {

        @Override
        public void customize(Server server) {
            Handler handler = server.getHandler();
            HandlerWrapper wrapper = new HandlerWrapper();
            wrapper.setHandler(handler);
            HandlerCollection collection = new HandlerCollection();
            collection.addHandler(wrapper);
            server.setHandler(collection);
        }
    }));
    this.webServer = factory.getWebServer(exampleServletRegistration());
    this.webServer.start();
    assertThat(getResponse(getLocalUrl("/hello"))).isEqualTo("Hello World");
}
Also used : Server(org.eclipse.jetty.server.Server) Handler(org.eclipse.jetty.server.Handler) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection) HandlerWrapper(org.eclipse.jetty.server.handler.HandlerWrapper) Test(org.junit.Test)

Example 12 with HandlerWrapper

use of org.eclipse.jetty.server.handler.HandlerWrapper in project processdash by dtuma.

the class WebServer method createServer.

private void createServer() {
    // compile JSPs using an internal compiler, not a JDK javac executable
    System.setProperty("org.apache.jasper.compiler.disablejsr199", "true");
    // create a new Jetty server
    server = new Server();
    server.setAttribute(DEFAULT_ENV_KEY, Collections.unmodifiableMap(DEFAULT_ENV));
    // the server thread pool should use daemon threads
    QueuedThreadPool threadPool = new QueuedThreadPool();
    threadPool.setName("WebServer");
    threadPool.setDaemon(true);
    server.setThreadPool(threadPool);
    // create a local connector which can be used for internal requests
    localConnector = new LocalConnector();
    server.addConnector(localConnector);
    // create a handler chain to serve requests
    webApps = new ContextHandlerCollection();
    webApps.setHandlers(new Handler[0]);
    HandlerWrapper interceptor = new DashboardHttpRequestInterceptor(startupTimestamp);
    interceptor.setHandler(webApps);
    server.setHandler(interceptor);
    // start the server
    try {
        server.start();
    } catch (Exception e) {
        logger.log(Level.SEVERE, "Could not start web server", e);
    }
}
Also used : Server(org.eclipse.jetty.server.Server) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) HandlerWrapper(org.eclipse.jetty.server.handler.HandlerWrapper) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 13 with HandlerWrapper

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

the class WebsocketComponent method createContext.

protected ServletContextHandler createContext(Server server, Connector connector, List<Handler> handlers) throws Exception {
    ServletContextHandler context = new ServletContextHandler(server, "/", ServletContextHandler.NO_SECURITY | ServletContextHandler.NO_SESSIONS);
    server.addConnector(connector);
    if (handlers != null && !handlers.isEmpty()) {
        for (Handler handler : handlers) {
            if (handler instanceof HandlerWrapper) {
                ((HandlerWrapper) handler).setHandler(server.getHandler());
                server.setHandler(handler);
            } else {
                HandlerCollection handlerCollection = new HandlerCollection();
                handlerCollection.addHandler(server.getHandler());
                handlerCollection.addHandler(handler);
                server.setHandler(handlerCollection);
            }
        }
    }
    return context;
}
Also used : ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) 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) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) HandlerWrapper(org.eclipse.jetty.server.handler.HandlerWrapper)

Example 14 with HandlerWrapper

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

the class HandlerTest method testWrapperChainLoop.

@Test
public void testWrapperChainLoop() {
    HandlerWrapper a = new HandlerWrapper();
    HandlerWrapper b = new HandlerWrapper();
    HandlerWrapper c = new HandlerWrapper();
    a.setHandler(b);
    c.setHandler(a);
    try {
        b.setHandler(c);
        fail();
    } catch (IllegalStateException e) {
        assertThat(e.getMessage(), containsString("loop"));
    }
}
Also used : HandlerWrapper(org.eclipse.jetty.server.handler.HandlerWrapper) Test(org.junit.Test)

Example 15 with HandlerWrapper

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

the class HandlerTest method testWrapperThisLoop.

@Test
public void testWrapperThisLoop() {
    HandlerWrapper a = new HandlerWrapper();
    try {
        a.setHandler(a);
        fail();
    } catch (IllegalStateException e) {
        assertThat(e.getMessage(), containsString("loop"));
    }
}
Also used : HandlerWrapper(org.eclipse.jetty.server.handler.HandlerWrapper) Test(org.junit.Test)

Aggregations

HandlerWrapper (org.eclipse.jetty.server.handler.HandlerWrapper)19 Test (org.junit.Test)14 Handler (org.eclipse.jetty.server.Handler)5 Server (org.eclipse.jetty.server.Server)5 HandlerCollection (org.eclipse.jetty.server.handler.HandlerCollection)4 IOException (java.io.IOException)3 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)3 File (java.io.File)2 ServletException (javax.servlet.ServletException)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 SessionHandler (org.eclipse.jetty.server.session.SessionHandler)2 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 UnknownHostException (java.net.UnknownHostException)1 HashMap (java.util.HashMap)1 ServletContext (javax.servlet.ServletContext)1 HttpServlet (javax.servlet.http.HttpServlet)1 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)1