Search in sources :

Example 1 with HandlerList

use of org.mortbay.jetty.handler.HandlerList in project sonatype-aether by sonatype.

the class HttpServer method start.

/**
     * Starts the server. Trying to start an already running server has no effect.
     *
     * @return This server, never {@code null}.
     * @throws Exception If the server could not be started.
     */
public HttpServer start() throws Exception {
    if (server != null) {
        return this;
    }
    recordedRequests.clear();
    List<Connector> connectors = new ArrayList<Connector>();
    if (httpPort >= 0) {
        connectors.add(newHttpConnector());
    }
    if (httpsPort >= 0 && keyStoreLocation != null) {
        connectors.add(newHttpsConnector());
    }
    HandlerList handlerList = new HandlerList();
    if (!recordedPatterns.isEmpty()) {
        handlerList.addHandler(new RecordingHandler());
    }
    if (latency != 0) {
        handlerList.addHandler(newSleepHandler(latency));
    }
    if (redirectToHttps) {
        handlerList.addHandler(newSslRedirectHandler());
    }
    if (proxyUsername != null && proxyPassword != null) {
        handlerList.addHandler(newProxyHandler());
    }
    if (!securedRealms.isEmpty()) {
        handlerList.addHandler(newSecurityHandler());
    }
    if (!resourceDirs.isEmpty()) {
        handlerList.addHandler(newResourceHandler());
    }
    handlerList.addHandler(new DefaultHandler());
    server = new Server(0);
    server.setHandler(handlerList);
    server.setConnectors(connectors.toArray(new Connector[connectors.size()]));
    server.start();
    waitForConnectors();
    addDefaultFilterTokens();
    return this;
}
Also used : HandlerList(org.mortbay.jetty.handler.HandlerList) Connector(org.mortbay.jetty.Connector) SslSocketConnector(org.mortbay.jetty.security.SslSocketConnector) SelectChannelConnector(org.mortbay.jetty.nio.SelectChannelConnector) Server(org.mortbay.jetty.Server) ArrayList(java.util.ArrayList) DefaultHandler(org.mortbay.jetty.handler.DefaultHandler)

Example 2 with HandlerList

use of org.mortbay.jetty.handler.HandlerList in project CloudStack-archive by CloudStack-extras.

the class JettyVmDataServer method setupJetty.

private void setupJetty(int vmDataPort, int fileservingPort) throws Exception {
    _jetty = new Server();
    SelectChannelConnector connector0 = new SelectChannelConnector();
    connector0.setHost(_hostIp);
    connector0.setPort(fileservingPort);
    connector0.setMaxIdleTime(30000);
    connector0.setRequestBufferSize(8192);
    SelectChannelConnector connector1 = new SelectChannelConnector();
    connector1.setHost(_hostIp);
    connector1.setPort(vmDataPort);
    connector1.setThreadPool(new QueuedThreadPool(5));
    connector1.setMaxIdleTime(30000);
    connector1.setRequestBufferSize(8192);
    _jetty.setConnectors(new Connector[] { connector0, connector1 });
    Context root = new Context(_jetty, "/latest", Context.SESSIONS);
    root.setResourceBase(_vmDataDir);
    root.addServlet(new ServletHolder(new VmDataServlet(this, USER_DATA)), "/*");
    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setResourceBase("/var/lib/images/");
    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] { root, resource_handler, new DefaultHandler() });
    _jetty.setHandler(handlers);
    _jetty.start();
// _jetty.join();
}
Also used : Context(org.mortbay.jetty.servlet.Context) HandlerList(org.mortbay.jetty.handler.HandlerList) SelectChannelConnector(org.mortbay.jetty.nio.SelectChannelConnector) Server(org.mortbay.jetty.Server) QueuedThreadPool(org.mortbay.thread.QueuedThreadPool) ServletHolder(org.mortbay.jetty.servlet.ServletHolder) ResourceHandler(org.mortbay.jetty.handler.ResourceHandler) DefaultHandler(org.mortbay.jetty.handler.DefaultHandler)

Example 3 with HandlerList

use of org.mortbay.jetty.handler.HandlerList in project ambrose by twitter.

the class ScriptStatusServer method run.

/**
   * Run the server in the current thread.
   */
@Override
public void run() {
    // override newServerSocket to log local port once bound
    Connector connector = new SocketConnector() {

        @Override
        protected ServerSocket newServerSocket(String host, int port, int backlog) throws IOException {
            ServerSocket ss = super.newServerSocket(host, port, backlog);
            int localPort = ss.getLocalPort();
            LOG.info("Ambrose web server listening on port {}", localPort);
            LOG.info("Browse to http://localhost:{}/ to see job progress", localPort);
            return ss;
        }
    };
    connector.setPort(port);
    server = new Server();
    server.setConnectors(new Connector[] { connector });
    // this needs to be loaded via the jar'ed resources, not the relative dir
    String resourcePath = "com/twitter/ambrose/server/web";
    URL resourceUrl = checkNotNull(APIHandler.class.getClassLoader().getResource(resourcePath), "Failed to find resource '%s'", resourcePath);
    ResourceHandler resourceHandler = new ResourceHandler();
    resourceHandler.setWelcomeFiles(new String[] { "workflow.html" });
    resourceHandler.setResourceBase(resourceUrl.toExternalForm());
    HandlerList handler = new HandlerList();
    handler.setHandlers(new Handler[] { resourceHandler, new APIHandler(workflowIndexReadService, statsReadService), new DefaultHandler() });
    server.setHandler(handler);
    server.setStopAtShutdown(false);
    try {
        server.start();
        server.join();
    } catch (Exception e) {
        LOG.error("Error launching ScriptStatusServer", e);
    }
}
Also used : HandlerList(org.mortbay.jetty.handler.HandlerList) Connector(org.mortbay.jetty.Connector) SocketConnector(org.mortbay.jetty.bio.SocketConnector) Server(org.mortbay.jetty.Server) ServerSocket(java.net.ServerSocket) ResourceHandler(org.mortbay.jetty.handler.ResourceHandler) SocketConnector(org.mortbay.jetty.bio.SocketConnector) URL(java.net.URL) IOException(java.io.IOException) DefaultHandler(org.mortbay.jetty.handler.DefaultHandler)

Aggregations

Server (org.mortbay.jetty.Server)3 DefaultHandler (org.mortbay.jetty.handler.DefaultHandler)3 HandlerList (org.mortbay.jetty.handler.HandlerList)3 Connector (org.mortbay.jetty.Connector)2 ResourceHandler (org.mortbay.jetty.handler.ResourceHandler)2 SelectChannelConnector (org.mortbay.jetty.nio.SelectChannelConnector)2 IOException (java.io.IOException)1 ServerSocket (java.net.ServerSocket)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 SocketConnector (org.mortbay.jetty.bio.SocketConnector)1 SslSocketConnector (org.mortbay.jetty.security.SslSocketConnector)1 Context (org.mortbay.jetty.servlet.Context)1 ServletHolder (org.mortbay.jetty.servlet.ServletHolder)1 QueuedThreadPool (org.mortbay.thread.QueuedThreadPool)1