Search in sources :

Example 1 with DefaultHandler

use of org.mortbay.jetty.handler.DefaultHandler 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 2 with DefaultHandler

use of org.mortbay.jetty.handler.DefaultHandler in project maven-plugins by apache.

the class ProjectInfoReportUtilsTest method startJetty.

private void startJetty(boolean isSSL, boolean withAuth) throws Exception {
    jettyServer = new Server();
    jettyServer.setStopAtShutdown(true);
    Connector connector = (isSSL ? getSSLConnector() : getDefaultConnector());
    jettyServer.setConnectors(new Connector[] { connector });
    WebAppContext webapp = new WebAppContext();
    webapp.setContextPath("/");
    webapp.setResourceBase(getBasedir() + "/target/classes/");
    webapp.setServer(jettyServer);
    if (withAuth) {
        Constraint constraint = new Constraint();
        constraint.setName(Constraint.__BASIC_AUTH);
        constraint.setRoles(new String[] { "user", "admin" });
        constraint.setAuthenticate(true);
        ConstraintMapping cm = new ConstraintMapping();
        cm.setConstraint(constraint);
        cm.setPathSpec("/*");
        SecurityHandler sh = new SecurityHandler();
        sh.setUserRealm(new HashUserRealm("MyRealm", getBasedir() + "/src/test/resources/realm.properties"));
        sh.setConstraintMappings(new ConstraintMapping[] { cm });
        webapp.addHandler(sh);
    }
    DefaultHandler defaultHandler = new DefaultHandler();
    defaultHandler.setServer(jettyServer);
    Handler[] handlers = new Handler[2];
    handlers[0] = webapp;
    handlers[1] = defaultHandler;
    jettyServer.setHandlers(handlers);
    jettyServer.start();
    port = connector.getLocalPort();
}
Also used : Connector(org.mortbay.jetty.Connector) SelectChannelConnector(org.mortbay.jetty.nio.SelectChannelConnector) SslSocketConnector(org.mortbay.jetty.security.SslSocketConnector) WebAppContext(org.mortbay.jetty.webapp.WebAppContext) SecurityHandler(org.mortbay.jetty.security.SecurityHandler) ConstraintMapping(org.mortbay.jetty.security.ConstraintMapping) Server(org.mortbay.jetty.Server) Constraint(org.mortbay.jetty.security.Constraint) Handler(org.mortbay.jetty.Handler) SecurityHandler(org.mortbay.jetty.security.SecurityHandler) DefaultHandler(org.mortbay.jetty.handler.DefaultHandler) HashUserRealm(org.mortbay.jetty.security.HashUserRealm) DefaultHandler(org.mortbay.jetty.handler.DefaultHandler)

Example 3 with DefaultHandler

use of org.mortbay.jetty.handler.DefaultHandler 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 4 with DefaultHandler

use of org.mortbay.jetty.handler.DefaultHandler 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)

Example 5 with DefaultHandler

use of org.mortbay.jetty.handler.DefaultHandler 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

DefaultHandler (org.mortbay.jetty.handler.DefaultHandler)6 Server (org.mortbay.jetty.Server)5 Connector (org.mortbay.jetty.Connector)4 SelectChannelConnector (org.mortbay.jetty.nio.SelectChannelConnector)4 HandlerList (org.mortbay.jetty.handler.HandlerList)3 IOException (java.io.IOException)2 Handler (org.mortbay.jetty.Handler)2 ResourceHandler (org.mortbay.jetty.handler.ResourceHandler)2 SslSocketConnector (org.mortbay.jetty.security.SslSocketConnector)2 WebAppContext (org.mortbay.jetty.webapp.WebAppContext)2 FileNotFoundException (java.io.FileNotFoundException)1 ServerSocket (java.net.ServerSocket)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 MojoFailureException (org.apache.maven.plugin.MojoFailureException)1 SocketConnector (org.mortbay.jetty.bio.SocketConnector)1 ContextHandlerCollection (org.mortbay.jetty.handler.ContextHandlerCollection)1 HandlerCollection (org.mortbay.jetty.handler.HandlerCollection)1 RequestLogHandler (org.mortbay.jetty.handler.RequestLogHandler)1