Search in sources :

Example 1 with WebXmlConfiguration

use of org.mortbay.jetty.webapp.WebXmlConfiguration in project hudson-2.x by hudson.

the class HudsonTestCase method createWebServer.

/**
     * Prepares a webapp hosting environment to get {@link ServletContext} implementation
     * that we need for testing.
     */
protected ServletContext createWebServer() throws Exception {
    server = new Server();
    WebAppContext context = new WebAppContext(WarExploder.getExplodedDir().getPath(), contextPath);
    context.setClassLoader(getClass().getClassLoader());
    context.setConfigurations(new Configuration[] { new WebXmlConfiguration(), new NoListenerConfiguration() });
    server.setHandler(context);
    context.setMimeTypes(MIME_TYPES);
    SocketConnector connector = new SocketConnector();
    server.addConnector(connector);
    server.addUserRealm(configureUserRealm());
    server.start();
    localPort = connector.getLocalPort();
    return context.getServletContext();
}
Also used : WebAppContext(org.mortbay.jetty.webapp.WebAppContext) WebXmlConfiguration(org.mortbay.jetty.webapp.WebXmlConfiguration) Server(org.mortbay.jetty.Server) SocketConnector(org.mortbay.jetty.bio.SocketConnector)

Example 2 with WebXmlConfiguration

use of org.mortbay.jetty.webapp.WebXmlConfiguration 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();
    }
}
Also used : ContextHandler(org.mortbay.jetty.handler.ContextHandler) WebAppContext(org.mortbay.jetty.webapp.WebAppContext) SecurityHandler(org.mortbay.jetty.security.SecurityHandler) WebXmlConfiguration(org.mortbay.jetty.webapp.WebXmlConfiguration) URL(java.net.URL)

Aggregations

WebAppContext (org.mortbay.jetty.webapp.WebAppContext)2 WebXmlConfiguration (org.mortbay.jetty.webapp.WebXmlConfiguration)2 URL (java.net.URL)1 Server (org.mortbay.jetty.Server)1 SocketConnector (org.mortbay.jetty.bio.SocketConnector)1 ContextHandler (org.mortbay.jetty.handler.ContextHandler)1 SecurityHandler (org.mortbay.jetty.security.SecurityHandler)1