Search in sources :

Example 6 with ContextHandlerCollection

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

the class ZeppelinServer method main.

public static void main(String[] args) throws InterruptedException {
    ZeppelinConfiguration conf = ZeppelinConfiguration.create();
    conf.setProperty("args", args);
    jettyWebServer = setupJettyServer(conf);
    ContextHandlerCollection contexts = new ContextHandlerCollection();
    jettyWebServer.setHandler(contexts);
    // Web UI
    final WebAppContext webApp = setupWebAppContext(contexts, conf);
    // Create `ZeppelinServer` using reflection and setup REST Api
    setupRestApiContextHandler(webApp, conf);
    // Notebook server
    setupNotebookServer(webApp, conf);
    //Below is commented since zeppelin-docs module is removed.
    //final WebAppContext webAppSwagg = setupWebAppSwagger(conf);
    LOG.info("Starting zeppelin server");
    try {
        //Instantiates ZeppelinServer
        jettyWebServer.start();
    } catch (Exception e) {
        LOG.error("Error while running jettyServer", e);
        System.exit(-1);
    }
    LOG.info("Done, zeppelin server started");
    Runtime.getRuntime().addShutdownHook(new Thread() {

        @Override
        public void run() {
            LOG.info("Shutting down Zeppelin Server ... ");
            try {
                jettyWebServer.stop();
                notebook.getInterpreterSettingManager().shutdown();
                notebook.close();
                Thread.sleep(3000);
            } catch (Exception e) {
                LOG.error("Error while stopping servlet container", e);
            }
            LOG.info("Bye");
        }
    });
    // for graceful shutdown, input any key in console window
    if (System.getenv("ZEPPELIN_IDENT_STRING") == null) {
        try {
            System.in.read();
        } catch (IOException e) {
            LOG.error("Exception in ZeppelinServer while main ", e);
        }
        System.exit(0);
    }
    jettyWebServer.join();
    ZeppelinServer.notebook.getInterpreterSettingManager().close();
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) ZeppelinConfiguration(org.apache.zeppelin.conf.ZeppelinConfiguration) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) IOException(java.io.IOException) IOException(java.io.IOException)

Example 7 with ContextHandlerCollection

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

the class DeploymentManagerTest method testReceiveApp.

@Test
public void testReceiveApp() throws Exception {
    DeploymentManager depman = new DeploymentManager();
    depman.setContexts(new ContextHandlerCollection());
    // no default
    depman.setDefaultLifeCycleGoal(null);
    AppLifeCyclePathCollector pathtracker = new AppLifeCyclePathCollector();
    MockAppProvider mockProvider = new MockAppProvider();
    depman.addLifeCycleBinding(pathtracker);
    depman.addAppProvider(mockProvider);
    // Start DepMan
    depman.start();
    // Trigger new App
    mockProvider.findWebapp("foo-webapp-1.war");
    // Test app tracking
    Collection<App> apps = depman.getApps();
    Assert.assertNotNull("Should never be null", apps);
    Assert.assertEquals("Expected App Count", 1, apps.size());
    // Test app get
    App actual = depman.getAppByOriginId("mock-foo-webapp-1.war");
    Assert.assertNotNull("Should have gotten app (by id)", actual);
    Assert.assertEquals("Should have gotten app (by id)", "mock-foo-webapp-1.war", actual.getOriginId());
}
Also used : ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) Test(org.junit.Test)

Example 8 with ContextHandlerCollection

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

the class OverlayServer method main.

public static void main(String[] args) throws Exception {
    // NamingUtil.__log.setDebugEnabled(true);
    String jetty_home = System.getProperty("jetty.home", "target/test-classes/home");
    System.setProperty("jetty.home", jetty_home);
    Server server = new Server();
    server.setAttribute("org.eclipse.jetty.webapp.configuration", new String[] { org.eclipse.jetty.webapp.WebInfConfiguration.class.getCanonicalName(), org.eclipse.jetty.webapp.WebXmlConfiguration.class.getCanonicalName(), org.eclipse.jetty.webapp.MetaInfConfiguration.class.getCanonicalName(), org.eclipse.jetty.webapp.FragmentConfiguration.class.getCanonicalName(), org.eclipse.jetty.plus.webapp.EnvConfiguration.class.getCanonicalName(), org.eclipse.jetty.plus.webapp.PlusConfiguration.class.getCanonicalName(), org.eclipse.jetty.webapp.JettyWebXmlConfiguration.class.getCanonicalName() });
    // Setup Connectors
    ServerConnector connector = new ServerConnector(server);
    connector.setPort(8080);
    server.addConnector(connector);
    HandlerCollection handlers = new HandlerCollection();
    ContextHandlerCollection contexts = new ContextHandlerCollection();
    RequestLogHandler requestLogHandler = new RequestLogHandler();
    handlers.setHandlers(new Handler[] { contexts, new DefaultHandler(), requestLogHandler });
    StatisticsHandler stats = new StatisticsHandler();
    stats.setHandler(handlers);
    server.setHandler(stats);
    // Setup deployers
    DeploymentManager deployer = new DeploymentManager();
    deployer.setContexts(contexts);
    server.addBean(deployer);
    OverlayedAppProvider provider = new OverlayedAppProvider();
    provider.setNodeName("nodeA");
    provider.setScanDir(new File(jetty_home + "/overlays"));
    provider.setScanInterval(2);
    deployer.addAppProvider(provider);
    server.setStopAtShutdown(true);
    //server.setSendServerVersion(true);
    // Uncomment to work with JNDI examples
    // new org.eclipse.jetty.plus.jndi.Transaction(new com.atomikos.icatch.jta.UserTransactionImp());
    server.start();
    server.join();
}
Also used : Server(org.eclipse.jetty.server.Server) DeploymentManager(org.eclipse.jetty.deploy.DeploymentManager) OverlayedAppProvider(org.eclipse.jetty.overlays.OverlayedAppProvider) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler) ServerConnector(org.eclipse.jetty.server.ServerConnector) RequestLogHandler(org.eclipse.jetty.server.handler.RequestLogHandler) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection) StatisticsHandler(org.eclipse.jetty.server.handler.StatisticsHandler) File(java.io.File)

Example 9 with ContextHandlerCollection

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

the class ServletContextHandlerTest method testFindContainer.

@Test
public void testFindContainer() throws Exception {
    ContextHandlerCollection contexts = new ContextHandlerCollection();
    _server.setHandler(contexts);
    ServletContextHandler root = new ServletContextHandler(contexts, "/", ServletContextHandler.SESSIONS);
    SessionHandler session = root.getSessionHandler();
    ServletHandler servlet = root.getServletHandler();
    SecurityHandler security = new ConstraintSecurityHandler();
    root.setSecurityHandler(security);
    _server.start();
    assertEquals(root, AbstractHandlerContainer.findContainerOf(_server, ContextHandler.class, session));
    assertEquals(root, AbstractHandlerContainer.findContainerOf(_server, ContextHandler.class, security));
    assertEquals(root, AbstractHandlerContainer.findContainerOf(_server, ContextHandler.class, servlet));
}
Also used : SessionHandler(org.eclipse.jetty.server.session.SessionHandler) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) ConstraintSecurityHandler(org.eclipse.jetty.security.ConstraintSecurityHandler) SecurityHandler(org.eclipse.jetty.security.SecurityHandler) ConstraintSecurityHandler(org.eclipse.jetty.security.ConstraintSecurityHandler) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) Test(org.junit.Test)

Example 10 with ContextHandlerCollection

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

the class DispatcherTest method init.

@Before
public void init() throws Exception {
    _server = new Server();
    _connector = new LocalConnector(_server);
    _connector.getConnectionFactory(HttpConfiguration.ConnectionFactory.class).getHttpConfiguration().setSendServerVersion(false);
    _connector.getConnectionFactory(HttpConfiguration.ConnectionFactory.class).getHttpConfiguration().setSendDateHeader(false);
    _contextCollection = new ContextHandlerCollection();
    _contextHandler = new ServletContextHandler();
    _contextHandler.setContextPath("/context");
    _contextCollection.addHandler(_contextHandler);
    _resourceHandler = new ResourceHandler();
    _resourceHandler.setResourceBase(MavenTestingUtils.getTestResourceDir("dispatchResourceTest").getAbsolutePath());
    _resourceHandler.setPathInfoOnly(true);
    ContextHandler resourceContextHandler = new ContextHandler("/resource");
    resourceContextHandler.setHandler(_resourceHandler);
    _contextCollection.addHandler(resourceContextHandler);
    _server.setHandler(_contextCollection);
    _server.addConnector(_connector);
    _server.start();
}
Also used : ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) Server(org.eclipse.jetty.server.Server) LocalConnector(org.eclipse.jetty.server.LocalConnector) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) ResourceHandler(org.eclipse.jetty.server.handler.ResourceHandler) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) Before(org.junit.Before)

Aggregations

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