use of org.mortbay.jetty.handler.HandlerList in project sonatype-aether by sonatype.
the class HttpServer method start.
/**
* Starts the server. Trying to start an already running server has no effect.
*
* @return This server, never {@code null}.
* @throws Exception If the server could not be started.
*/
public HttpServer start() throws Exception {
if (server != null) {
return this;
}
recordedRequests.clear();
List<Connector> connectors = new ArrayList<Connector>();
if (httpPort >= 0) {
connectors.add(newHttpConnector());
}
if (httpsPort >= 0 && keyStoreLocation != null) {
connectors.add(newHttpsConnector());
}
HandlerList handlerList = new HandlerList();
if (!recordedPatterns.isEmpty()) {
handlerList.addHandler(new RecordingHandler());
}
if (latency != 0) {
handlerList.addHandler(newSleepHandler(latency));
}
if (redirectToHttps) {
handlerList.addHandler(newSslRedirectHandler());
}
if (proxyUsername != null && proxyPassword != null) {
handlerList.addHandler(newProxyHandler());
}
if (!securedRealms.isEmpty()) {
handlerList.addHandler(newSecurityHandler());
}
if (!resourceDirs.isEmpty()) {
handlerList.addHandler(newResourceHandler());
}
handlerList.addHandler(new DefaultHandler());
server = new Server(0);
server.setHandler(handlerList);
server.setConnectors(connectors.toArray(new Connector[connectors.size()]));
server.start();
waitForConnectors();
addDefaultFilterTokens();
return this;
}
use of org.mortbay.jetty.handler.HandlerList 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.HandlerList 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