Java Code Examples for org.eclipse.jetty.server.handler.gzip.GzipHandler#setHandler()

The following examples show how to use org.eclipse.jetty.server.handler.gzip.GzipHandler#setHandler() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DremioServer.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
protected void addHandlers() {
  // root handler with request logging
  final RequestLogHandler rootHandler = new RequestLogHandler();
  embeddedJetty.insertHandler(rootHandler);
  RequestLogImpl_Jetty_Fix requestLogger = new RequestLogImpl_Jetty_Fix();
  requestLogger.setResource("/logback-access.xml");
  rootHandler.setRequestLog(requestLogger);

  // gzip handler.
  final GzipHandler gzipHandler = new GzipHandler();
  // gzip handler interferes with ChunkedOutput, so exclude the job download path
  gzipHandler.addExcludedPaths("/apiv2/job/*");
  rootHandler.setHandler(gzipHandler);

  // servlet handler for everything (to manage path mapping)
  servletContextHandler = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
  servletContextHandler.setContextPath("/");
  gzipHandler.setHandler(servletContextHandler);

  // error handler
  final ErrorHandler errorHandler = new ErrorHandler();
  errorHandler.setShowStacks(true);
  errorHandler.setShowMessageInTitle(true);
  embeddedJetty.setErrorHandler(errorHandler);
}
 
Example 2
Source File: TestServer.java    From webtau with Apache License 2.0 5 votes vote down vote up
public void start(int port) {
    server = new Server(port);

    GzipHandler gzipHandler = new GzipHandler();
    gzipHandler.setHandler(new RequestHandler());

    server.setHandler(gzipHandler);
    try {
        server.start();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 3
Source File: Poseidon.java    From Poseidon with Apache License 2.0 5 votes vote down vote up
private Handler getGzipHandler(Handler handler) {
    GzipHandler gzipHandler = new GzipHandler();
    gzipHandler.addIncludedMethods("GET", "POST", "PUT", "DELETE", "PATCH");
    gzipHandler.addIncludedPaths("/*");
    gzipHandler.setHandler(handler);
    return gzipHandler;
}
 
Example 4
Source File: ApplicationServer.java    From rest-utils with Apache License 2.0 5 votes vote down vote up
static Handler wrapWithGzipHandler(RestConfig config, Handler handler) {
  if (config.getBoolean(RestConfig.ENABLE_GZIP_COMPRESSION_CONFIG)) {
    GzipHandler gzip = new GzipHandler();
    gzip.setIncludedMethods("GET", "POST");
    gzip.setHandler(handler);
    return gzip;
  }
  return handler;
}
 
Example 5
Source File: AssetsContextHandler.java    From gocd with Apache License 2.0 5 votes vote down vote up
public AssetsContextHandler(SystemEnvironment systemEnvironment) {
    super(systemEnvironment.getWebappContextPath() + "/assets");
    this.systemEnvironment = systemEnvironment;
    handler = new AssetsHandler();

    GzipHandler gzipHandler = Jetty9Server.gzipHandler();
    gzipHandler.setHandler(this.handler);
    setHandler(gzipHandler);
}
 
Example 6
Source File: ServerDaemon.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
private Pair<SessionHandler,HandlerCollection> createHandlers() {
    final WebAppContext webApp = new WebAppContext();
    webApp.setContextPath(contextPath);
    webApp.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");

    // GZIP handler
    final GzipHandler gzipHandler = new GzipHandler();
    gzipHandler.addIncludedMimeTypes("text/html", "text/xml", "text/css", "text/plain", "text/javascript", "application/javascript", "application/json", "application/xml");
    gzipHandler.setIncludedMethods("GET", "POST");
    gzipHandler.setCompressionLevel(9);
    gzipHandler.setHandler(webApp);

    if (Strings.isNullOrEmpty(webAppLocation)) {
        webApp.setWar(getShadedWarUrl());
    } else {
        webApp.setWar(webAppLocation);
    }

    // Request log handler
    final RequestLogHandler log = new RequestLogHandler();
    log.setRequestLog(createRequestLog());

    // Redirect root context handler_war
    MovedContextHandler rootRedirect = new MovedContextHandler();
    rootRedirect.setContextPath("/");
    rootRedirect.setNewContextURL(contextPath);
    rootRedirect.setPermanent(true);

    // Put rootRedirect at the end!
    return new Pair<>(webApp.getSessionHandler(), new HandlerCollection(log, gzipHandler, rootRedirect));
}
 
Example 7
Source File: FuzzerServer.java    From graphicsfuzz with Apache License 2.0 4 votes vote down vote up
public void start() throws Exception {

    FuzzerServiceImpl fuzzerService = new FuzzerServiceImpl(
        Paths.get(workingDir, processingDir).toString(),
        executorService);

    FuzzerService.Processor processor =
        new FuzzerService.Processor<FuzzerService.Iface>(fuzzerService);

    FuzzerServiceManagerImpl fuzzerServiceManager = new FuzzerServiceManagerImpl(fuzzerService,
          new PublicServerCommandDispatcher());
    FuzzerServiceManager.Processor managerProcessor =
        new FuzzerServiceManager.Processor<FuzzerServiceManager.Iface>(fuzzerServiceManager);

    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setContextPath("/");

    {
      ServletHolder sh = new ServletHolder();
      sh.setServlet(new TServlet(processor, new TBinaryProtocol.Factory()));
      context.addServlet(sh, "/request");
    }
    {
      ServletHolder serveltHolderJson = new ServletHolder();
      serveltHolderJson.setServlet(new TServlet(processor, new TJSONProtocol.Factory()));
      context.addServlet(serveltHolderJson, "/requestJSON");
    }

    {
      ServletHolder shManager = new ServletHolder();
      shManager.setServlet(new TServlet(managerProcessor, new TBinaryProtocol.Factory()));
      context.addServlet(shManager, "/manageAPI");
    }

    final String staticDir = ToolPaths.getStaticDir();
    context.addServlet(
          new ServletHolder(
                new FileDownloadServlet(
                    (pathInfo, worker) -> Paths.get(staticDir, pathInfo).toFile(), staticDir)),
          "/static/*");

    HandlerList handlerList = new HandlerList();
    handlerList.addHandler(context);

    GzipHandler gzipHandler = new GzipHandler();
    gzipHandler.setHandler(handlerList);

    Server server = new Server(port);

    server.setHandler(gzipHandler);
    server.start();
    server.join();
  }
 
Example 8
Source File: FuzzerServer.java    From graphicsfuzz with Apache License 2.0 4 votes vote down vote up
public void start() throws Exception {

    FuzzerServiceImpl fuzzerService = new FuzzerServiceImpl(
        Paths.get(workingDir, processingDir).toString(),
        executorService);

    FuzzerService.Processor processor =
        new FuzzerService.Processor<FuzzerService.Iface>(fuzzerService);

    FuzzerServiceManagerImpl fuzzerServiceManager = new FuzzerServiceManagerImpl(fuzzerService,
          new GraphicsFuzzServerCommandDispatcher());
    FuzzerServiceManager.Processor managerProcessor =
        new FuzzerServiceManager.Processor<FuzzerServiceManager.Iface>(fuzzerServiceManager);

    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setContextPath("/");

    {
      ServletHolder sh = new ServletHolder();
      sh.setServlet(new TServlet(processor, new TBinaryProtocol.Factory()));
      context.addServlet(sh, "/request");
    }
    {
      ServletHolder serveltHolderJson = new ServletHolder();
      serveltHolderJson.setServlet(new TServlet(processor, new TJSONProtocol.Factory()));
      context.addServlet(serveltHolderJson, "/requestJSON");
    }

    {
      ServletHolder shManager = new ServletHolder();
      shManager.setServlet(new TServlet(managerProcessor, new TBinaryProtocol.Factory()));
      context.addServlet(shManager, "/manageAPI");
    }

    context.addServlet(new ServletHolder(new WebUi(fuzzerServiceManager, fileOps)), "/webui/*");

    final String staticDir = ToolPaths.getStaticDir();
    context.addServlet(
        new ServletHolder(
            new FileDownloadServlet(
                (pathInfo, workerName) -> Paths.get(staticDir, pathInfo).toFile(), staticDir)),
        "/static/*");

    HandlerList handlerList = new HandlerList();
    handlerList.addHandler(context);

    GzipHandler gzipHandler = new GzipHandler();
    gzipHandler.setHandler(handlerList);

    Server server = new Server(port);

    server.setHandler(gzipHandler);
    server.start();
    server.join();
  }
 
Example 9
Source File: CenterServerTools.java    From o2oa with GNU Affero General Public License v3.0 4 votes vote down vote up
public static Server start(CenterServer centerServer) throws Exception {

		cleanWorkDirectory();

		HandlerList handlers = new HandlerList();

		File war = new File(Config.dir_store(), x_program_center.class.getSimpleName() + ".war");
		File dir = new File(Config.dir_servers_centerServer_work(true), x_program_center.class.getSimpleName());
		if (war.exists()) {
			modified(war, dir);
			QuickStartWebApp webApp = new QuickStartWebApp();
			webApp.setAutoPreconfigure(false);
			webApp.setDisplayName(x_program_center.class.getSimpleName());
			webApp.setContextPath("/" + x_program_center.class.getSimpleName());
			webApp.setResourceBase(dir.getAbsolutePath());
			webApp.setDescriptor(new File(dir, "WEB-INF/web.xml").getAbsolutePath());
			webApp.setExtraClasspath(calculateExtraClassPath(x_program_center.class));
			webApp.getInitParams().put("org.eclipse.jetty.servlet.Default.useFileMappedBuffer", "false");
			webApp.getInitParams().put("org.eclipse.jetty.jsp.precompiled", "true");
			webApp.getInitParams().put("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
			/* stat */
			if (centerServer.getStatEnable()) {
				FilterHolder statFilterHolder = new FilterHolder(new WebStatFilter());
				statFilterHolder.setInitParameter("exclusions", centerServer.getStatExclusions());
				webApp.addFilter(statFilterHolder, "/*", EnumSet.of(DispatcherType.REQUEST));
				ServletHolder statServletHolder = new ServletHolder(StatViewServlet.class);
				statServletHolder.setInitParameter("sessionStatEnable", "false");
				webApp.addServlet(statServletHolder, "/druid/*");
			}
			/* stat end */
			handlers.addHandler(webApp);
		} else {
			throw new Exception("centerServer war not exist.");
		}

		QueuedThreadPool threadPool = new QueuedThreadPool();
		threadPool.setMinThreads(CENTERSERVER_THREAD_POOL_SIZE_MIN);
		threadPool.setMaxThreads(CENTERSERVER_THREAD_POOL_SIZE_MAX);
		Server server = new Server(threadPool);
		server.setAttribute("maxFormContentSize", centerServer.getMaxFormContent() * 1024 * 1024);

		if (centerServer.getSslEnable()) {
			addHttpsConnector(server, centerServer.getPort());
		} else {
			addHttpConnector(server, centerServer.getPort());
		}

		GzipHandler gzipHandler = new GzipHandler();
		gzipHandler.setHandler(handlers);
		server.setHandler(gzipHandler);

		server.setDumpAfterStart(false);
		server.setDumpBeforeStop(false);
		server.setStopAtShutdown(true);

		server.start();
		Thread.sleep(1000);
		System.out.println("****************************************");
		System.out.println("* center server start completed.");
		System.out.println("* port: " + centerServer.getPort() + ".");
		System.out.println("****************************************");
		return server;
	}
 
Example 10
Source File: JettyHttpServer.java    From vespa with Apache License 2.0 4 votes vote down vote up
private HandlerCollection getHandlerCollection(
        ServerConfig serverConfig,
        ServletPathsConfig servletPathsConfig,
        List<JDiscServerConnector> connectors,
        ServletHolder jdiscServlet,
        ComponentRegistry<ServletHolder> servletHolders,
        FilterHolder jDiscFilterInvokerFilter) {

    ServletContextHandler servletContextHandler = createServletContextHandler();

    servletHolders.allComponentsById().forEach((id, servlet) -> {
        String path = getServletPath(servletPathsConfig, id);
        servletContextHandler.addServlet(servlet, path);
        servletContextHandler.addFilter(jDiscFilterInvokerFilter, path, EnumSet.allOf(DispatcherType.class));
    });

    servletContextHandler.addServlet(jdiscServlet, "/*");

    List<ConnectorConfig> connectorConfigs = connectors.stream().map(JDiscServerConnector::connectorConfig).collect(toList());
    var secureRedirectHandler = new SecuredRedirectHandler(connectorConfigs);
    secureRedirectHandler.setHandler(servletContextHandler);

    var proxyHandler = new HealthCheckProxyHandler(connectors);
    proxyHandler.setHandler(secureRedirectHandler);

    var authEnforcer = new TlsClientAuthenticationEnforcer(connectorConfigs);
    authEnforcer.setHandler(proxyHandler);

    GzipHandler gzipHandler = newGzipHandler(serverConfig);
    gzipHandler.setHandler(authEnforcer);

    HttpResponseStatisticsCollector statisticsCollector = new HttpResponseStatisticsCollector(serverConfig.metric().monitoringHandlerPaths());
    statisticsCollector.setHandler(gzipHandler);

    StatisticsHandler statisticsHandler = newStatisticsHandler();
    statisticsHandler.setHandler(statisticsCollector);

    HandlerCollection handlerCollection = new HandlerCollection();
    handlerCollection.setHandlers(new Handler[] { statisticsHandler });
    return handlerCollection;
}
 
Example 11
Source File: JettyServerModule.java    From attic-aurora with Apache License 2.0 4 votes vote down vote up
private static Handler getGzipHandler(Handler wrapped) {
  GzipHandler gzip = new GzipHandler();
  gzip.addIncludedMethods(HttpMethod.POST);
  gzip.setHandler(wrapped);
  return gzip;
}