Search in sources :

Example 1 with RequestLogHandler

use of org.mortbay.jetty.handler.RequestLogHandler in project commons by twitter.

the class JettyHttpServerDispatch method listen.

@Override
public synchronized boolean listen(int minPort, int maxPort) {
    boolean state = !isStarted();
    Preconditions.checkState(state, "HttpServerDispatch has already been started on port: %d", port);
    Connector connector = openConnector(minPort, maxPort);
    // Couldn't open a server port.
    if (connector == null)
        return false;
    port = connector.getLocalPort();
    server = new Server();
    server.addConnector(connector);
    context = new Context(server, "/", Context.NO_SESSIONS);
    if (requestLog.isPresent()) {
        RequestLogHandler logHandler = new RequestLogHandler();
        logHandler.setRequestLog(requestLog.get());
        context.addHandler(logHandler);
    }
    context.addServlet(new ServletHolder(new RootHandler()), "/");
    try {
        server.start();
        LOG.info("HTTP server is listening on port " + port);
        return true;
    } catch (Exception e) {
        LOG.log(Level.SEVERE, "HTTP server failed to start on port " + connector.getLocalPort(), e);
        return false;
    }
}
Also used : Context(org.mortbay.jetty.servlet.Context) Connector(org.mortbay.jetty.Connector) SelectChannelConnector(org.mortbay.jetty.nio.SelectChannelConnector) AbstractConnector(org.mortbay.jetty.AbstractConnector) Server(org.mortbay.jetty.Server) RequestLogHandler(org.mortbay.jetty.handler.RequestLogHandler) ServletHolder(org.mortbay.jetty.servlet.ServletHolder) IOException(java.io.IOException)

Example 2 with RequestLogHandler

use of org.mortbay.jetty.handler.RequestLogHandler in project gradle by gradle.

the class Jetty6PluginServer method configureHandlers.

/**
     * Set up the handler structure to receive a webapp. Also put in a DefaultHandler so we get a nice page than a 404
     * if we hit the root and the webapp's context isn't at root.
     */
public void configureHandlers() throws Exception {
    this.defaultHandler = new DefaultHandler();
    this.requestLogHandler = new RequestLogHandler();
    if (this.requestLog != null) {
        this.requestLogHandler.setRequestLog(this.requestLog);
    }
    this.contexts = (ContextHandlerCollection) server.getChildHandlerByClass(ContextHandlerCollection.class);
    if (this.contexts == null) {
        this.contexts = new ContextHandlerCollection();
        this.handlers = (HandlerCollection) server.getChildHandlerByClass(HandlerCollection.class);
        if (this.handlers == null) {
            this.handlers = new HandlerCollection();
            this.server.setHandler(handlers);
            this.handlers.setHandlers(new Handler[] { this.contexts, this.defaultHandler, this.requestLogHandler });
        } else {
            this.handlers.addHandler(this.contexts);
        }
    }
}
Also used : RequestLogHandler(org.mortbay.jetty.handler.RequestLogHandler) ContextHandlerCollection(org.mortbay.jetty.handler.ContextHandlerCollection) HandlerCollection(org.mortbay.jetty.handler.HandlerCollection) ContextHandlerCollection(org.mortbay.jetty.handler.ContextHandlerCollection) DefaultHandler(org.mortbay.jetty.handler.DefaultHandler)

Aggregations

RequestLogHandler (org.mortbay.jetty.handler.RequestLogHandler)2 IOException (java.io.IOException)1 AbstractConnector (org.mortbay.jetty.AbstractConnector)1 Connector (org.mortbay.jetty.Connector)1 Server (org.mortbay.jetty.Server)1 ContextHandlerCollection (org.mortbay.jetty.handler.ContextHandlerCollection)1 DefaultHandler (org.mortbay.jetty.handler.DefaultHandler)1 HandlerCollection (org.mortbay.jetty.handler.HandlerCollection)1 SelectChannelConnector (org.mortbay.jetty.nio.SelectChannelConnector)1 Context (org.mortbay.jetty.servlet.Context)1 ServletHolder (org.mortbay.jetty.servlet.ServletHolder)1