本文整理汇总了Java中org.eclipse.jetty.server.handler.gzip.GzipHandler类的典型用法代码示例。如果您正苦于以下问题:Java GzipHandler类的具体用法?Java GzipHandler怎么用?Java GzipHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GzipHandler类属于org.eclipse.jetty.server.handler.gzip包,在下文中一共展示了GzipHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setGzipHandler
import org.eclipse.jetty.server.handler.gzip.GzipHandler; //导入依赖的package包/类
/**
* @param gzipHandler The {@link GzipHandler} to set on this context.
*/
public void setGzipHandler(GzipHandler gzipHandler)
{
if (isStarted())
throw new IllegalStateException("STARTED");
Handler next=null;
if (_gzipHandler!=null)
{
next=_gzipHandler.getHandler();
_gzipHandler.setHandler(null);
replaceHandler(_gzipHandler,gzipHandler);
}
_gzipHandler = gzipHandler;
if (next!=null && _gzipHandler.getHandler()==null)
_gzipHandler.setHandler(next);
relinkHandlers();
}
示例2: addStaticResourceConfig
import org.eclipse.jetty.server.handler.gzip.GzipHandler; //导入依赖的package包/类
private void addStaticResourceConfig(ServletContextHandler context) {
URL webappLocation = getClass().getResource("/webapp/index.html");
if (webappLocation == null) {
System.err.println("Couldn't get webapp location.");
} else {
try {
URI webRootUri = URI.create(webappLocation.toURI().toASCIIString().replaceFirst("/index.html$", "/"));
context.setBaseResource(Resource.newResource(webRootUri));
context.setWelcomeFiles(new String[]{"index.html"});
GzipHandler gzipHandler = new GzipHandler();
gzipHandler.setIncludedMethods(HttpMethod.GET.name(), HttpMethod.POST.name(), HttpMethod.PUT.name());
context.setGzipHandler(gzipHandler);
context.addFilter(TryFilesFilter.class, "*", EnumSet.of(DispatcherType.REQUEST));
} catch (URISyntaxException | MalformedURLException e) {
e.printStackTrace();
}
}
}
示例3: 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;
}
示例4: jettyEmbeddedServletContainerFactory
import org.eclipse.jetty.server.handler.gzip.GzipHandler; //导入依赖的package包/类
@Bean
public JettyEmbeddedServletContainerFactory jettyEmbeddedServletContainerFactory(
@Value("${server.port:8080}") final String port,
@Value("${jetty.threadPool.maxThreads:200}") final String maxThreads,
@Value("${jetty.threadPool.minThreads:8}") final String minThreads,
@Value("${jetty.threadPool.idleTimeout:60000}") final String idleTimeout) {
final JettyEmbeddedServletContainerFactory factory =
new JettyEmbeddedServletContainerFactory(Integer.valueOf(port));
factory.addServerCustomizers((JettyServerCustomizer) server -> {
final QueuedThreadPool threadPool = server.getBean(QueuedThreadPool.class);
threadPool.setMaxThreads(Integer.valueOf(maxThreads));
threadPool.setMinThreads(Integer.valueOf(minThreads));
threadPool.setIdleTimeout(Integer.valueOf(idleTimeout));
final GzipHandler gzipHandler = new GzipHandler();
gzipHandler.setHandler(server.getHandler());
gzipHandler.setSyncFlush(true);
server.setHandler(gzipHandler);
});
return factory;
}
示例5: doPut
import org.eclipse.jetty.server.handler.gzip.GzipHandler; //导入依赖的package包/类
@Override
protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
final String path = req.getPathInfo();
if (path != null && byName.matcher(path).matches()) {
final String key = path.trim().substring(1);
InputStream inputStream = req.getInputStream();
if (GzipHandler.GZIP.equalsIgnoreCase(req.getHeader(HttpHeaders.CONTENT_ENCODING))) {
inputStream = new GZIPInputStream(inputStream);
}
try (InputStreamReader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8)) {
final String body = CharStreams.toString(reader);
writeResponse(resp, circuitBreakersResource.modifyCircuitBreaker(key, body));
}
} else {
resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
}
}
示例6: setGzipEnabled
import org.eclipse.jetty.server.handler.gzip.GzipHandler; //导入依赖的package包/类
/**
* Calling this method will cause the server to compress the responses if the client supports GZIP responses and the resource mime type is not of a known compressed type.
*In most cases it should be enabled.
*/
public void setGzipEnabled(boolean b) {
if (b) {
gzipHandler = new GzipHandler();
gzipHandler.setIncludedMethods(HttpMethod.POST.toString(), HttpMethod.GET.toString());
} else {
gzipHandler = null;
}
}
示例7: createGzipHandler
import org.eclipse.jetty.server.handler.gzip.GzipHandler; //导入依赖的package包/类
@Override
public HandlerWrapper createGzipHandler(Compression compression) {
GzipHandler handler = new GzipHandler();
handler.setMinGzipSize(compression.getMinResponseSize());
handler.setIncludedMimeTypes(compression.getMimeTypes());
if (compression.getExcludedUserAgents() != null) {
handler.setExcludedAgentPatterns(compression.getExcludedUserAgents());
}
return handler;
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:11,代码来源:JettyEmbeddedServletContainerFactory.java
示例8: 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);
}
示例9: 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;
}
示例10: newGzipHandler
import org.eclipse.jetty.server.handler.gzip.GzipHandler; //导入依赖的package包/类
private GzipHandler newGzipHandler(ServerConfig serverConfig) {
GzipHandler gzipHandler = new GzipHandlerWithVaryHeaderFixed();
gzipHandler.setCompressionLevel(serverConfig.responseCompressionLevel());
gzipHandler.setCheckGzExists(false);
gzipHandler.setIncludedMethods("GET", "POST");
return gzipHandler;
}
示例11: createGzipHandler
import org.eclipse.jetty.server.handler.gzip.GzipHandler; //导入依赖的package包/类
private GzipHandler createGzipHandler() {
GzipHandler gzipHandler = new GzipHandler();
gzipHandler.setIncludedPaths("/*");
gzipHandler.setMinGzipSize(0);
gzipHandler.setIncludedMimeTypes("text/plain", "text/html");
return gzipHandler;
}
示例12: 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());
}
示例13: setupHandler
import org.eclipse.jetty.server.handler.gzip.GzipHandler; //导入依赖的package包/类
private HandlerCollection setupHandler() throws Exception {
final ResourceConfig resourceConfig = setupResourceConfig();
final ServletContainer servlet = new ServletContainer(resourceConfig);
final ServletHolder jerseyServlet = new ServletHolder(servlet);
// Initialize and register Jersey ServletContainer
jerseyServlet.setInitOrder(1);
// statically provide injector to jersey application.
final ServletContextHandler context =
new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
context.setContextPath("/");
GzipHandler gzip = new GzipHandler();
gzip.setIncludedMethods("POST");
gzip.setMinGzipSize(860);
gzip.setIncludedMimeTypes("application/json");
context.setGzipHandler(gzip);
context.addServlet(jerseyServlet, "/*");
context.addFilter(new FilterHolder(new ShutdownFilter(stopping, mapper)), "/*", null);
context.setErrorHandler(new JettyJSONErrorHandler(mapper));
final RequestLogHandler requestLogHandler = new RequestLogHandler();
requestLogHandler.setRequestLog(new Slf4jRequestLog());
final RewriteHandler rewrite = new RewriteHandler();
makeRewriteRules(rewrite);
final HandlerCollection handlers = new HandlerCollection();
handlers.setHandlers(new Handler[]{rewrite, context, requestLogHandler});
return handlers;
}
示例14: 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;
}
示例15: provideGzipHandler
import org.eclipse.jetty.server.handler.gzip.GzipHandler; //导入依赖的package包/类
@Provides(type = Type.SET)
ContextConfigurator provideGzipHandler() {
return new ContextConfigurator() {
@Override
public void init(ServletContextHandler context) {
context.setGzipHandler(new GzipHandler());
}
};
}