use of org.mortbay.jetty.webapp.WebAppContext in project nhin-d by DirectProject.
the class ConfigServiceRunner method startConfigService.
public static synchronized void startConfigService() throws Exception {
if (server == null) {
/*
* Setup the configuration service server
*/
server = new Server();
SocketConnector connector = new SocketConnector();
HTTPPort = AvailablePortFinder.getNextAvailable(1024);
connector.setPort(HTTPPort);
WebAppContext context = new WebAppContext();
context.setContextPath("/config");
context.setServer(server);
context.setWar("war/config-service.war");
server.setSendServerVersion(false);
server.addConnector(connector);
server.addHandler(context);
server.start();
configServiceURL = "http://localhost:" + HTTPPort + "/config/ConfigurationService";
}
}
use of org.mortbay.jetty.webapp.WebAppContext in project OpenRefine by OpenRefine.
the class ShutdownSignalHandler method init.
public void init(String host, int port) throws Exception {
logger.info("Starting Server bound to '" + host + ":" + port + "'");
String memory = Configurations.get("refine.memory");
if (memory != null) {
logger.info("refine.memory size: " + memory + " JVM Max heap: " + Runtime.getRuntime().maxMemory());
}
int maxThreads = Configurations.getInteger("refine.queue.size", 30);
int maxQueue = Configurations.getInteger("refine.queue.max_size", 300);
long keepAliveTime = Configurations.getInteger("refine.queue.idle_time", 60);
LinkedBlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>(maxQueue);
threadPool = new ThreadPoolExecutor(maxThreads, maxQueue, keepAliveTime, TimeUnit.SECONDS, queue);
this.setThreadPool(new ThreadPoolExecutorAdapter(threadPool));
Connector connector = new SocketConnector();
connector.setPort(port);
connector.setHost(host);
connector.setMaxIdleTime(Configurations.getInteger("refine.connection.max_idle_time", 60000));
connector.setStatsOn(false);
this.addConnector(connector);
File webapp = new File(Configurations.get("refine.webapp", "main/webapp"));
if (!isWebapp(webapp)) {
webapp = new File("main/webapp");
if (!isWebapp(webapp)) {
webapp = new File("webapp");
if (!isWebapp(webapp)) {
logger.warn("Warning: Failed to find web application at '" + webapp.getAbsolutePath() + "'");
System.exit(-1);
}
}
}
final String contextPath = Configurations.get("refine.context_path", "/");
final int maxFormContentSize = Configurations.getInteger("refine.max_form_content_size", 1048576);
logger.info("Initializing context: '" + contextPath + "' from '" + webapp.getAbsolutePath() + "'");
WebAppContext context = new WebAppContext(webapp.getAbsolutePath(), contextPath);
context.setMaxFormContentSize(maxFormContentSize);
this.setHandler(context);
this.setStopAtShutdown(true);
this.setSendServerVersion(true);
// Enable context autoreloading
if (Configurations.getBoolean("refine.autoreload", false)) {
scanForUpdates(webapp, context);
}
// start the server
try {
this.start();
} catch (BindException e) {
logger.error("Failed to start server - is there another copy running already on this port/address?");
throw e;
}
configure(context);
}
use of org.mortbay.jetty.webapp.WebAppContext 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.webapp.WebAppContext in project roboguice by roboguice.
the class Main method main.
public static void main(String[] args) throws Exception {
Server server = new Server();
Connector connector = new SelectChannelConnector();
connector.setPort(8080);
server.setConnectors(new Connector[] { connector });
WebAppContext webapp = new WebAppContext("./root", "/example");
server.addHandler(webapp);
server.start();
server.join();
}
use of org.mortbay.jetty.webapp.WebAppContext in project exhibitor by soabase.
the class ExhibitorMain method addSecurityFile.
private void addSecurityFile(HashUserRealm realm, String securityFile, Context root) throws Exception {
// create a temp Jetty context to parse the security portion of the web.xml file
/*
TODO
This code assumes far too much internal knowledge of Jetty. I don't know
of simple way to parse the web.xml though and don't want to write it myself.
*/
final URL url = new URL("file", null, securityFile);
final WebXmlConfiguration webXmlConfiguration = new WebXmlConfiguration();
WebAppContext context = new WebAppContext();
context.setServer(server);
webXmlConfiguration.setWebAppContext(context);
ContextHandler contextHandler = new ContextHandler("/") {
@Override
protected void startContext() throws Exception {
super.startContext();
setServer(server);
webXmlConfiguration.configure(url.toString());
}
};
contextHandler.start();
try {
SecurityHandler securityHandler = webXmlConfiguration.getWebAppContext().getSecurityHandler();
if (realm != null) {
securityHandler.setUserRealm(realm);
}
root.setSecurityHandler(securityHandler);
} finally {
contextHandler.stop();
}
}
Aggregations