use of org.eclipse.jetty.webapp.WebAppContext in project jetty.project by eclipse.
the class GCloudSessionTester method main.
public static void main(String[] args) throws Exception {
if (args.length < 4)
System.err.println("Usage: GCloudSessionTester projectid p12file password serviceaccount");
System.setProperty("org.eclipse.jetty.server.session.LEVEL", "DEBUG");
Server server = new Server(8080);
HashLoginService loginService = new HashLoginService();
loginService.setName("Test Realm");
loginService.setConfig("../../jetty-distribution/target/distribution/demo-base/resources/realm.properties");
server.addBean(loginService);
DefaultSessionIdManager idmgr = new DefaultSessionIdManager(server);
idmgr.setWorkerName("w1");
server.setSessionIdManager(idmgr);
WebAppContext webapp = new WebAppContext();
webapp.setContextPath("/");
webapp.setWar("../../jetty-distribution/target/distribution/demo-base/webapps/test.war");
webapp.addAliasCheck(new AllowSymLinkAliasChecker());
GCloudSessionDataStore ds = new GCloudSessionDataStore();
DefaultSessionCache ss = new DefaultSessionCache(webapp.getSessionHandler());
webapp.getSessionHandler().setSessionCache(ss);
ss.setSessionDataStore(ds);
webapp.getSessionHandler().setSessionIdManager(idmgr);
// A WebAppContext is a ContextHandler as well so it needs to be set to
// the server so it is aware of where to send the appropriate requests.
server.setHandler(webapp);
// Start things up!
server.start();
server.join();
}
use of org.eclipse.jetty.webapp.WebAppContext in project jetty.project by eclipse.
the class XmlConfiguredJetty method assertWebAppContextsExists.
public void assertWebAppContextsExists(String... expectedContextPaths) {
List<WebAppContext> contexts = getWebAppContexts();
if (expectedContextPaths.length != contexts.size()) {
System.err.println("## Expected Contexts");
for (String expected : expectedContextPaths) {
System.err.println(expected);
}
System.err.println("## Actual Contexts");
for (WebAppContext context : contexts) {
System.err.printf("%s ## %s%n", context.getContextPath(), context);
}
Assert.assertEquals("Contexts.size", expectedContextPaths.length, contexts.size());
}
for (String expectedPath : expectedContextPaths) {
boolean found = false;
for (WebAppContext context : contexts) {
if (context.getContextPath().equals(expectedPath)) {
found = true;
Assert.assertThat("Context[" + context.getContextPath() + "].state", context.getState(), is("STARTED"));
break;
}
}
Assert.assertTrue("Did not find Expected Context Path " + expectedPath, found);
}
}
use of org.eclipse.jetty.webapp.WebAppContext in project jetty.project by eclipse.
the class XmlConfiguredJetty method getWebAppContexts.
public List<WebAppContext> getWebAppContexts() {
List<WebAppContext> contexts = new ArrayList<>();
HandlerCollection handlers = (HandlerCollection) _server.getHandler();
Handler[] children = handlers.getChildHandlers();
for (Handler handler : children) {
if (handler instanceof WebAppContext) {
WebAppContext context = (WebAppContext) handler;
contexts.add(context);
}
}
return contexts;
}
use of org.eclipse.jetty.webapp.WebAppContext in project jetty.project by eclipse.
the class WSServer method createWebAppContext.
public WebAppContext createWebAppContext() throws MalformedURLException, IOException {
WebAppContext context = new WebAppContext();
context.setContextPath(this.contextPath);
context.setBaseResource(Resource.newResource(this.contextDir));
context.setAttribute("org.eclipse.jetty.websocket.jsr356", Boolean.TRUE);
// @formatter:off
context.setConfigurations(new Configuration[] { new AnnotationConfiguration(), new WebXmlConfiguration(), new WebInfConfiguration(), new PlusConfiguration(), new MetaInfConfiguration(), new FragmentConfiguration(), new EnvConfiguration() });
return context;
}
use of org.eclipse.jetty.webapp.WebAppContext in project jetty.project by eclipse.
the class EnvConfiguration method bindEnvEntries.
/**
* Bind all EnvEntries that have been declared, so that the processing of the
* web.xml file can potentially override them.
*
* We first bind EnvEntries declared in Server scope, then WebAppContext scope.
* @param context the context to use for the object scope
* @throws NamingException if unable to bind env entries
*/
public void bindEnvEntries(WebAppContext context) throws NamingException {
LOG.debug("Binding env entries from the jvm scope");
InitialContext ic = new InitialContext();
Context envCtx = (Context) ic.lookup("java:comp/env");
Object scope = null;
List<Object> list = NamingEntryUtil.lookupNamingEntries(scope, EnvEntry.class);
Iterator<Object> itor = list.iterator();
while (itor.hasNext()) {
EnvEntry ee = (EnvEntry) itor.next();
ee.bindToENC(ee.getJndiName());
Name namingEntryName = NamingEntryUtil.makeNamingEntryName(null, ee);
//also save the EnvEntry in the context so we can check it later
NamingUtil.bind(envCtx, namingEntryName.toString(), ee);
}
LOG.debug("Binding env entries from the server scope");
scope = context.getServer();
list = NamingEntryUtil.lookupNamingEntries(scope, EnvEntry.class);
itor = list.iterator();
while (itor.hasNext()) {
EnvEntry ee = (EnvEntry) itor.next();
ee.bindToENC(ee.getJndiName());
Name namingEntryName = NamingEntryUtil.makeNamingEntryName(null, ee);
//also save the EnvEntry in the context so we can check it later
NamingUtil.bind(envCtx, namingEntryName.toString(), ee);
}
LOG.debug("Binding env entries from the context scope");
scope = context;
list = NamingEntryUtil.lookupNamingEntries(scope, EnvEntry.class);
itor = list.iterator();
while (itor.hasNext()) {
EnvEntry ee = (EnvEntry) itor.next();
ee.bindToENC(ee.getJndiName());
Name namingEntryName = NamingEntryUtil.makeNamingEntryName(null, ee);
//also save the EnvEntry in the context so we can check it later
NamingUtil.bind(envCtx, namingEntryName.toString(), ee);
}
}
Aggregations