Search in sources :

Example 1 with ServletHolder

use of org.mortbay.jetty.servlet.ServletHolder 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 ServletHolder

use of org.mortbay.jetty.servlet.ServletHolder in project dubbo by alibaba.

the class JettyContainer method start.

public void start() {
    String serverPort = ConfigUtils.getProperty(JETTY_PORT);
    int port;
    if (serverPort == null || serverPort.length() == 0) {
        port = DEFAULT_JETTY_PORT;
    } else {
        port = Integer.parseInt(serverPort);
    }
    connector = new SelectChannelConnector();
    connector.setPort(port);
    ServletHandler handler = new ServletHandler();
    String resources = ConfigUtils.getProperty(JETTY_DIRECTORY);
    if (resources != null && resources.length() > 0) {
        FilterHolder resourceHolder = handler.addFilterWithMapping(ResourceFilter.class, "/*", Handler.DEFAULT);
        resourceHolder.setInitParameter("resources", resources);
    }
    ServletHolder pageHolder = handler.addServletWithMapping(PageServlet.class, "/*");
    pageHolder.setInitParameter("pages", ConfigUtils.getProperty(JETTY_PAGES));
    pageHolder.setInitOrder(2);
    Server server = new Server();
    server.addConnector(connector);
    server.addHandler(handler);
    try {
        server.start();
    } catch (Exception e) {
        throw new IllegalStateException("Failed to start jetty server on " + NetUtils.getLocalHost() + ":" + port + ", cause: " + e.getMessage(), e);
    }
}
Also used : SelectChannelConnector(org.mortbay.jetty.nio.SelectChannelConnector) ServletHandler(org.mortbay.jetty.servlet.ServletHandler) FilterHolder(org.mortbay.jetty.servlet.FilterHolder) Server(org.mortbay.jetty.Server) ServletHolder(org.mortbay.jetty.servlet.ServletHolder)

Example 3 with ServletHolder

use of org.mortbay.jetty.servlet.ServletHolder in project incubator-dubbo-ops by apache.

the class JettyContainer method start.

public void start() {
    String serverPort = ConfigUtils.getProperty(JETTY_PORT);
    int port;
    if (serverPort == null || serverPort.length() == 0) {
        port = DEFAULT_JETTY_PORT;
    } else {
        port = Integer.parseInt(serverPort);
    }
    connector = new SelectChannelConnector();
    connector.setPort(port);
    ServletHandler handler = new ServletHandler();
    String resources = ConfigUtils.getProperty(JETTY_DIRECTORY);
    if (resources != null && resources.length() > 0) {
        FilterHolder resourceHolder = handler.addFilterWithMapping(ResourceFilter.class, "/*", Handler.DEFAULT);
        resourceHolder.setInitParameter("resources", resources);
    }
    ServletHolder pageHolder = handler.addServletWithMapping(PageServlet.class, "/*");
    pageHolder.setInitParameter("pages", ConfigUtils.getProperty(JETTY_PAGES));
    pageHolder.setInitOrder(2);
    Server server = new Server();
    server.addConnector(connector);
    server.addHandler(handler);
    try {
        server.start();
    } catch (Exception e) {
        throw new IllegalStateException("Failed to start jetty server on " + NetUtils.getLocalHost() + ":" + port + ", cause: " + e.getMessage(), e);
    }
}
Also used : SelectChannelConnector(org.mortbay.jetty.nio.SelectChannelConnector) ServletHandler(org.mortbay.jetty.servlet.ServletHandler) FilterHolder(org.mortbay.jetty.servlet.FilterHolder) Server(org.mortbay.jetty.Server) ServletHolder(org.mortbay.jetty.servlet.ServletHolder)

Example 4 with ServletHolder

use of org.mortbay.jetty.servlet.ServletHolder in project nutch by apache.

the class TestProtocolHttp method setUp.

public void setUp(boolean redirection) throws Exception {
    conf = new Configuration();
    conf.addResource("nutch-default.xml");
    conf.addResource("nutch-site-test.xml");
    http = new Http();
    http.setConf(conf);
    server = new Server();
    if (redirection) {
        root = new Context(server, "/redirection", Context.SESSIONS);
        root.setAttribute("newContextURL", "/redirect");
    } else {
        root = new Context(server, "/", Context.SESSIONS);
    }
    ServletHolder sh = new ServletHolder(org.apache.jasper.servlet.JspServlet.class);
    root.addServlet(sh, "*.jsp");
    root.setResourceBase(RES_DIR);
}
Also used : Context(org.mortbay.jetty.servlet.Context) Configuration(org.apache.hadoop.conf.Configuration) Server(org.mortbay.jetty.Server) ServletHolder(org.mortbay.jetty.servlet.ServletHolder)

Example 5 with ServletHolder

use of org.mortbay.jetty.servlet.ServletHolder in project incubator-myriad by apache.

the class TestObjectFactory method getJettyServer.

public static Server getJettyServer() {
    Server server = new Server();
    ServletHandler context = new ServletHandler();
    ServletHolder holder = new ServletHolder(DefaultServlet.class);
    holder.setInitParameter("resourceBase", System.getProperty("user.dir"));
    holder.setInitParameter("dirAllowed", "true");
    context.setServer(server);
    context.addServlet(holder);
    server.setHandler(context);
    return server;
}
Also used : ServletHandler(org.mortbay.jetty.servlet.ServletHandler) Server(org.mortbay.jetty.Server) MyriadWebServer(org.apache.myriad.webapp.MyriadWebServer) ServletHolder(org.mortbay.jetty.servlet.ServletHolder)

Aggregations

ServletHolder (org.mortbay.jetty.servlet.ServletHolder)15 Server (org.mortbay.jetty.Server)12 Context (org.mortbay.jetty.servlet.Context)10 SelectChannelConnector (org.mortbay.jetty.nio.SelectChannelConnector)5 FilterHolder (org.mortbay.jetty.servlet.FilterHolder)4 ServletHandler (org.mortbay.jetty.servlet.ServletHandler)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 QueuedThreadPool (org.mortbay.thread.QueuedThreadPool)2 VoldemortServer (voldemort.server.VoldemortServer)2 HessianServlet (com.caucho.hessian.server.HessianServlet)1 TearDown (com.google.common.testing.TearDown)1 Method (java.lang.reflect.Method)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 ServletException (javax.servlet.ServletException)1 Configuration (org.apache.hadoop.conf.Configuration)1 MyriadWebServer (org.apache.myriad.webapp.MyriadWebServer)1 RestServlet (org.datanucleus.api.rest.RestServlet)1