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();
}
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();
}
}
Aggregations