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();
}
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);
}
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();
}
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;
}
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();
}
Aggregations