use of org.mortbay.jetty.handler.ResourceHandler in project aws-doc-sdk-examples by awsdocs.
the class WebHandler method main.
public static void main(String[] args) throws Exception {
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(new DummyRecommender()) });
server.setHandler(handlers);
server.start();
if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
Desktop.getDesktop().browse(new URI("http://localhost:8080"));
}
server.join();
}
use of org.mortbay.jetty.handler.ResourceHandler 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);
}
}
Aggregations