Search in sources :

Example 41 with XmlConfiguration

use of org.eclipse.jetty.xml.XmlConfiguration in project ddf by codice.

the class JettySessionManagementTest method setupClass.

@BeforeClass
public static void setupClass() throws Exception {
    // To get the AccessRequestLog to log in the target folder
    System.setProperty("ddf.data", "target");
    server = new Server();
    HandlerList handlers = new HandlerList();
    server.setHandler(handlers);
    // Configure server according to the jetty.xml file
    XmlConfiguration configuration = new XmlConfiguration(JettySessionManagementTest.class.getResourceAsStream("/jetty-session.xml"));
    configuration.configure(server);
    // Have server bind to first available port
    ServerConnector connector = new ServerConnector(server);
    connector.setPort(0);
    server.addConnector(connector);
    ServletContextHandler context = new ServletContextHandler(null, "/context1", ServletContextHandler.SESSIONS);
    context.addServlet(new ServletHolder(new TestServlet()), "/");
    context.getSessionHandler().setMaxInactiveInterval(MAX_INACTIVE_INTERVAL_SECONDS);
    handlers.addHandler(context);
    ServletContextHandler context2 = new ServletContextHandler(null, "/context2", ServletContextHandler.SESSIONS);
    context2.addServlet(new ServletHolder(new TestServlet()), "/");
    context2.getSessionHandler().setMaxInactiveInterval(MAX_INACTIVE_INTERVAL_SECONDS);
    handlers.addHandler(context2);
    HouseKeeper houseKeeper = new HouseKeeper();
    houseKeeper.setIntervalSec(SCAVENGE_INTERVAL_SECONDS);
    server.getSessionIdManager().setSessionHouseKeeper(houseKeeper);
    server.start();
    port = connector.getLocalPort();
}
Also used : HandlerList(org.eclipse.jetty.server.handler.HandlerList) ServerConnector(org.eclipse.jetty.server.ServerConnector) Server(org.eclipse.jetty.server.Server) HouseKeeper(org.eclipse.jetty.server.session.HouseKeeper) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) XmlConfiguration(org.eclipse.jetty.xml.XmlConfiguration) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) BeforeClass(org.junit.BeforeClass)

Example 42 with XmlConfiguration

use of org.eclipse.jetty.xml.XmlConfiguration in project i2p.i2p by i2p.

the class JettyStart method parseArgs.

/**
 *  Modified from XmlConfiguration.main()
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public void parseArgs(String[] args) throws Exception {
    Properties properties = new Properties();
    XmlConfiguration last = null;
    for (int i = 0; i < args.length; i++) {
        File f = new File(args[i]);
        if (args[i].toLowerCase().endsWith(".properties")) {
            InputStream in = null;
            try {
                in = new FileInputStream(f);
                properties.load(in);
            } finally {
                if (in != null)
                    try {
                        in.close();
                    } catch (IOException ioe) {
                    }
            }
        } else {
            URL configUrl = f.toURI().toURL();
            XmlConfiguration configuration = new XmlConfiguration(configUrl);
            if (last != null)
                configuration.getIdMap().putAll(last.getIdMap());
            if (properties.size() > 0) {
                // to avoid compiler errror
                Map foo = configuration.getProperties();
                foo.putAll(properties);
            }
            Object o = configuration.configure();
            if (o instanceof LifeCycle)
                _jettys.add((LifeCycle) o);
            last = configuration;
        }
    }
}
Also used : LifeCycle(org.eclipse.jetty.util.component.LifeCycle) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) XmlConfiguration(org.eclipse.jetty.xml.XmlConfiguration) IOException(java.io.IOException) Properties(java.util.Properties) File(java.io.File) Map(java.util.Map) FileInputStream(java.io.FileInputStream) URL(java.net.URL)

Example 43 with XmlConfiguration

use of org.eclipse.jetty.xml.XmlConfiguration in project killbill by killbill.

the class HttpServer method configure.

public void configure(final String jettyXml) throws Exception {
    final XmlConfiguration configuration = new XmlConfiguration(Resources.getResource(jettyXml));
    configuration.configure(server);
}
Also used : XmlConfiguration(org.eclipse.jetty.xml.XmlConfiguration)

Aggregations

XmlConfiguration (org.eclipse.jetty.xml.XmlConfiguration)43 Server (org.eclipse.jetty.server.Server)24 Resource (org.eclipse.jetty.util.resource.Resource)18 URL (java.net.URL)12 File (java.io.File)9 IOException (java.io.IOException)9 HashMap (java.util.HashMap)6 Test (org.junit.Test)6 InputStream (java.io.InputStream)5 ArrayList (java.util.ArrayList)5 Handler (org.eclipse.jetty.server.Handler)5 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)5 FileInputStream (java.io.FileInputStream)4 URLClassLoader (java.net.URLClassLoader)4 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)4 JettyWebXmlConfiguration (org.eclipse.jetty.webapp.JettyWebXmlConfiguration)4 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)4 FileNotFoundException (java.io.FileNotFoundException)3 HttpURLConnection (java.net.HttpURLConnection)3 MalformedURLException (java.net.MalformedURLException)3