Search in sources :

Example 31 with ContextHandlerCollection

use of org.eclipse.jetty.server.handler.ContextHandlerCollection in project Openfire by igniterealtime.

the class HttpBindManager method configureHttpBindServer.

/**
     * Starts an HTTP Bind server on the specified port and secure port.
     *
     * @param port the port to start the normal (unsecured) HTTP Bind service on.
     * @param securePort the port to start the TLS (secure) HTTP Bind service on.
     */
private synchronized void configureHttpBindServer(int port, int securePort) {
    // this is the number of threads allocated to each connector/port
    final int processingThreads = JiveGlobals.getIntProperty(HTTP_BIND_THREADS, HTTP_BIND_THREADS_DEFAULT);
    final QueuedThreadPool tp = new QueuedThreadPool(processingThreads);
    tp.setName("Jetty-QTP-BOSH");
    httpBindServer = new Server(tp);
    if (JMXManager.isEnabled()) {
        JMXManager jmx = JMXManager.getInstance();
        httpBindServer.addBean(jmx.getContainer());
    }
    createConnector(port);
    createSSLConnector(securePort);
    if (httpConnector == null && httpsConnector == null) {
        httpBindServer = null;
        return;
    }
    if (httpConnector != null) {
        httpBindServer.addConnector(httpConnector);
    }
    if (httpsConnector != null) {
        httpBindServer.addConnector(httpsConnector);
    }
    //contexts = new ContextHandlerCollection();
    // TODO implement a way to get plugins to add their their web services to contexts
    createBoshHandler(contexts, "/http-bind");
    createCrossDomainHandler(contexts, "/crossdomain.xml");
    loadStaticDirectory(contexts);
    HandlerCollection collection = new HandlerCollection();
    httpBindServer.setHandler(collection);
    collection.setHandlers(new Handler[] { contexts, new DefaultHandler() });
}
Also used : JMXManager(org.jivesoftware.openfire.JMXManager) XMPPServer(org.jivesoftware.openfire.XMPPServer) Server(org.eclipse.jetty.server.Server) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler)

Example 32 with ContextHandlerCollection

use of org.eclipse.jetty.server.handler.ContextHandlerCollection in project jetty.project by eclipse.

the class LikeJettyXml method main.

public static void main(String[] args) throws Exception {
    // Path to as-built jetty-distribution directory
    String jettyHomeBuild = "../../jetty-distribution/target/distribution";
    // Find jetty home and base directories
    String homePath = System.getProperty("jetty.home", jettyHomeBuild);
    File start_jar = new File(homePath, "start.jar");
    if (!start_jar.exists()) {
        homePath = jettyHomeBuild = "jetty-distribution/target/distribution";
        start_jar = new File(homePath, "start.jar");
        if (!start_jar.exists())
            throw new FileNotFoundException(start_jar.toString());
    }
    File homeDir = new File(homePath);
    String basePath = System.getProperty("jetty.base", homeDir + "/demo-base");
    File baseDir = new File(basePath);
    if (!baseDir.exists()) {
        throw new FileNotFoundException(baseDir.getAbsolutePath());
    }
    // Configure jetty.home and jetty.base system properties
    String jetty_home = homeDir.getAbsolutePath();
    String jetty_base = baseDir.getAbsolutePath();
    System.setProperty("jetty.home", jetty_home);
    System.setProperty("jetty.base", jetty_base);
    // === jetty.xml ===
    // Setup Threadpool
    QueuedThreadPool threadPool = new QueuedThreadPool();
    threadPool.setMaxThreads(500);
    // Server
    Server server = new Server(threadPool);
    // Scheduler
    server.addBean(new ScheduledExecutorScheduler());
    // HTTP Configuration
    HttpConfiguration http_config = new HttpConfiguration();
    http_config.setSecureScheme("https");
    http_config.setSecurePort(8443);
    http_config.setOutputBufferSize(32768);
    http_config.setRequestHeaderSize(8192);
    http_config.setResponseHeaderSize(8192);
    http_config.setSendServerVersion(true);
    http_config.setSendDateHeader(false);
    // httpConfig.addCustomizer(new ForwardedRequestCustomizer());
    // Handler Structure
    HandlerCollection handlers = new HandlerCollection();
    ContextHandlerCollection contexts = new ContextHandlerCollection();
    handlers.setHandlers(new Handler[] { contexts, new DefaultHandler() });
    server.setHandler(handlers);
    // Extra options
    server.setDumpAfterStart(false);
    server.setDumpBeforeStop(false);
    server.setStopAtShutdown(true);
    // === jetty-jmx.xml ===
    MBeanContainer mbContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
    server.addBean(mbContainer);
    // === jetty-http.xml ===
    ServerConnector http = new ServerConnector(server, new HttpConnectionFactory(http_config));
    http.setPort(8080);
    http.setIdleTimeout(30000);
    server.addConnector(http);
    // === jetty-https.xml ===
    // SSL Context Factory
    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setKeyStorePath(jetty_home + "/../../../jetty-server/src/test/config/etc/keystore");
    sslContextFactory.setKeyStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
    sslContextFactory.setKeyManagerPassword("OBF:1u2u1wml1z7s1z7a1wnl1u2g");
    sslContextFactory.setTrustStorePath(jetty_home + "/../../../jetty-server/src/test/config/etc/keystore");
    sslContextFactory.setTrustStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
    sslContextFactory.setExcludeCipherSuites("SSL_RSA_WITH_DES_CBC_SHA", "SSL_DHE_RSA_WITH_DES_CBC_SHA", "SSL_DHE_DSS_WITH_DES_CBC_SHA", "SSL_RSA_EXPORT_WITH_RC4_40_MD5", "SSL_RSA_EXPORT_WITH_DES40_CBC_SHA", "SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA", "SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA");
    // SSL HTTP Configuration
    HttpConfiguration https_config = new HttpConfiguration(http_config);
    https_config.addCustomizer(new SecureRequestCustomizer());
    // SSL Connector
    ServerConnector sslConnector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(https_config));
    sslConnector.setPort(8443);
    server.addConnector(sslConnector);
    // === jetty-deploy.xml ===
    DeploymentManager deployer = new DeploymentManager();
    DebugListener debug = new DebugListener(System.err, true, true, true);
    server.addBean(debug);
    deployer.addLifeCycleBinding(new DebugListenerBinding(debug));
    deployer.setContexts(contexts);
    deployer.setContextAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern", ".*/servlet-api-[^/]*\\.jar$");
    WebAppProvider webapp_provider = new WebAppProvider();
    webapp_provider.setMonitoredDirName(jetty_base + "/webapps");
    webapp_provider.setDefaultsDescriptor(jetty_home + "/etc/webdefault.xml");
    webapp_provider.setScanInterval(1);
    webapp_provider.setExtractWars(true);
    webapp_provider.setConfigurationManager(new PropertiesConfigurationManager());
    deployer.addAppProvider(webapp_provider);
    server.addBean(deployer);
    // === setup jetty plus ==
    Configuration.ClassList.setServerDefault(server).addAfter("org.eclipse.jetty.webapp.FragmentConfiguration", "org.eclipse.jetty.plus.webapp.EnvConfiguration", "org.eclipse.jetty.plus.webapp.PlusConfiguration");
    // === jetty-stats.xml ===
    StatisticsHandler stats = new StatisticsHandler();
    stats.setHandler(server.getHandler());
    server.setHandler(stats);
    ServerConnectionStatistics.addToAllConnectors(server);
    // === Rewrite Handler
    RewriteHandler rewrite = new RewriteHandler();
    rewrite.setHandler(server.getHandler());
    server.setHandler(rewrite);
    // === jetty-requestlog.xml ===
    NCSARequestLog requestLog = new NCSARequestLog();
    requestLog.setFilename(jetty_home + "/logs/yyyy_mm_dd.request.log");
    requestLog.setFilenameDateFormat("yyyy_MM_dd");
    requestLog.setRetainDays(90);
    requestLog.setAppend(true);
    requestLog.setExtended(true);
    requestLog.setLogCookies(false);
    requestLog.setLogTimeZone("GMT");
    RequestLogHandler requestLogHandler = new RequestLogHandler();
    requestLogHandler.setRequestLog(requestLog);
    handlers.addHandler(requestLogHandler);
    // === jetty-lowresources.xml ===
    LowResourceMonitor lowResourcesMonitor = new LowResourceMonitor(server);
    lowResourcesMonitor.setPeriod(1000);
    lowResourcesMonitor.setLowResourcesIdleTimeout(200);
    lowResourcesMonitor.setMonitorThreads(true);
    lowResourcesMonitor.setMaxConnections(0);
    lowResourcesMonitor.setMaxMemory(0);
    lowResourcesMonitor.setMaxLowResourcesTime(5000);
    server.addBean(lowResourcesMonitor);
    // === test-realm.xml ===
    HashLoginService login = new HashLoginService();
    login.setName("Test Realm");
    login.setConfig(jetty_base + "/etc/realm.properties");
    login.setHotReload(false);
    server.addBean(login);
    // Start the server
    server.start();
    server.join();
}
Also used : Server(org.eclipse.jetty.server.Server) DeploymentManager(org.eclipse.jetty.deploy.DeploymentManager) FileNotFoundException(java.io.FileNotFoundException) ScheduledExecutorScheduler(org.eclipse.jetty.util.thread.ScheduledExecutorScheduler) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) ServerConnector(org.eclipse.jetty.server.ServerConnector) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) HashLoginService(org.eclipse.jetty.security.HashLoginService) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) DebugListenerBinding(org.eclipse.jetty.deploy.bindings.DebugListenerBinding) RequestLogHandler(org.eclipse.jetty.server.handler.RequestLogHandler) NCSARequestLog(org.eclipse.jetty.server.NCSARequestLog) PropertiesConfigurationManager(org.eclipse.jetty.deploy.PropertiesConfigurationManager) MBeanContainer(org.eclipse.jetty.jmx.MBeanContainer) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection) RewriteHandler(org.eclipse.jetty.rewrite.handler.RewriteHandler) SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) DebugListener(org.eclipse.jetty.server.DebugListener) WebAppProvider(org.eclipse.jetty.deploy.providers.WebAppProvider) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler) LowResourceMonitor(org.eclipse.jetty.server.LowResourceMonitor) StatisticsHandler(org.eclipse.jetty.server.handler.StatisticsHandler) File(java.io.File)

Example 33 with ContextHandlerCollection

use of org.eclipse.jetty.server.handler.ContextHandlerCollection in project jetty.project by eclipse.

the class ManyContexts method main.

public static void main(String[] args) throws Exception {
    Server server = new Server(8080);
    ContextHandler context = new ContextHandler("/");
    context.setContextPath("/");
    context.setHandler(new HelloHandler("Root Hello"));
    ContextHandler contextFR = new ContextHandler("/fr");
    contextFR.setHandler(new HelloHandler("Bonjoir"));
    ContextHandler contextIT = new ContextHandler("/it");
    contextIT.setHandler(new HelloHandler("Bongiorno"));
    ContextHandler contextV = new ContextHandler("/");
    contextV.setVirtualHosts(new String[] { "127.0.0.2" });
    contextV.setHandler(new HelloHandler("Virtual Hello"));
    ContextHandlerCollection contexts = new ContextHandlerCollection();
    contexts.setHandlers(new Handler[] { context, contextFR, contextIT, contextV });
    server.setHandler(contexts);
    server.start();
    server.join();
}
Also used : ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) Server(org.eclipse.jetty.server.Server) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection)

Example 34 with ContextHandlerCollection

use of org.eclipse.jetty.server.handler.ContextHandlerCollection in project jetty.project by eclipse.

the class ServerProxyImpl method configureHandlers.

/**
     * 
     */
private void configureHandlers() {
    RequestLogHandler requestLogHandler = new RequestLogHandler();
    if (requestLog != null)
        requestLogHandler.setRequestLog(requestLog);
    contexts = (ContextHandlerCollection) server.getChildHandlerByClass(ContextHandlerCollection.class);
    if (contexts == null) {
        contexts = new ContextHandlerCollection();
        HandlerCollection handlers = (HandlerCollection) server.getChildHandlerByClass(HandlerCollection.class);
        if (handlers == null) {
            handlers = new HandlerCollection();
            server.setHandler(handlers);
            handlers.setHandlers(new Handler[] { contexts, new DefaultHandler(), requestLogHandler });
        } else {
            handlers.addHandler(contexts);
        }
    }
    //if there are any extra contexts to deploy
    if (contextHandlers != null && contextHandlers.getContextHandlers() != null) {
        for (ContextHandler c : contextHandlers.getContextHandlers()) contexts.addHandler(c);
    }
}
Also used : ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) RequestLogHandler(org.eclipse.jetty.server.handler.RequestLogHandler) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler)

Example 35 with ContextHandlerCollection

use of org.eclipse.jetty.server.handler.ContextHandlerCollection in project jetty.project by eclipse.

the class SplitFileServer method main.

public static void main(String[] args) throws Exception {
    // Create the Server object and a corresponding ServerConnector and then
    // set the port for the connector. In this example the server will
    // listen on port 8090. If you set this to port 0 then when the server
    // has been started you can called connector.getLocalPort() to
    // programmatically get the port the server started on.
    Server server = new Server();
    ServerConnector connector = new ServerConnector(server);
    connector.setPort(8090);
    server.setConnectors(new Connector[] { connector });
    // Create a Context Handler and ResourceHandler. The ContextHandler is
    // getting set to "/" path but this could be anything you like for
    // builing out your url. Note how we are setting the ResourceBase using
    // our jetty maven testing utilities to get the proper resource
    // directory, you needn't use these, you simply need to supply the paths
    // you are looking to serve content from.
    ResourceHandler rh0 = new ResourceHandler();
    ContextHandler context0 = new ContextHandler();
    context0.setContextPath("/");
    File dir0 = MavenTestingUtils.getTestResourceDir("dir0");
    context0.setBaseResource(Resource.newResource(dir0));
    context0.setHandler(rh0);
    // Rinse and repeat the previous item, only specifying a different
    // resource base.
    ResourceHandler rh1 = new ResourceHandler();
    ContextHandler context1 = new ContextHandler();
    context1.setContextPath("/");
    File dir1 = MavenTestingUtils.getTestResourceDir("dir1");
    context1.setBaseResource(Resource.newResource(dir1));
    context1.setHandler(rh1);
    // Create a ContextHandlerCollection and set the context handlers to it.
    // This will let jetty process urls against the declared contexts in
    // order to match up content.
    ContextHandlerCollection contexts = new ContextHandlerCollection();
    contexts.setHandlers(new Handler[] { context0, context1 });
    server.setHandler(contexts);
    // Start things up! 
    server.start();
    // Dump the server state
    System.out.println(server.dump());
    // The use of server.join() the will make the current thread join and
    // wait until the server is done executing.
    // See http://docs.oracle.com/javase/7/docs/api/java/lang/Thread.html#join()
    server.join();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) Server(org.eclipse.jetty.server.Server) ResourceHandler(org.eclipse.jetty.server.handler.ResourceHandler) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) File(java.io.File)

Aggregations

ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)59 Server (org.eclipse.jetty.server.Server)27 HandlerCollection (org.eclipse.jetty.server.handler.HandlerCollection)21 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)18 DefaultHandler (org.eclipse.jetty.server.handler.DefaultHandler)17 RequestLogHandler (org.eclipse.jetty.server.handler.RequestLogHandler)17 ServerConnector (org.eclipse.jetty.server.ServerConnector)15 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)15 Handler (org.eclipse.jetty.server.Handler)10 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)10 Test (org.junit.Test)10 URI (java.net.URI)7 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)7 ResourceHandler (org.eclipse.jetty.server.handler.ResourceHandler)7 File (java.io.File)6 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)6 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)6 ArrayList (java.util.ArrayList)5 MBeanContainer (org.eclipse.jetty.jmx.MBeanContainer)5 HttpURLConnection (java.net.HttpURLConnection)4