Search in sources :

Example 96 with WebAppContext

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();
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) DefaultSessionCache(org.eclipse.jetty.server.session.DefaultSessionCache) HashLoginService(org.eclipse.jetty.security.HashLoginService) DefaultSessionIdManager(org.eclipse.jetty.server.session.DefaultSessionIdManager) AllowSymLinkAliasChecker(org.eclipse.jetty.server.handler.AllowSymLinkAliasChecker) Server(org.eclipse.jetty.server.Server)

Example 97 with WebAppContext

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);
    }
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext)

Example 98 with WebAppContext

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;
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) ArrayList(java.util.ArrayList) Handler(org.eclipse.jetty.server.Handler) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection)

Example 99 with WebAppContext

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;
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) WebXmlConfiguration(org.eclipse.jetty.webapp.WebXmlConfiguration) WebInfConfiguration(org.eclipse.jetty.webapp.WebInfConfiguration) MetaInfConfiguration(org.eclipse.jetty.webapp.MetaInfConfiguration) PlusConfiguration(org.eclipse.jetty.plus.webapp.PlusConfiguration) FragmentConfiguration(org.eclipse.jetty.webapp.FragmentConfiguration) AnnotationConfiguration(org.eclipse.jetty.annotations.AnnotationConfiguration) EnvConfiguration(org.eclipse.jetty.plus.webapp.EnvConfiguration)

Example 100 with WebAppContext

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);
    }
}
Also used : InitialContext(javax.naming.InitialContext) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) NamingContext(org.eclipse.jetty.jndi.NamingContext) Context(javax.naming.Context) InitialContext(javax.naming.InitialContext) EnvEntry(org.eclipse.jetty.plus.jndi.EnvEntry) Name(javax.naming.Name)

Aggregations

WebAppContext (org.eclipse.jetty.webapp.WebAppContext)142 Server (org.eclipse.jetty.server.Server)58 File (java.io.File)37 Test (org.junit.Test)29 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)20 ServerConnector (org.eclipse.jetty.server.ServerConnector)18 URL (java.net.URL)16 ArrayList (java.util.ArrayList)11 IOException (java.io.IOException)10 URI (java.net.URI)10 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)9 FileWriter (java.io.FileWriter)7 Configuration (org.apache.hadoop.conf.Configuration)7 HashLoginService (org.eclipse.jetty.security.HashLoginService)7 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)7 FilterHolder (org.eclipse.jetty.servlet.FilterHolder)7 ServletMapping (org.eclipse.jetty.servlet.ServletMapping)7 BeforeClass (org.junit.BeforeClass)7 OutputStream (java.io.OutputStream)6 InitialContext (javax.naming.InitialContext)6