Search in sources :

Example 16 with HandlerWrapper

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

the class HandlerTest method testInsertWrapperChain.

@Test
public void testInsertWrapperChain() {
    HandlerWrapper a = new HandlerWrapper();
    HandlerWrapper b = new HandlerWrapper();
    HandlerWrapper c = new HandlerWrapper();
    HandlerWrapper d = new HandlerWrapper();
    a.insertHandler(d);
    b.insertHandler(c);
    a.insertHandler(b);
    assertThat(a.getHandler(), equalTo(b));
    assertThat(b.getHandler(), equalTo(c));
    assertThat(c.getHandler(), equalTo(d));
    assertThat(d.getHandler(), nullValue());
}
Also used : HandlerWrapper(org.eclipse.jetty.server.handler.HandlerWrapper) Test(org.junit.Test)

Example 17 with HandlerWrapper

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

the class ServletContextHandlerTest method testHandlerBeforeServletHandler.

@Test
public void testHandlerBeforeServletHandler() throws Exception {
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    HandlerWrapper extra = new HandlerWrapper();
    context.getSessionHandler().insertHandler(extra);
    context.addServlet(TestServlet.class, "/test");
    context.setContextPath("/");
    _server.setHandler(context);
    _server.start();
    StringBuffer request = new StringBuffer();
    request.append("GET /test HTTP/1.0\n");
    request.append("Host: localhost\n");
    request.append("\n");
    String response = _connector.getResponses(request.toString());
    assertResponseContains("Test", response);
    assertEquals(extra, context.getSessionHandler().getHandler());
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) HandlerWrapper(org.eclipse.jetty.server.handler.HandlerWrapper) Test(org.junit.Test)

Example 18 with HandlerWrapper

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

the class AssetsContextHandlerTest method shouldSetHeadersAndBaseDirectory.

@Test
public void shouldSetHeadersAndBaseDirectory() throws IOException {
    assertThat(handler.getContextPath(), is("/go/assets"));
    assertThat(((HandlerWrapper) handler.getHandler()).getHandler() instanceof AssetsContextHandler.AssetsHandler, is(true));
    AssetsContextHandler.AssetsHandler assetsHandler = (AssetsContextHandler.AssetsHandler) ((HandlerWrapper) handler.getHandler()).getHandler();
    ResourceHandler resourceHandler = (ResourceHandler) ReflectionUtil.getField(assetsHandler, "resourceHandler");
    assertThat(resourceHandler.getCacheControl(), is("max-age=31536000,public"));
    assertThat(resourceHandler.getResourceBase(), isSameFileAs(new File("WEB-INF/rails.root/public/assets").toURI().toString()));
}
Also used : ResourceHandler(org.eclipse.jetty.server.handler.ResourceHandler) HandlerWrapper(org.eclipse.jetty.server.handler.HandlerWrapper) File(java.io.File) Test(org.junit.Test)

Example 19 with HandlerWrapper

use of org.eclipse.jetty.server.handler.HandlerWrapper 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)

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