Java Code Examples for org.mortbay.jetty.webapp.WebAppContext#setServer()

The following examples show how to use org.mortbay.jetty.webapp.WebAppContext#setServer() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExhibitorMain.java    From exhibitor with Apache License 2.0 4 votes vote down vote up
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();
    }
}
 
Example 2
Source File: JettyServer.java    From athena-rest with Apache License 2.0 3 votes vote down vote up
protected void doStart() throws Exception {

		server = new Server();

		if (this.minThreads != -1 && this.maxThreads != -1) {
			BoundedThreadPool btp = new BoundedThreadPool();
			server.setThreadPool(btp);
		}

		SelectChannelConnector connector = new SelectChannelConnector();

		// Set some timeout options to make debugging easier.
		connector.setSoLingerTime(-1);
		connector.setPort(port);

		server.setConnectors(new Connector[] { connector });

		WebAppContext wac = new WebAppContext();

		wac.setServer(server);
		wac.setContextPath(contextPath);
		wac.setWar(webappPath);

		server.setHandler(wac);

		log.info("Starting jetty server actually.");
		server.start();
	}