Package org.eclipse.jetty.servlet

Examples of org.eclipse.jetty.servlet.ServletContextHandler$Context


  public Server getServer(final Injector injector, Connector connector) {
    WebServerConfig webServerConfig = injector.getInstance(WebServerConfig.class);
    String staticDir = webServerConfig.getStaticDirectory();
    Server server = new Server();
    server.addConnector(connector);
    ServletContextHandler servletHandler = new ServletContextHandler();
    servletHandler.addEventListener(new GuiceServletContextListener() {
      @Override
      protected Injector getInjector() {
        return injector;
      }
    });

    servletHandler.setSecurityHandler(makeSecurityHandler(System.getenv("beaker_plugin_password")));
    servletHandler.addFilter(GuiceFilter.class, "/*", null);
    servletHandler.addServlet(DefaultServlet.class, "/*");
    servletHandler.setInitParameter("org.eclipse.jetty.servlet.Default.resourceBase", staticDir);
    servletHandler.setInitParameter("maxCacheSize", "0");
    servletHandler.setInitParameter("cacheControl", "no-cache, max-age=0");

    server.setHandler(servletHandler);

    return server;
  }
View Full Code Here


        // testing easier (you can just reload old tab after restarting proxy)
        // connector.setPort(8889);
        server.setConnectors(new Connector[] { connector });

        // Create root context and add the ProxyServlet.Transparent to it
        ServletContextHandler contextHandler = new ServletContextHandler();
        server.setHandler(contextHandler);
        contextHandler.setContextPath("/");
        ServletHolder servletHolder = contextHandler.addServlet(
                ProxyServlet.Transparent.class, "/*");

        // Configure servlet to forward to the root of the original server
        servletHolder.setInitParameter(
                "ProxyTo",
View Full Code Here

  public Server getServer(final Injector injector, Connector connector) {
    WebServerConfig webServerConfig = injector.getInstance(WebServerConfig.class);
    String staticDir = webServerConfig.getStaticDirectory();
    Server server = new Server();
    server.addConnector(connector);
    ServletContextHandler servletHandler = new ServletContextHandler();
    servletHandler.addEventListener(new GuiceServletContextListener() {
      @Override
      protected Injector getInjector() {
        return injector;
      }
    });

    servletHandler.setSecurityHandler(makeSecurityHandler(webServerConfig.getPassword()));
    servletHandler.addFilter(GuiceFilter.class, "/*", null);
    servletHandler.addServlet(DefaultServlet.class, "/*");
    servletHandler.setInitParameter("org.eclipse.jetty.servlet.Default.resourceBase", staticDir);
    servletHandler.setInitParameter("maxCacheSize", "0");
    servletHandler.setInitParameter("cacheControl", "no-cache, max-age=0");

    server.setHandler(servletHandler);

    return server;
  }
View Full Code Here

    }

    ContextHandlerCollection contexts = new ContextHandlerCollection();

    {
      ServletContextHandler context = new ServletContextHandler(contexts, "/api");
      // context.setContextPath("/");
      context.addEventListener(guiceServletConfig);

      // Must add DefaultServlet for embedded Jetty
      // Failing to do this will cause 404 errors.
      context.addServlet(DefaultServlet.class, "/");

      FilterHolder filterHolder = new FilterHolder(GuiceFilter.class);
      context.addFilter(filterHolder, "*", EnumSet.of(DispatcherType.REQUEST));

      context.setClassLoader(Thread.currentThread().getContextClassLoader());
    }

    for (Entry<String, File> entry : wars.entrySet()) {
      String contextPath = entry.getKey();
      File war = entry.getValue();

      WebAppContext context = new WebAppContext();
      context.setWar(war.getAbsolutePath());
      context.setContextPath(contextPath);

      context.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");

      context.addFilter(GwtCacheHeaderFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));

      contexts.addHandler(context);
    }

    server.setHandler(contexts);
View Full Code Here

        final Connector connector = new ServerConnector(server,
                                                        new InstrumentedConnectionFactory(new HttpConnectionFactory(),
                                                                                          REGISTRY.timer("http.connection")));
        server.addConnector(connector);

        final ServletContextHandler context = new ServletContextHandler();
        context.setContextPath("/initial");
        context.setAttribute(MetricsServlet.METRICS_REGISTRY, REGISTRY);
        context.setAttribute(HealthCheckServlet.HEALTH_CHECK_REGISTRY, new HealthCheckRegistry());

        final ServletHolder holder = new ServletHolder(new AdminServlet());
        context.addServlet(holder, "/dingo/*");

        final InstrumentedHandler handler = new InstrumentedHandler(REGISTRY);
        handler.setHandler(context);
        server.setHandler(handler);
       
View Full Code Here

      server.setConnectors(new Connector[] { http, https });

      // Serve via servlet
      final EnumSet<DispatcherType> dispatchers = EnumSet.range(
          DispatcherType.FORWARD, DispatcherType.ERROR);
      final ServletContextHandler context = new ServletContextHandler(
          ServletContextHandler.SESSIONS
              | ServletContextHandler.SECURITY);

      // final SessionIdManager idManager = new HashSessionIdManager();
      // final SessionManager sessionManager = new HashSessionManager();
      // SessionHandler sessionHandler = new
      // SessionHandler(sessionManager);
      // sessionManager.setSessionIdManager(idManager);
      // sessionManager.setSessionHandler(sessionHandler);
      // handler.setSessionHandler(sessionHandler);

      context.setContextPath("/");
      final FilterHolder fh = new FilterHolder(WebFilter.class);
      // let the filter know who to use to auto authenticate against when
      // accessed by host machine
      fh.setInitParameter(ActorType.ID.name(),
          String.valueOf(actorExtractor.extract().getId()));
      context.addFilter(fh, "/*", dispatchers);
      final ServletHolder sh = new ServletHolder(
          UGateWebSocketServlet.class);
      context.addServlet(sh,
          "/" + UGateWebSocketServlet.class.getSimpleName());
      final ServletHolder sh2 = new ServletHolder(
          UGateAjaxUpdaterServlet.class);
      context.addServlet(sh2, "/*");
      context.setErrorHandler(new ErrorHandler() {
        @Override
        public void handle(String target, Request baseRequest,
            HttpServletRequest request, HttpServletResponse response)
            throws IOException {
          // delegate errors to the filter
View Full Code Here

  public MockWebService(int docsPerLevel, int maxLevels, boolean generateBadPages)
  {
    server = new Server(8191);
    server.setThreadPool(new QueuedThreadPool(100));
    servlet = new WebServlet(docsPerLevel, maxLevels, generateBadPages);
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setContextPath("/web");
    server.setHandler(context);
    context.addServlet(new ServletHolder(servlet), "/gen.php");
  }
View Full Code Here

            //server.addBean(mbContainer);
        }
    }

    private void enableSessionSupport(Server server, String connectorKey) throws Exception {
        ServletContextHandler context = server.getChildHandlerByClass(ServletContextHandler.class);
        if (context.getSessionHandler() == null) {
            SessionHandler sessionHandler = new SessionHandler();
            if (context.isStarted()) {
                throw new IllegalStateException("Server has already been started. Cannot enabled sessionSupport on " + connectorKey);
            } else {
                context.setSessionHandler(sessionHandler);
            }
        }
    }
View Full Code Here

            }
        }
    }
   
    private void setFilters(JettyHttpEndpoint endpoint, Server server, String connectorKey) {
        ServletContextHandler context = server.getChildHandlerByClass(ServletContextHandler.class);
        List<Filter> filters = endpoint.getFilters();
        for (Filter filter : filters) {
            FilterHolder filterHolder = new FilterHolder();
            filterHolder.setFilter(new CamelFilterWrapper(filter));
            String pathSpec = endpoint.getPath();
View Full Code Here

    private void addFilter(ServletContextHandler context, FilterHolder filterHolder, String pathSpec) {
        context.getServletHandler().addFilterWithMapping(filterHolder, pathSpec, 0);
    }

    private void enableMultipartFilter(HttpEndpoint endpoint, Server server, String connectorKey) throws Exception {
        ServletContextHandler context = server.getChildHandlerByClass(ServletContextHandler.class);
        CamelContext camelContext = this.getCamelContext();
        FilterHolder filterHolder = new FilterHolder();
        filterHolder.setInitParameter("deleteFiles", "true");
        if (ObjectHelper.isNotEmpty(camelContext.getProperty(TMP_DIR))) {
            File file = new File(camelContext.getProperty(TMP_DIR));
            if (!file.isDirectory()) {
                throw new RuntimeCamelException(
                        "The temp file directory of camel-jetty is not exists, please recheck it with directory name :"
                                + camelContext.getProperties().get(TMP_DIR));
            }
            context.setAttribute("javax.servlet.context.tempdir", file);
        }
        // if a filter ref was provided, use it.
        Filter filter = ((JettyHttpEndpoint) endpoint).getMultipartFilter();
        if (filter == null) {
            // if no filter ref was provided, use the default filter
View Full Code Here

TOP

Related Classes of org.eclipse.jetty.servlet.ServletContextHandler$Context

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.