use of org.eclipse.jetty.server.handler.HandlerWrapper in project jetty.project by eclipse.
the class ManyHandlers method main.
public static void main(String[] args) throws Exception {
Server server = new Server(8080);
// create the handlers
Handler param = new ParamHandler();
HandlerWrapper wrapper = new WelcomeWrapHandler();
Handler hello = new HelloHandler();
Handler dft = new DefaultHandler();
RequestLogHandler requestLog = new RequestLogHandler();
// configure request logging
File requestLogFile = File.createTempFile("demo", "log");
NCSARequestLog ncsaLog = new NCSARequestLog(requestLogFile.getAbsolutePath());
requestLog.setRequestLog(ncsaLog);
// create the handler collections
HandlerCollection handlers = new HandlerCollection();
HandlerList list = new HandlerList();
// link them all together
wrapper.setHandler(hello);
list.setHandlers(new Handler[] { param, new GzipHandler(), dft });
handlers.setHandlers(new Handler[] { list, requestLog });
// Handler tree looks like the following
// <pre>
// Server
// + HandlerCollection
// . + HandlerList
// . | + param (ParamHandler)
// . | + wrapper (WelcomeWrapHandler)
// . | | \ hello (HelloHandler)
// . | \ dft (DefaultHandler)
// . \ requestLog (RequestLogHandler)
// </pre>
server.setHandler(handlers);
server.start();
server.join();
}
use of org.eclipse.jetty.server.handler.HandlerWrapper in project jetty.project by eclipse.
the class FastCGIProxyServletTest method testURIRewrite.
@Test
public void testURIRewrite() throws Exception {
String originalPath = "/original/index.php";
String originalQuery = "foo=bar";
String remotePath = "/remote/index.php";
prepare(new HttpServlet() {
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Assert.assertThat((String) request.getAttribute(FCGI.Headers.REQUEST_URI), Matchers.startsWith(originalPath));
Assert.assertEquals(originalQuery, request.getAttribute(FCGI.Headers.QUERY_STRING));
Assert.assertThat(request.getRequestURI(), Matchers.endsWith(remotePath));
}
});
context.stop();
String pathAttribute = "_path_attribute";
String queryAttribute = "_query_attribute";
ServletHolder fcgi = context.getServletHandler().getServlet("fcgi");
fcgi.setInitParameter(FastCGIProxyServlet.ORIGINAL_URI_ATTRIBUTE_INIT_PARAM, pathAttribute);
fcgi.setInitParameter(FastCGIProxyServlet.ORIGINAL_QUERY_ATTRIBUTE_INIT_PARAM, queryAttribute);
context.insertHandler(new HandlerWrapper() {
@Override
public void handle(String target, org.eclipse.jetty.server.Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
if (target.startsWith("/remote/")) {
request.setAttribute(pathAttribute, originalPath);
request.setAttribute(queryAttribute, originalQuery);
}
super.handle(target, baseRequest, request, response);
}
});
context.start();
ContentResponse response = client.newRequest("localhost", httpConnector.getLocalPort()).path(remotePath).send();
Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
}
use of org.eclipse.jetty.server.handler.HandlerWrapper in project jetty.project by eclipse.
the class HandlerTest method testWrapperServerSet.
@Test
public void testWrapperServerSet() {
Server s = new Server();
HandlerWrapper a = new HandlerWrapper();
HandlerWrapper b = new HandlerWrapper();
HandlerWrapper c = new HandlerWrapper();
a.setServer(s);
b.setHandler(c);
a.setHandler(b);
assertThat(b.getServer(), equalTo(s));
assertThat(c.getServer(), equalTo(s));
}
use of org.eclipse.jetty.server.handler.HandlerWrapper in project jetty.project by eclipse.
the class HandlerTest method testWrapperSimpleLoop.
@Test
public void testWrapperSimpleLoop() {
HandlerWrapper a = new HandlerWrapper();
HandlerWrapper b = new HandlerWrapper();
a.setHandler(b);
try {
b.setHandler(a);
fail();
} catch (IllegalStateException e) {
assertThat(e.getMessage(), containsString("loop"));
}
}
use of org.eclipse.jetty.server.handler.HandlerWrapper in project jetty.project by eclipse.
the class HandlerTest method testWrapperSetServer.
@Test
public void testWrapperSetServer() {
Server s = new Server();
HandlerWrapper a = new HandlerWrapper();
HandlerWrapper b = new HandlerWrapper();
HandlerWrapper c = new HandlerWrapper();
a.setHandler(b);
b.setHandler(c);
a.setServer(s);
assertThat(b.getServer(), equalTo(s));
assertThat(c.getServer(), equalTo(s));
}
Aggregations