当前位置: 首页>>代码示例>>Java>>正文


Java GzipHandler.setHandler方法代码示例

本文整理汇总了Java中org.eclipse.jetty.server.handler.gzip.GzipHandler.setHandler方法的典型用法代码示例。如果您正苦于以下问题:Java GzipHandler.setHandler方法的具体用法?Java GzipHandler.setHandler怎么用?Java GzipHandler.setHandler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.jetty.server.handler.gzip.GzipHandler的用法示例。


在下文中一共展示了GzipHandler.setHandler方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createRestService

import org.eclipse.jetty.server.handler.gzip.GzipHandler; //导入方法依赖的package包/类
private Handler createRestService() {
    ResourceConfig rc = new ResourceConfig();
    rc.register(systemResource);
    rc.register(appResource);
    rc.register(JacksonFeature.class);
    rc.register(CORSFilter.class);
    SwaggerDocs.registerSwaggerJsonResource(rc);
    rc.addProperties(new HashMap<String,Object>() {{
        // Turn off buffering so results can be streamed
        put(ServerProperties.OUTBOUND_CONTENT_LENGTH_BUFFER, 0);
    }});

    ServletHolder holder = new ServletHolder(new ServletContainer(rc));

    ServletContextHandler sch = new ServletContextHandler();
    sch.setContextPath("/api/v1");
    sch.addServlet(holder, "/*");

    GzipHandler gzipHandler = new GzipHandler();
    gzipHandler.setHandler(sch);
    return gzipHandler;
}
 
开发者ID:danielflower,项目名称:app-runner,代码行数:23,代码来源:WebServer.java

示例2: JettyServer

import org.eclipse.jetty.server.handler.gzip.GzipHandler; //导入方法依赖的package包/类
public JettyServer(List<HttpServerConnectorCreator> connectors, List<Object> resources) {
        server=new org.eclipse.jetty.server.Server();
        currentConnectors.addAll(connectors);
        for (HttpServerConnectorCreator creator : currentConnectors) {
            creator.addToServer(server);
        }

        rootServlet = new UpdateableServlet(new ServletContainer(jerseySetup(resources)));
        ServletHolder holder = new ServletHolder(rootServlet);
        ServletContextHandler contextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
        contextHandler.addServlet( holder, "/*");
        ErrorHandler errorHandler = new ErrorHandler();
        errorHandler.setShowStacks(true);
        contextHandler.setErrorHandler(errorHandler);

        GzipHandler gzipHandler = new GzipHandler();
//            HashSet<String> mimeTypes = new HashSet<>();
//            mimeTypes.add("text/html");
//            mimeTypes.add("text/plain");
//            mimeTypes.add("text/css");
//            mimeTypes.add("application/x-javascript");
//            mimeTypes.add("application/json");
        gzipHandler.setMinGzipSize(0);

        gzipHandler.setHandler(contextHandler);

        HandlerCollection handlers = new HandlerList();
        additionalHandlers().forEach(handler -> handlers.addHandler(handler));
        handlers.addHandler(gzipHandler);
        server.setHandler(handlers);
    }
 
开发者ID:factoryfx,项目名称:factoryfx,代码行数:32,代码来源:JettyServer.java

示例3: getHandlerCollection

import org.eclipse.jetty.server.handler.gzip.GzipHandler; //导入方法依赖的package包/类
private HandlerCollection getHandlerCollection(
        ServerConfig serverConfig,
        ServletPathsConfig servletPathsConfig,
        ServletHolder jdiscServlet,
        ComponentRegistry<ServletHolder> servletHolders,
        FilterHolder jDiscFilterInvokerFilter,
        RequestLog requestLog) {

    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, "/*");

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

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

    RequestLogHandler requestLogHandler = new RequestLogHandler();
    requestLogHandler.setRequestLog(requestLog);

    HandlerCollection handlerCollection = new HandlerCollection();
    handlerCollection.setHandlers(new Handler[]{statisticsHandler, requestLogHandler});
    return handlerCollection;
}
 
开发者ID:vespa-engine,项目名称:vespa,代码行数:32,代码来源:JettyHttpServer.java

示例4: startImpl

import org.eclipse.jetty.server.handler.gzip.GzipHandler; //导入方法依赖的package包/类
protected String startImpl(ServletHolder holder, int port) throws Exception {
    holder.setInitOrder(0);

    {
        MultipartConfig multipartConfig = frontServletClass.getAnnotation(MultipartConfig.class);
        if (multipartConfig != null)

            holder.getRegistration().setMultipartConfig(new MultipartConfigElement(multipartConfig));
        else
            holder.getRegistration().setMultipartConfig(new MultipartConfigElement(""));
    }

    ServletContextHandler ctx = new ServletContextHandler(ServletContextHandler.SESSIONS);
    ctx.setContextPath("");
    ctx.addServlet(holder, "/*");

    ctx.setResourceBase(Paths.get("").toString());

    server = new Server();
    ServerConnector connector = new ServerConnector(server);
    connector.setPort(port);
    server.setConnectors(new Connector[] { connector });

    GzipHandler gzip = new GzipHandler();
    gzip.setHandler(ctx);
    server.setHandler(gzip);
    server.start();

    this.servlet = (FrontServletBase) holder.getServlet();

    String host = connector.getHost();
    if (host == null) {
        host = "localhost";
    }
    return String.format("http://%s:%d", host, connector.getLocalPort());
}
 
开发者ID:ruediste,项目名称:rise,代码行数:37,代码来源:RiseServer.java

示例5: getGzipHandler

import org.eclipse.jetty.server.handler.gzip.GzipHandler; //导入方法依赖的package包/类
private Handler getGzipHandler(Handler handler) {
    GzipHandler gzipHandler = new GzipHandler();
    gzipHandler.addIncludedMethods("GET", "POST", "PUT", "DELETE", "PATCH");
    gzipHandler.addIncludedPaths("/*");
    gzipHandler.setHandler(handler);
    return gzipHandler;
}
 
开发者ID:flipkart-incubator,项目名称:Poseidon,代码行数:8,代码来源:Poseidon.java

示例6: createHandlers

import org.eclipse.jetty.server.handler.gzip.GzipHandler; //导入方法依赖的package包/类
private HandlerCollection createHandlers() {
    final WebAppContext webApp = new WebAppContext();
    webApp.setContextPath(contextPath);
    webApp.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
    webApp.getSessionHandler().setMaxInactiveInterval(sessionTimeout * 60);

    // 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
    MovedContextHandler rootRedirect = new MovedContextHandler();
    rootRedirect.setContextPath("/");
    rootRedirect.setNewContextURL(contextPath);
    rootRedirect.setPermanent(true);

    // Put rootRedirect at the end!
    return new HandlerCollection(log, gzipHandler, rootRedirect);
}
 
开发者ID:apache,项目名称:cloudstack,代码行数:33,代码来源:ServerDaemon.java

示例7: getGzipHandler

import org.eclipse.jetty.server.handler.gzip.GzipHandler; //导入方法依赖的package包/类
private static Handler getGzipHandler(Handler wrapped) {
  GzipHandler gzip = new GzipHandler();
  gzip.addIncludedMethods(HttpMethod.POST);
  gzip.setHandler(wrapped);
  return gzip;
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:7,代码来源:JettyServerModule.java

示例8: enableGzip

import org.eclipse.jetty.server.handler.gzip.GzipHandler; //导入方法依赖的package包/类
/**
 * Wraps the whole web app in a gzip handler to make Jetty return compressed content
 *
 * http://www.eclipse.org/jetty/documentation/current/gzip-filter.html
 */
private Handler enableGzip(WebAppContext ctx) {
    GzipHandler gzipHandler = new GzipHandler();
    gzipHandler.setHandler(ctx);
    return gzipHandler;
}
 
开发者ID:RWTH-i5-IDSG,项目名称:steve-plugsurfing,代码行数:11,代码来源:SteveAppContext.java

示例9: gzipped

import org.eclipse.jetty.server.handler.gzip.GzipHandler; //导入方法依赖的package包/类
private Handler gzipped(Handler handler) {
    GzipHandler gzipHandler = new GzipHandler();
    gzipHandler.setHandler(handler);
    return gzipHandler;
}
 
开发者ID:danielflower,项目名称:app-runner-router,代码行数:6,代码来源:WebServer.java

示例10: start

import org.eclipse.jetty.server.handler.gzip.GzipHandler; //导入方法依赖的package包/类
public void start() {
        System.setProperty("java.net.preferIPv4Stack", "true");//TODO optional?

        server = new org.eclipse.jetty.server.Server();
//        HashSessionIdManager sessionIdManager = new HashSessionIdManager();
//        server.setSessionIdManager(sessionIdManager);

        connector = new NetworkTrafficServerConnector(server);
        connector.setPort(httpPort);
        connector.setHost(host);
        server.addConnector(connector);


        ServletContextHandler contextHandler = new ServletContextHandler();
        SessionHandler sessionHandler = new SessionHandler();
//        HashSessionManager sessionManager = new HashSessionManager();
//        sessionManager.setMaxInactiveInterval(sessionTimeoutS);
//        sessionManager.setSessionCookie(sessionManager.getSessionCookie()+httpPort); //avoid session mix up for 2 server running as localhost
//        sessionHandler.setSessionManager(sessionManager);


        contextHandler.setSessionHandler(sessionHandler);
        contextHandler.addServlet(new ServletHolder(new ServletContainer(jerseySetup(restResource))), "/applicationServer/*");

        ErrorHandler errorHandler = new ErrorHandler();
        errorHandler.setShowStacks(true);
        contextHandler.setErrorHandler(errorHandler);

        GzipHandler gzipHandler = new GzipHandler();
//            HashSet<String> mimeTypes = new HashSet<>();
//            mimeTypes.add("text/html");
//            mimeTypes.add("text/plain");
//            mimeTypes.add("text/css");
//            mimeTypes.add("application/x-javascript");
//            mimeTypes.add("application/json");
        gzipHandler.setMinGzipSize(0);
//            gzipHandler.setMimeTypes(mimeTypes);

        HandlerCollection handlers = new HandlerCollection();
        handlers.setHandlers(new Handler[]{resourceHandler, contextHandler});
        gzipHandler.setHandler(handlers);
        server.setHandler(gzipHandler);

        try {
            server.start();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
 
开发者ID:factoryfx,项目名称:factoryfx,代码行数:50,代码来源:HttpServer.java

示例11: main

import org.eclipse.jetty.server.handler.gzip.GzipHandler; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {

        try {
            // Set up the configuration
            configuration = new Configuration();

            // Create the Jetty server
            server = new Server(configuration.port);

            // Create the handlers
            mainHandler = new MainHandler();
            gzipHandler = new GzipHandler();
            gzipHandler.setHandler(mainHandler);

            // Select the handler to be used
            Handler handler;
            if (configuration.authenticationEnabled) {
                securityHandler = new BasicAuth();
                securityHandler.setHandler(gzipHandler);
                handler = securityHandler;
            } else {
                handler = gzipHandler;
            }

            // Graceful shutdown
            statisticsHandler = new StatisticsHandler();
            statisticsHandler.setHandler(handler);
            server.setHandler(statisticsHandler);
            Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        log.info("Initiating graceful shutdown...");
                        //server.getHandler().stop();
                        server.stop();
                        log.info("Shutdown completed gracefully.");
                    } catch (Exception e) {
                        log.info("Shutdown error:");
                        e.printStackTrace();
                    }
                }
            }));

            // And we're good to go
            server.start();
            System.out.println(configuration);
            log.info("Completed startup process.");
            server.join();

        } finally {
            ClassReloader.shutdown();
        }
    }
 
开发者ID:davidcarboni,项目名称:restolino,代码行数:54,代码来源:Main.java


注:本文中的org.eclipse.jetty.server.handler.gzip.GzipHandler.setHandler方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。