*/
@Test(timeout=4000)
public void testLogHandlerWrapped() throws Exception
{
Server server = new Server();
ServerConnector connector = new ServerConnector(server);
connector.setPort(0);
server.setConnectors(new Connector[] { connector });
// First the behavior as defined in etc/jetty.xml (as is)
// id="Handlers"
HandlerCollection handlers = new HandlerCollection();
// id="Contexts"
ContextHandlerCollection contexts = new ContextHandlerCollection();
// id="DefaultHandler"
DefaultHandler defaultHandler = new DefaultHandler();
handlers.setHandlers(new Handler[] { contexts, defaultHandler });
server.setHandler(handlers);
// Next the proposed behavioral change to etc/jetty-requestlog.xml
// the id="RequestLog"
RequestLogHandler requestLog = new RequestLogHandler();
CaptureLog captureLog = new CaptureLog();
requestLog.setRequestLog(captureLog);
Handler origServerHandler = server.getHandler();
requestLog.setHandler(origServerHandler);
server.setHandler(requestLog);
// Lastly, the behavior as defined by deployment of a webapp
// Add the Servlet Context
ServletContextHandler app = new ServletContextHandler(ServletContextHandler.SESSIONS);
app.setContextPath("/");
contexts.addHandler(app);
// Add the test servlet
ServletHolder testHolder = new ServletHolder(testServlet);
app.addServlet(testHolder,"/test");
app.addServlet(CustomErrorServlet.class,"/errorpage");
// Add error page mapping
ErrorPageErrorHandler errorMapper = new ErrorPageErrorHandler();
errorMapper.addErrorPage(500,"/errorpage");
app.setErrorHandler(errorMapper);
try
{
server.start();
String host = connector.getHost();
if (host == null)
{
host = "localhost";
}
int port = connector.getLocalPort();
URI serverUri = new URI("http",null,host,port,"/test",null,null);
// Make call to test handler
HttpURLConnection connection = (HttpURLConnection)serverUri.toURL().openConnection();