Search in sources :

Example 1 with ResourceHandler

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

use of org.mortbay.jetty.handler.ResourceHandler in project epadd by ePADD.

the class JettyShutdownThread method setupResources.

public static void setupResources() throws IOException {
    // deployWarAt("root.war", "/"); // for redirecting
    WebAppContext webapp0 = null;
    String path = "/epadd";
    WebAppContext webapp1 = deployWarAt("epadd.war", path);
    if (webapp1 == null) {
        System.err.println("Aborting... no webapp");
        return;
    }
    // if in any debug mode, turn blurring off
    if (debug)
        webapp1.setAttribute("noblur", true);
    // we set this and its read by JSPHelper within the webapp
    System.setProperty("muse.container", "jetty");
    // need to copy crossdomain.xml file for
    String tmp = System.getProperty("java.io.tmpdir");
    final URL url = Main.class.getClassLoader().getResource("crossdomain.xml");
    try {
        InputStream is = url.openStream();
        String file = tmp + File.separatorChar + "crossdomain.xml";
        copy_stream_to_file(is, file);
    } catch (Exception e) {
        System.err.println("Aborting..." + e);
        return;
    }
    server = new Server(PORT);
    ResourceHandler resource_handler = new ResourceHandler();
    // resource_handler.setWelcomeFiles(new String[]{ "index.html" });
    resource_handler.setResourceBase(tmp);
    // set the header buffer size in the connectors, default is a ridiculous 4K, which causes failures any time there is
    // is a large request, such as selecting a few hundred folders. (even for posts!)
    // usually there is only one SocketConnector, so we just put the setHeaderBufferSize in a loop.
    Connector[] conns = server.getConnectors();
    for (Connector conn : conns) {
        int NEW_BUFSIZE = 1000000;
        // out.println ("Connector " + conn + " buffer size is " + conn.getHeaderBufferSize() + " setting to " + NEW_BUFSIZE);
        conn.setHeaderBufferSize(NEW_BUFSIZE);
    }
    BASE_URL = "http://localhost:" + PORT + path;
    // for quick check of existing muse or successful start up. BASE_URL may take some time to run and may not always be available now that we set dirAllowed to false and public mode does not serve /muse.
    MUSE_CHECK_URL = BASE_URL + "/js/muse.js";
    debugFile = tmp + File.separatorChar + "debug.txt";
    HandlerList hl = new HandlerList();
    if (webapp0 != null)
        hl.setHandlers(new Handler[] { webapp1, webapp0, resource_handler });
    else
        hl.setHandlers(new Handler[] { webapp1, resource_handler });
    server.setHandler(hl);
}
Also used : HandlerList(org.mortbay.jetty.handler.HandlerList) Connector(org.mortbay.jetty.Connector) Server(org.mortbay.jetty.Server) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) Handler(org.mortbay.jetty.Handler) ResourceHandler(org.mortbay.jetty.handler.ResourceHandler) CookieHandler(java.net.CookieHandler) ResourceHandler(org.mortbay.jetty.handler.ResourceHandler) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) AWTException(java.awt.AWTException) BindException(java.net.BindException) ConnectException(java.net.ConnectException) MalformedURLException(java.net.MalformedURLException) UnsupportedOperatingSystemException(edu.stanford.ejalbert.exception.UnsupportedOperatingSystemException) IOException(java.io.IOException) BrowserLaunchingInitializingException(edu.stanford.ejalbert.exception.BrowserLaunchingInitializingException) WebAppContext(org.mortbay.jetty.webapp.WebAppContext)

Example 3 with ResourceHandler

use of org.mortbay.jetty.handler.ResourceHandler in project testcontainers-java by testcontainers.

the class LocalServerWebDriverContainerTest method setupLocalServer.

@Before
public void setupLocalServer() throws Exception {
    // Set up a local Jetty HTTP server
    Server server = new Server();
    server.addConnector(new SocketConnector());
    ResourceHandler resourceHandler = new ResourceHandler();
    resourceHandler.setResourceBase("src/test/resources/server");
    server.addHandler(resourceHandler);
    server.start();
    // The server will have a random port assigned, so capture that
    localPort = server.getConnectors()[0].getLocalPort();
}
Also used : Server(org.mortbay.jetty.Server) ResourceHandler(org.mortbay.jetty.handler.ResourceHandler) SocketConnector(org.mortbay.jetty.bio.SocketConnector)

Example 4 with ResourceHandler

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

use of org.mortbay.jetty.handler.ResourceHandler in project aws-doc-sdk-examples by awsdocs.

the class PersonalizeDemoOnMovieLens20M method runWebDemo.

private static void runWebDemo(PersonalizeRuntimeClient personalizeRuntimeClient, PersonalizeEventsClient personalizeEventsClient, String userPersonalizationCampaignArn, String simsCampaignArn, String eventTrackingId, DatasetProvider datasetProvider) throws Exception {
    RecommendationsInterface recommender = new AmazonPersonalizeRecommender(personalizeRuntimeClient, personalizeEventsClient, userPersonalizationCampaignArn, simsCampaignArn, eventTrackingId, datasetProvider);
    Server server = new Server();
    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(8080);
    server.addConnector(connector);
    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setWelcomeFiles(new String[] { "homepage.html" });
    resource_handler.setResourceBase("static/web/");
    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] { resource_handler, new WebHandler(recommender) });
    server.setHandler(handlers);
    server.start();
    if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
        Desktop.getDesktop().browse(new URI("http://localhost:8080"));
    }
    server.join();
}
Also used : HandlerList(org.mortbay.jetty.handler.HandlerList) SelectChannelConnector(org.mortbay.jetty.nio.SelectChannelConnector) Server(org.mortbay.jetty.Server) ResourceHandler(org.mortbay.jetty.handler.ResourceHandler) URI(java.net.URI)

Aggregations

Server (org.mortbay.jetty.Server)7 ResourceHandler (org.mortbay.jetty.handler.ResourceHandler)7 HandlerList (org.mortbay.jetty.handler.HandlerList)5 SocketConnector (org.mortbay.jetty.bio.SocketConnector)3 SelectChannelConnector (org.mortbay.jetty.nio.SelectChannelConnector)3 IOException (java.io.IOException)2 URI (java.net.URI)2 URL (java.net.URL)2 Connector (org.mortbay.jetty.Connector)2 DefaultHandler (org.mortbay.jetty.handler.DefaultHandler)2 BrowserLaunchingInitializingException (edu.stanford.ejalbert.exception.BrowserLaunchingInitializingException)1 UnsupportedOperatingSystemException (edu.stanford.ejalbert.exception.UnsupportedOperatingSystemException)1 AWTException (java.awt.AWTException)1 BufferedInputStream (java.io.BufferedInputStream)1 InputStream (java.io.InputStream)1 BindException (java.net.BindException)1 ConnectException (java.net.ConnectException)1 CookieHandler (java.net.CookieHandler)1 MalformedURLException (java.net.MalformedURLException)1 ServerSocket (java.net.ServerSocket)1