Search in sources :

Example 31 with WebAppContext

use of org.eclipse.jetty.webapp.WebAppContext in project neo4j by neo4j.

the class Jetty9WebServer method loadStaticContent.

private void loadStaticContent(SessionManager sm, String mountPoint) {
    String contentLocation = staticContent.get(mountPoint);
    try {
        SessionHandler sessionHandler = new SessionHandler(sm);
        sessionHandler.setServer(getJetty());
        final WebAppContext staticContext = new WebAppContext();
        staticContext.setServer(getJetty());
        staticContext.setContextPath(mountPoint);
        staticContext.setSessionHandler(sessionHandler);
        staticContext.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
        URL resourceLoc = getClass().getClassLoader().getResource(contentLocation);
        if (resourceLoc != null) {
            URL url = resourceLoc.toURI().toURL();
            final Resource resource = Resource.newResource(url);
            staticContext.setBaseResource(resource);
            addFiltersTo(staticContext);
            staticContext.addFilter(new FilterHolder(new NoCacheHtmlFilter()), "/*", EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD));
            handlers.addHandler(staticContext);
        } else {
            log.warn("No static content available for Neo Server at %s, management console may not be available.", jettyAddress);
        }
    } catch (Exception e) {
        log.error("Unknown error loading static content", e);
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}
Also used : SessionHandler(org.eclipse.jetty.server.session.SessionHandler) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) FilterHolder(org.eclipse.jetty.servlet.FilterHolder) Resource(org.eclipse.jetty.util.resource.Resource) URL(java.net.URL) ServletException(javax.servlet.ServletException) URISyntaxException(java.net.URISyntaxException) PortBindException(org.neo4j.helpers.PortBindException) BindException(java.net.BindException) IOException(java.io.IOException)

Example 32 with WebAppContext

use of org.eclipse.jetty.webapp.WebAppContext in project hadoop by apache.

the class TestHttpFSServer method createHttpFSServer.

private void createHttpFSServer(boolean addDelegationTokenAuthHandler) throws Exception {
    File homeDir = TestDirHelper.getTestDir();
    Assert.assertTrue(new File(homeDir, "conf").mkdir());
    Assert.assertTrue(new File(homeDir, "log").mkdir());
    Assert.assertTrue(new File(homeDir, "temp").mkdir());
    HttpFSServerWebApp.setHomeDirForCurrentThread(homeDir.getAbsolutePath());
    File secretFile = new File(new File(homeDir, "conf"), "secret");
    Writer w = new FileWriter(secretFile);
    w.write("secret");
    w.close();
    //HDFS configuration
    File hadoopConfDir = new File(new File(homeDir, "conf"), "hadoop-conf");
    hadoopConfDir.mkdirs();
    Configuration hdfsConf = TestHdfsHelper.getHdfsConf();
    // Http Server's conf should be based on HDFS's conf
    Configuration conf = new Configuration(hdfsConf);
    conf.setBoolean(DFSConfigKeys.DFS_NAMENODE_ACLS_ENABLED_KEY, true);
    conf.setBoolean(DFSConfigKeys.DFS_NAMENODE_XATTRS_ENABLED_KEY, true);
    File hdfsSite = new File(hadoopConfDir, "hdfs-site.xml");
    OutputStream os = new FileOutputStream(hdfsSite);
    conf.writeXml(os);
    os.close();
    //HTTPFS configuration
    conf = new Configuration(false);
    if (addDelegationTokenAuthHandler) {
        conf.set("httpfs.authentication.type", HttpFSKerberosAuthenticationHandlerForTesting.class.getName());
    }
    conf.set("httpfs.services.ext", MockGroups.class.getName());
    conf.set("httpfs.admin.group", HadoopUsersConfTestHelper.getHadoopUserGroups(HadoopUsersConfTestHelper.getHadoopUsers()[0])[0]);
    conf.set("httpfs.proxyuser." + HadoopUsersConfTestHelper.getHadoopProxyUser() + ".groups", HadoopUsersConfTestHelper.getHadoopProxyUserGroups());
    conf.set("httpfs.proxyuser." + HadoopUsersConfTestHelper.getHadoopProxyUser() + ".hosts", HadoopUsersConfTestHelper.getHadoopProxyUserHosts());
    conf.set("httpfs.authentication.signature.secret.file", secretFile.getAbsolutePath());
    conf.set("httpfs.hadoop.config.dir", hadoopConfDir.toString());
    File httpfsSite = new File(new File(homeDir, "conf"), "httpfs-site.xml");
    os = new FileOutputStream(httpfsSite);
    conf.writeXml(os);
    os.close();
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    URL url = cl.getResource("webapp");
    WebAppContext context = new WebAppContext(url.getPath(), "/webhdfs");
    Server server = TestJettyHelper.getJettyServer();
    server.setHandler(context);
    server.start();
    if (addDelegationTokenAuthHandler) {
        HttpFSServerWebApp.get().setAuthority(TestJettyHelper.getAuthority());
    }
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) Configuration(org.apache.hadoop.conf.Configuration) Server(org.eclipse.jetty.server.Server) FileWriter(java.io.FileWriter) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) Writer(java.io.Writer) FileWriter(java.io.FileWriter) URL(java.net.URL) AuthenticatedURL(org.apache.hadoop.security.authentication.client.AuthenticatedURL)

Example 33 with WebAppContext

use of org.eclipse.jetty.webapp.WebAppContext in project spark by perwendel.

the class ServletTest method setup.

@BeforeClass
public static void setup() throws InterruptedException {
    testUtil = new SparkTestUtil(PORT);
    final Server server = new Server();
    ServerConnector connector = new ServerConnector(server);
    // Set some timeout options to make debugging easier.
    connector.setIdleTimeout(1000 * 60 * 60);
    connector.setSoLingerTime(-1);
    connector.setPort(PORT);
    server.setConnectors(new Connector[] { connector });
    WebAppContext bb = new WebAppContext();
    bb.setServer(server);
    bb.setContextPath(SOMEPATH);
    bb.setWar("src/test/webapp");
    server.setHandler(bb);
    CountDownLatch latch = new CountDownLatch(1);
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                LOGGER.info(">>> STARTING EMBEDDED JETTY SERVER for jUnit testing of SparkFilter");
                server.start();
                latch.countDown();
                System.in.read();
                LOGGER.info(">>> STOPPING EMBEDDED JETTY SERVER");
                server.stop();
                server.join();
            } catch (Exception e) {
                e.printStackTrace();
                System.exit(100);
            }
        }
    }).start();
    latch.await();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) Server(org.eclipse.jetty.server.Server) SparkTestUtil(spark.util.SparkTestUtil) CountDownLatch(java.util.concurrent.CountDownLatch) BeforeClass(org.junit.BeforeClass)

Example 34 with WebAppContext

use of org.eclipse.jetty.webapp.WebAppContext in project Synthese_2BIN by TheYoungSensei.

the class MyServer method main.

public static void main(String[] args) throws Exception {
    // lie le server � un port
    Server server = new Server(8000);
    // instancie un WebAppContext pour configurer le server
    WebAppContext context = new WebAppContext();
    // O� se trouvent les fichiers (ils seront servis par un DefaultServlet)
    context.setResourceBase("www");
    // MaServlet r�pondra aux requ�tes commen�ant par /chemin/
    context.addServlet(new ServletHolder(new MachineServlet()), "/Machine");
    // Le DefaultServlet sert des fichiers (html, js, css, images, ...). Il est en g�n�ral ajout� en dernier pour que les autres servlets soient prioritaires sur l�interpr�tation des URLs.
    context.addServlet(new ServletHolder(new DefaultServlet()), "/");
    // ce server utilise ce context
    server.setHandler(context);
    // allons-y
    server.start();
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) Server(org.eclipse.jetty.server.Server) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) DefaultServlet(org.eclipse.jetty.servlet.DefaultServlet)

Example 35 with WebAppContext

use of org.eclipse.jetty.webapp.WebAppContext in project jetty.project by eclipse.

the class Activator method start.

/**
     * 
     * @param context
     */
public void start(BundleContext context) throws Exception {
    //Create webappA as a Service and target it at the default server
    WebAppContext webapp = new WebAppContext();
    webapp.addServlet(new ServletHolder(new TestServlet()), "/mime");
    Dictionary props = new Hashtable();
    props.put("war", "webappA");
    props.put("contextPath", "/acme");
    props.put("managedServerName", "defaultJettyServer");
    _srA = context.registerService(WebAppContext.class.getName(), webapp, props);
    //Create a second webappB as a Service and target it at a custom Server
    //deployed by another bundle
    WebAppContext webappB = new WebAppContext();
    Dictionary propsB = new Hashtable();
    propsB.put("war", "webappB");
    propsB.put("contextPath", "/acme");
    propsB.put("managedServerName", "fooServer");
    _srB = context.registerService(WebAppContext.class.getName(), webappB, propsB);
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) Dictionary(java.util.Dictionary) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) Hashtable(java.util.Hashtable)

Aggregations

WebAppContext (org.eclipse.jetty.webapp.WebAppContext)291 Server (org.eclipse.jetty.server.Server)108 File (java.io.File)74 HandlerCollection (org.eclipse.jetty.server.handler.HandlerCollection)38 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)35 IOException (java.io.IOException)31 ServerConnector (org.eclipse.jetty.server.ServerConnector)31 DefaultHandler (org.eclipse.jetty.server.handler.DefaultHandler)31 Test (org.junit.Test)27 ArrayList (java.util.ArrayList)22 URL (java.net.URL)21 URISyntaxException (java.net.URISyntaxException)20 Handler (org.eclipse.jetty.server.Handler)17 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)17 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)15 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)15 WebXmlConfiguration (org.eclipse.jetty.webapp.WebXmlConfiguration)15 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)14 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)14 Resource (org.eclipse.jetty.util.resource.Resource)13