Search in sources :

Example 91 with ServletHolder

use of org.eclipse.jetty.servlet.ServletHolder in project druid by druid-io.

the class MiddleManagerJettyServerInitializer method initialize.

@Override
public void initialize(Server server, Injector injector) {
    final ServletContextHandler root = new ServletContextHandler(ServletContextHandler.SESSIONS);
    root.addServlet(new ServletHolder(new DefaultServlet()), "/*");
    JettyServerInitUtils.addExtensionFilters(root, injector);
    root.addFilter(GuiceFilter.class, "/*", null);
    final HandlerList handlerList = new HandlerList();
    handlerList.setHandlers(new Handler[] { JettyServerInitUtils.getJettyRequestLogHandler(), JettyServerInitUtils.wrapWithDefaultGzipHandler(root), new DefaultHandler() });
    server.setHandler(handlerList);
}
Also used : HandlerList(org.eclipse.jetty.server.handler.HandlerList) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) DefaultServlet(org.eclipse.jetty.servlet.DefaultServlet) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler)

Example 92 with ServletHolder

use of org.eclipse.jetty.servlet.ServletHolder in project druid by druid-io.

the class QueryJettyServerInitializer method initialize.

@Override
public void initialize(Server server, Injector injector) {
    final ServletContextHandler root = new ServletContextHandler(ServletContextHandler.SESSIONS);
    root.addServlet(new ServletHolder(new DefaultServlet()), "/*");
    JettyServerInitUtils.addExtensionFilters(root, injector);
    root.addFilter(GuiceFilter.class, "/*", null);
    final HandlerList handlerList = new HandlerList();
    final Handler[] handlers = new Handler[extensionHandlers.size() + 2];
    handlers[0] = JettyServerInitUtils.getJettyRequestLogHandler();
    handlers[handlers.length - 1] = JettyServerInitUtils.wrapWithDefaultGzipHandler(root);
    for (int i = 0; i < extensionHandlers.size(); i++) {
        handlers[i + 1] = extensionHandlers.get(i);
    }
    handlerList.setHandlers(handlers);
    server.setHandler(handlerList);
}
Also used : HandlerList(org.eclipse.jetty.server.handler.HandlerList) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) Handler(org.eclipse.jetty.server.Handler) DefaultServlet(org.eclipse.jetty.servlet.DefaultServlet) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 93 with ServletHolder

use of org.eclipse.jetty.servlet.ServletHolder in project druid by druid-io.

the class RouterJettyServerInitializer method initialize.

@Override
public void initialize(Server server, Injector injector) {
    final ServletContextHandler root = new ServletContextHandler(ServletContextHandler.SESSIONS);
    root.addServlet(new ServletHolder(new DefaultServlet()), "/*");
    asyncQueryForwardingServlet.setTimeout(httpClientConfig.getReadTimeout().getMillis());
    ServletHolder sh = new ServletHolder(asyncQueryForwardingServlet);
    //NOTE: explicit maxThreads to workaround https://tickets.puppetlabs.com/browse/TK-152
    sh.setInitParameter("maxThreads", Integer.toString(httpClientConfig.getNumMaxThreads()));
    root.addServlet(sh, "/druid/v2/*");
    JettyServerInitUtils.addExtensionFilters(root, injector);
    // Can't use '/*' here because of Guice conflicts with AsyncQueryForwardingServlet path
    root.addFilter(GuiceFilter.class, "/status/*", null);
    final HandlerList handlerList = new HandlerList();
    handlerList.setHandlers(new Handler[] { JettyServerInitUtils.getJettyRequestLogHandler(), JettyServerInitUtils.wrapWithDefaultGzipHandler(root) });
    server.setHandler(handlerList);
}
Also used : HandlerList(org.eclipse.jetty.server.handler.HandlerList) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) DefaultServlet(org.eclipse.jetty.servlet.DefaultServlet) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 94 with ServletHolder

use of org.eclipse.jetty.servlet.ServletHolder in project druid by druid-io.

the class CoordinatorJettyServerInitializer method initialize.

@Override
public void initialize(Server server, Injector injector) {
    final ServletContextHandler root = new ServletContextHandler(ServletContextHandler.SESSIONS);
    root.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
    ServletHolder holderPwd = new ServletHolder("default", DefaultServlet.class);
    root.addServlet(holderPwd, "/");
    if (config.getConsoleStatic() == null) {
        ResourceCollection staticResources;
        if (beOverlord) {
            staticResources = new ResourceCollection(Resource.newClassPathResource("io/druid/console"), Resource.newClassPathResource("static"), Resource.newClassPathResource("indexer_static"));
        } else {
            staticResources = new ResourceCollection(Resource.newClassPathResource("io/druid/console"), Resource.newClassPathResource("static"));
        }
        root.setBaseResource(staticResources);
    } else {
        // used for console development
        root.setResourceBase(config.getConsoleStatic());
    }
    JettyServerInitUtils.addExtensionFilters(root, injector);
    // /status should not redirect, so add first
    root.addFilter(GuiceFilter.class, "/status/*", null);
    // redirect anything other than status to the current lead
    root.addFilter(new FilterHolder(injector.getInstance(RedirectFilter.class)), "/*", null);
    // The coordinator really needs a standarized api path
    // Can't use '/*' here because of Guice and Jetty static content conflicts
    root.addFilter(GuiceFilter.class, "/info/*", null);
    root.addFilter(GuiceFilter.class, "/druid/coordinator/*", null);
    if (beOverlord) {
        root.addFilter(GuiceFilter.class, "/druid/indexer/*", null);
    }
    // this will be removed in the next major release
    root.addFilter(GuiceFilter.class, "/coordinator/*", null);
    if (!beOverlord) {
        root.addServlet(new ServletHolder(injector.getInstance(OverlordProxyServlet.class)), "/druid/indexer/*");
    }
    HandlerList handlerList = new HandlerList();
    handlerList.setHandlers(new Handler[] { JettyServerInitUtils.getJettyRequestLogHandler(), JettyServerInitUtils.wrapWithDefaultGzipHandler(root) });
    server.setHandler(handlerList);
}
Also used : HandlerList(org.eclipse.jetty.server.handler.HandlerList) FilterHolder(org.eclipse.jetty.servlet.FilterHolder) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) ResourceCollection(org.eclipse.jetty.util.resource.ResourceCollection)

Example 95 with ServletHolder

use of org.eclipse.jetty.servlet.ServletHolder 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)

Aggregations

ServletHolder (org.eclipse.jetty.servlet.ServletHolder)287 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)158 Server (org.eclipse.jetty.server.Server)111 Test (org.junit.Test)77 FilterHolder (org.eclipse.jetty.servlet.FilterHolder)46 ServerConnector (org.eclipse.jetty.server.ServerConnector)45 HttpServletRequest (javax.servlet.http.HttpServletRequest)38 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)25 HttpClient (org.eclipse.jetty.client.HttpClient)23 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)23 IOException (java.io.IOException)22 CountDownLatch (java.util.concurrent.CountDownLatch)22 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)22 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)19 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)18 DefaultServlet (org.eclipse.jetty.servlet.DefaultServlet)18 HttpServletResponse (javax.servlet.http.HttpServletResponse)17 BeforeClass (org.junit.BeforeClass)17 File (java.io.File)15 ServletException (javax.servlet.ServletException)15