use of org.mortbay.jetty.handler.DefaultHandler 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.DefaultHandler in project maven-plugins by apache.
the class ProjectInfoReportUtilsTest method startJetty.
private void startJetty(boolean isSSL, boolean withAuth) throws Exception {
jettyServer = new Server();
jettyServer.setStopAtShutdown(true);
Connector connector = (isSSL ? getSSLConnector() : getDefaultConnector());
jettyServer.setConnectors(new Connector[] { connector });
WebAppContext webapp = new WebAppContext();
webapp.setContextPath("/");
webapp.setResourceBase(getBasedir() + "/target/classes/");
webapp.setServer(jettyServer);
if (withAuth) {
Constraint constraint = new Constraint();
constraint.setName(Constraint.__BASIC_AUTH);
constraint.setRoles(new String[] { "user", "admin" });
constraint.setAuthenticate(true);
ConstraintMapping cm = new ConstraintMapping();
cm.setConstraint(constraint);
cm.setPathSpec("/*");
SecurityHandler sh = new SecurityHandler();
sh.setUserRealm(new HashUserRealm("MyRealm", getBasedir() + "/src/test/resources/realm.properties"));
sh.setConstraintMappings(new ConstraintMapping[] { cm });
webapp.addHandler(sh);
}
DefaultHandler defaultHandler = new DefaultHandler();
defaultHandler.setServer(jettyServer);
Handler[] handlers = new Handler[2];
handlers[0] = webapp;
handlers[1] = defaultHandler;
jettyServer.setHandlers(handlers);
jettyServer.start();
port = connector.getLocalPort();
}
use of org.mortbay.jetty.handler.DefaultHandler 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.DefaultHandler in project gradle by gradle.
the class Jetty6PluginServer method configureHandlers.
/**
* Set up the handler structure to receive a webapp. Also put in a DefaultHandler so we get a nice page than a 404
* if we hit the root and the webapp's context isn't at root.
*/
public void configureHandlers() throws Exception {
this.defaultHandler = new DefaultHandler();
this.requestLogHandler = new RequestLogHandler();
if (this.requestLog != null) {
this.requestLogHandler.setRequestLog(this.requestLog);
}
this.contexts = (ContextHandlerCollection) server.getChildHandlerByClass(ContextHandlerCollection.class);
if (this.contexts == null) {
this.contexts = new ContextHandlerCollection();
this.handlers = (HandlerCollection) server.getChildHandlerByClass(HandlerCollection.class);
if (this.handlers == null) {
this.handlers = new HandlerCollection();
this.server.setHandler(handlers);
this.handlers.setHandlers(new Handler[] { this.contexts, this.defaultHandler, this.requestLogHandler });
} else {
this.handlers.addHandler(this.contexts);
}
}
}
use of org.mortbay.jetty.handler.DefaultHandler 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