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());
}
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());
}
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()));
}
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);
}
}
}
}
Aggregations