Search in sources :

Example 6 with DefaultServlet

use of org.eclipse.jetty.servlet.DefaultServlet 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 7 with DefaultServlet

use of org.eclipse.jetty.servlet.DefaultServlet in project jena by apache.

the class SPARQLServer method addContent.

private static void addContent(ServletContextHandler context, String pathSpec, String pages) {
    DefaultServlet staticServlet = new DefaultServlet();
    ServletHolder staticContent = new ServletHolder(staticServlet);
    staticContent.setInitParameter("resourceBase", pages);
    // Note we set GZip to false for static content because the Jetty
    // DefaultServlet has
    // a built-in GZip capability that is better for static content than the
    // mechanism the
    // GzipFilter uses for dynamic content
    addServlet(context, staticContent, pathSpec, false);
}
Also used : ServletHolder(org.eclipse.jetty.servlet.ServletHolder) DefaultServlet(org.eclipse.jetty.servlet.DefaultServlet)

Example 8 with DefaultServlet

use of org.eclipse.jetty.servlet.DefaultServlet in project samza by apache.

the class TestYarnContainerHeartbeatServlet method setup.

@Before
public void setup() throws Exception {
    container = mock(YarnContainer.class);
    ReadableMetricsRegistry registry = new MetricsRegistryMap("test-registry");
    yarnAppState = new YarnAppState(-1, ConverterUtils.toContainerId("container_1350670447861_0003_01_000001"), "testHost", 1, 1);
    webApp = new HttpServer("/", 0, "", new ServletHolder(new DefaultServlet()));
    webApp.addServlet("/", new YarnContainerHeartbeatServlet(yarnAppState, registry));
    webApp.start();
    mapper = new ObjectMapper();
}
Also used : ReadableMetricsRegistry(org.apache.samza.metrics.ReadableMetricsRegistry) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) YarnAppState(org.apache.samza.job.yarn.YarnAppState) HttpServer(org.apache.samza.coordinator.server.HttpServer) YarnContainer(org.apache.samza.job.yarn.YarnContainer) DefaultServlet(org.eclipse.jetty.servlet.DefaultServlet) MetricsRegistryMap(org.apache.samza.metrics.MetricsRegistryMap) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Before(org.junit.Before)

Example 9 with DefaultServlet

use of org.eclipse.jetty.servlet.DefaultServlet in project camel by apache.

the class WebsocketComponent method createStaticResourcesServer.

protected Server createStaticResourcesServer(Server server, ServletContextHandler context, String home) throws Exception {
    context.setContextPath("/");
    SessionHandler sh = new SessionHandler();
    context.setSessionHandler(sh);
    if (home != null) {
        String[] resources = home.split(":");
        if (LOG.isDebugEnabled()) {
            LOG.debug(">>> Protocol found: " + resources[0] + ", and resource: " + resources[1]);
        }
        if (resources[0].equals("classpath")) {
            context.setBaseResource(new JettyClassPathResource(getCamelContext().getClassResolver(), resources[1]));
        } else if (resources[0].equals("file")) {
            context.setBaseResource(Resource.newResource(resources[1]));
        }
        DefaultServlet defaultServlet = new DefaultServlet();
        ServletHolder holder = new ServletHolder(defaultServlet);
        // avoid file locking on windows
        // http://stackoverflow.com/questions/184312/how-to-make-jetty-dynamically-load-static-pages
        holder.setInitParameter("useFileMappedBuffer", "false");
        context.addServlet(holder, "/");
    }
    server.setHandler(context);
    return server;
}
Also used : SessionHandler(org.eclipse.jetty.server.session.SessionHandler) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) DefaultServlet(org.eclipse.jetty.servlet.DefaultServlet)

Example 10 with DefaultServlet

use of org.eclipse.jetty.servlet.DefaultServlet in project zeppelin by apache.

the class ZeppelinServer method setupWebAppContext.

private static WebAppContext setupWebAppContext(ContextHandlerCollection contexts, ZeppelinConfiguration conf) {
    WebAppContext webApp = new WebAppContext();
    webApp.setContextPath(conf.getServerContextPath());
    File warPath = new File(conf.getString(ConfVars.ZEPPELIN_WAR));
    if (warPath.isDirectory()) {
        // Development mode, read from FS
        // webApp.setDescriptor(warPath+"/WEB-INF/web.xml");
        webApp.setResourceBase(warPath.getPath());
        webApp.setParentLoaderPriority(true);
    } else {
        // use packaged WAR
        webApp.setWar(warPath.getAbsolutePath());
        File warTempDirectory = new File(conf.getRelativeDir(ConfVars.ZEPPELIN_WAR_TEMPDIR));
        warTempDirectory.mkdir();
        LOG.info("ZeppelinServer Webapp path: {}", warTempDirectory.getPath());
        webApp.setTempDirectory(warTempDirectory);
    }
    // Explicit bind to root
    webApp.addServlet(new ServletHolder(new DefaultServlet()), "/*");
    contexts.addHandler(webApp);
    webApp.addFilter(new FilterHolder(CorsFilter.class), "/*", EnumSet.allOf(DispatcherType.class));
    webApp.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", Boolean.toString(conf.getBoolean(ConfVars.ZEPPELIN_SERVER_DEFAULT_DIR_ALLOWED)));
    return webApp;
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) FilterHolder(org.eclipse.jetty.servlet.FilterHolder) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) DefaultServlet(org.eclipse.jetty.servlet.DefaultServlet) DispatcherType(javax.servlet.DispatcherType) File(java.io.File)

Aggregations

DefaultServlet (org.eclipse.jetty.servlet.DefaultServlet)12 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)11 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)6 HandlerList (org.eclipse.jetty.server.handler.HandlerList)4 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)4 File (java.io.File)3 Server (org.eclipse.jetty.server.Server)3 DefaultHandler (org.eclipse.jetty.server.handler.DefaultHandler)2 FilterHolder (org.eclipse.jetty.servlet.FilterHolder)2 CertificateAndKey (com.fathomdb.crypto.CertificateAndKey)1 GuiceFilter (com.google.inject.servlet.GuiceFilter)1 KeyStore (java.security.KeyStore)1 HashSet (java.util.HashSet)1 SSLContext (javax.net.ssl.SSLContext)1 DispatcherType (javax.servlet.DispatcherType)1 HttpServer (org.apache.samza.coordinator.server.HttpServer)1 YarnAppState (org.apache.samza.job.yarn.YarnAppState)1 YarnContainer (org.apache.samza.job.yarn.YarnContainer)1 MetricsRegistryMap (org.apache.samza.metrics.MetricsRegistryMap)1 ReadableMetricsRegistry (org.apache.samza.metrics.ReadableMetricsRegistry)1