after the DefaultHandler.
It will never be called, as DefaultHandler is the fallback for all unhandled prior requests. :-)
Best if you setup a hierarchy for your handlers instead.
Like this ...
package jetty;
import java.io.File;
import java.net.InetSocketAddress;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.NCSARequestLog;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.handler.DefaultHandler;
import org.eclipse.jetty.server.handler.HandlerList;
import org.eclipse.jetty.server.handler.RequestLogHandler;
import org.eclipse.jetty.server.handler.ResourceHandler;
public class RequestLogging
{
public static void main(String[] args) throws Exception
{
Server server = new Server();
ServerConnector connector = new ServerConnector(server);
connector.setHost("localhost");
connector.setPort(8765);
server.addConnector(connector);
// Setup directories and file references
File userHomeDir = new File(System.getProperty("user.home"));
File tmpDir = new File(userHomeDir, "tmp");
File baseResourceDir = new File(tmpDir, "docroot");
baseResourceDir.mkdirs();
File logFile = new File(tmpDir, "access.log");
logFile.getParentFile().mkdirs();
// Create resource handler (for serving static content)
ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler.setDirectoriesListed(true);
resourceHandler.setWelcomeFiles(new String[] { "index.html" });
resourceHandler.setResourceBase(baseResourceDir.getAbsolutePath());
// Create request log handler (access log)
NCSARequestLog requestLog = new NCSARequestLog(logFile.getAbsolutePath());
requestLog.setExtended(true);
RequestLogHandler requestLogHandler = new RequestLogHandler();
requestLogHandler.setRequestLog(requestLog);
requestLog.setAppend(true);
// Create main handler list (the meat of what is being done)
HandlerList mainHandlers = new HandlerList();
mainHandlers.addHandler(resourceHandler);
// default for all prior unhandled requests
mainHandlers.addHandler(new DefaultHandler());
// Make main handler list be tracked by request logging
requestLogHandler.setHandler(mainHandlers);
// Setup top level handler list, what the server uses
HandlerList topLevelHandlers = new HandlerList();
// NOTE: If you want some handlers to exist, and not be tracked by
// the request log handler (such as rewrites), then declare them
// outside of the scop of the requestLogHandler.
// Example: baseHandler.addHandler(rewriteHandler);
topLevelHandlers.addHandler(requestLogHandler);
// Add top level handler list to server
server.setHandler(topLevelHandlers);
server.start();
server.join();
}
}