本文整理汇总了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;
}
示例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);
}
示例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;
}
示例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());
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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();
}
}