Search in sources :

Example 21 with Server

use of org.mortbay.jetty.Server in project nutch by apache.

the class CrawlDBTestUtil method getServer.

/**
 * Creates a new JettyServer with one static root context
 *
 * @param port
 *          port to listen to
 * @param staticContent
 *          folder where static content lives
 * @throws UnknownHostException
 */
public static Server getServer(int port, String staticContent) throws UnknownHostException {
    Server webServer = new org.mortbay.jetty.Server();
    SocketConnector listener = new SocketConnector();
    listener.setPort(port);
    listener.setHost("127.0.0.1");
    webServer.addConnector(listener);
    ContextHandler staticContext = new ContextHandler();
    staticContext.setContextPath("/");
    staticContext.setResourceBase(staticContent);
    staticContext.addHandler(new ResourceHandler());
    webServer.addHandler(staticContext);
    return webServer;
}
Also used : ContextHandler(org.mortbay.jetty.handler.ContextHandler) Server(org.mortbay.jetty.Server) ResourceHandler(org.mortbay.jetty.handler.ResourceHandler) SocketConnector(org.mortbay.jetty.bio.SocketConnector)

Example 22 with Server

use of org.mortbay.jetty.Server in project ghostdriver by detro.

the class CallbackHttpServer method start.

public void start() throws Exception {
    server = new Server(0);
    Context context = new Context(server, "/");
    addServlets(context);
    server.start();
}
Also used : Context(org.mortbay.jetty.servlet.Context) Server(org.mortbay.jetty.Server)

Example 23 with Server

use of org.mortbay.jetty.Server in project gradle by gradle.

the class JettyRun method finishConfigurationBeforeStart.

public void finishConfigurationBeforeStart() throws Exception {
    Handler[] handlers = getConfiguredContextHandlers();
    org.gradle.api.plugins.jetty.internal.JettyPluginServer plugin = getServer();
    Server server = (Server) plugin.getProxiedObject();
    HandlerCollection contexts = (HandlerCollection) server.getChildHandlerByClass(ContextHandlerCollection.class);
    if (contexts == null) {
        contexts = (HandlerCollection) server.getChildHandlerByClass(HandlerCollection.class);
    }
    for (int i = 0; (handlers != null) && (i < handlers.length); i++) {
        contexts.addHandler(handlers[i]);
    }
}
Also used : JettyPluginServer(org.gradle.api.plugins.jetty.internal.JettyPluginServer) Jetty6PluginServer(org.gradle.api.plugins.jetty.internal.Jetty6PluginServer) Server(org.mortbay.jetty.Server) JettyPluginServer(org.gradle.api.plugins.jetty.internal.JettyPluginServer) Handler(org.mortbay.jetty.Handler) ContextHandler(org.mortbay.jetty.handler.ContextHandler) HandlerCollection(org.mortbay.jetty.handler.HandlerCollection) ContextHandlerCollection(org.mortbay.jetty.handler.ContextHandlerCollection) ContextHandlerCollection(org.mortbay.jetty.handler.ContextHandlerCollection)

Example 24 with Server

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

Example 25 with Server

use of org.mortbay.jetty.Server in project eureka by Netflix.

the class MockRemoteEurekaServer method start.

public void start() throws Exception {
    server = new Server(port);
    server.setHandler(new AppsResourceHandler());
    server.start();
    port = server.getConnectors()[0].getLocalPort();
}
Also used : Server(org.mortbay.jetty.Server)

Aggregations

Server (org.mortbay.jetty.Server)37 SocketConnector (org.mortbay.jetty.bio.SocketConnector)16 WebAppContext (org.mortbay.jetty.webapp.WebAppContext)14 SelectChannelConnector (org.mortbay.jetty.nio.SelectChannelConnector)11 Context (org.mortbay.jetty.servlet.Context)10 ServletHolder (org.mortbay.jetty.servlet.ServletHolder)9 Connector (org.mortbay.jetty.Connector)8 IOException (java.io.IOException)5 DefaultHandler (org.mortbay.jetty.handler.DefaultHandler)5 Configuration (org.apache.hadoop.conf.Configuration)4 Handler (org.mortbay.jetty.Handler)4 ContextHandler (org.mortbay.jetty.handler.ContextHandler)4 HandlerList (org.mortbay.jetty.handler.HandlerList)4 ResourceHandler (org.mortbay.jetty.handler.ResourceHandler)3 SslSocketConnector (org.mortbay.jetty.security.SslSocketConnector)3 ServletHandler (org.mortbay.jetty.servlet.ServletHandler)3 ArrayList (java.util.ArrayList)2 Repository (javax.jcr.Repository)2 ServletException (javax.servlet.ServletException)2 Before (org.junit.Before)2