Search in sources :

Example 1 with ContentEncoding

use of org.glassfish.grizzly.http.ContentEncoding in project Payara by payara.

the class GenericGrizzlyListener method configureCompressionEncodings.

protected Set<ContentEncoding> configureCompressionEncodings(Http http) {
    final String mode = http.getCompression();
    int compressionMinSize = Integer.parseInt(http.getCompressionMinSizeBytes());
    CompressionLevel compressionLevel;
    try {
        compressionLevel = CompressionLevel.getCompressionLevel(mode);
    } catch (IllegalArgumentException e) {
        try {
            // Try to parse compression as an int, which would give the
            // minimum compression size
            compressionLevel = CompressionLevel.ON;
            compressionMinSize = Integer.parseInt(mode);
        } catch (Exception ignore) {
            compressionLevel = CompressionLevel.OFF;
        }
    }
    final String compressableMimeTypesString = http.getCompressableMimeType();
    final String noCompressionUserAgentsString = http.getNoCompressionUserAgents();
    final String[] compressableMimeTypes = ((compressableMimeTypesString != null) ? compressableMimeTypesString.split(",") : new String[0]);
    final String[] noCompressionUserAgents = ((noCompressionUserAgentsString != null) ? noCompressionUserAgentsString.split(",") : new String[0]);
    final ContentEncoding gzipContentEncoding = new GZipContentEncoding(GZipContentEncoding.DEFAULT_IN_BUFFER_SIZE, GZipContentEncoding.DEFAULT_OUT_BUFFER_SIZE, new CompressionEncodingFilter(compressionLevel, compressionMinSize, compressableMimeTypes, noCompressionUserAgents, GZipContentEncoding.getGzipAliases(), compressionLevel != CompressionLevel.OFF));
    final ContentEncoding lzmaEncoding = new LZMAContentEncoding(new CompressionEncodingFilter(compressionLevel, compressionMinSize, compressableMimeTypes, noCompressionUserAgents, LZMAContentEncoding.getLzmaAliases(), compressionLevel != CompressionLevel.OFF));
    final Set<ContentEncoding> set = new HashSet<ContentEncoding>(2);
    set.add(gzipContentEncoding);
    set.add(lzmaEncoding);
    return set;
}
Also used : CompressionEncodingFilter(org.glassfish.grizzly.http.server.CompressionEncodingFilter) CompressionLevel(org.glassfish.grizzly.http.server.CompressionLevel) GZipContentEncoding(org.glassfish.grizzly.http.GZipContentEncoding) LZMAContentEncoding(org.glassfish.grizzly.http.LZMAContentEncoding) ContentEncoding(org.glassfish.grizzly.http.ContentEncoding) GZipContentEncoding(org.glassfish.grizzly.http.GZipContentEncoding) LZMAContentEncoding(org.glassfish.grizzly.http.LZMAContentEncoding) IOException(java.io.IOException) HashSet(java.util.HashSet)

Example 2 with ContentEncoding

use of org.glassfish.grizzly.http.ContentEncoding in project Payara by payara.

the class GenericGrizzlyListener method configureHttpProtocol.

@SuppressWarnings({ "deprecation" })
protected void configureHttpProtocol(final ServiceLocator habitat, final NetworkListener networkListener, final Http http, final FilterChainBuilder filterChainBuilder, boolean secure) {
    transactionTimeoutMillis = Long.parseLong(http.getRequestTimeoutSeconds()) * 1000;
    filterChainBuilder.add(new IdleTimeoutFilter(obtainDelayedExecutor(), getTimeoutSeconds(http), TimeUnit.SECONDS));
    final org.glassfish.grizzly.http.HttpServerFilter httpServerFilter = createHttpServerCodecFilter(http);
    httpServerFilter.setRemoveHandledContentEncodingHeaders(true);
    final Set<ContentEncoding> contentEncodings = configureContentEncodings(http);
    for (ContentEncoding contentEncoding : contentEncodings) {
        httpServerFilter.addContentEncoding(contentEncoding);
    }
    // httpServerFilter.getMonitoringConfig().addProbes(
    // serverConfig.getMonitoringConfig().getHttpConfig().getProbes());
    filterChainBuilder.add(httpServerFilter);
    final FileCache fileCache = configureHttpFileCache(http.getFileCache());
    fileCache.initialize(obtainDelayedExecutor());
    final FileCacheFilter fileCacheFilter = new FileCacheFilter(fileCache);
    // fileCache.getMonitoringConfig().addProbes(
    // serverConfig.getMonitoringConfig().getFileCacheConfig().getProbes());
    filterChainBuilder.add(fileCacheFilter);
    final HttpServerFilter webServerFilter = new HttpServerFilter(getHttpServerFilterConfiguration(http), obtainDelayedExecutor());
    final HttpHandler httpHandler = getHttpHandler();
    httpHandler.setAllowEncodedSlash(GrizzlyConfig.toBoolean(http.getEncodedSlashEnabled()));
    webServerFilter.setHttpHandler(httpHandler);
    // webServerFilter.getMonitoringConfig().addProbes(
    // serverConfig.getMonitoringConfig().getWebServerConfig().getProbes());
    filterChainBuilder.add(webServerFilter);
    configureHttp2Support(habitat, networkListener, http, filterChainBuilder, secure);
    // TODO: evaluate comet/websocket support over SPDY.
    configureCometSupport(habitat, networkListener, http, filterChainBuilder);
    configureWebSocketSupport(habitat, networkListener, http, filterChainBuilder);
    configureAjpSupport(habitat, networkListener, http, filterChainBuilder);
}
Also used : HttpServerFilter(org.glassfish.grizzly.http.server.HttpServerFilter) StaticHttpHandler(org.glassfish.grizzly.http.server.StaticHttpHandler) HttpHandler(org.glassfish.grizzly.http.server.HttpHandler) IdleTimeoutFilter(org.glassfish.grizzly.utils.IdleTimeoutFilter) FileCacheFilter(org.glassfish.grizzly.http.server.FileCacheFilter) GZipContentEncoding(org.glassfish.grizzly.http.GZipContentEncoding) LZMAContentEncoding(org.glassfish.grizzly.http.LZMAContentEncoding) ContentEncoding(org.glassfish.grizzly.http.ContentEncoding) FileCache(org.glassfish.grizzly.http.server.filecache.FileCache)

Aggregations

ContentEncoding (org.glassfish.grizzly.http.ContentEncoding)2 GZipContentEncoding (org.glassfish.grizzly.http.GZipContentEncoding)2 LZMAContentEncoding (org.glassfish.grizzly.http.LZMAContentEncoding)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 CompressionEncodingFilter (org.glassfish.grizzly.http.server.CompressionEncodingFilter)1 CompressionLevel (org.glassfish.grizzly.http.server.CompressionLevel)1 FileCacheFilter (org.glassfish.grizzly.http.server.FileCacheFilter)1 HttpHandler (org.glassfish.grizzly.http.server.HttpHandler)1 HttpServerFilter (org.glassfish.grizzly.http.server.HttpServerFilter)1 StaticHttpHandler (org.glassfish.grizzly.http.server.StaticHttpHandler)1 FileCache (org.glassfish.grizzly.http.server.filecache.FileCache)1 IdleTimeoutFilter (org.glassfish.grizzly.utils.IdleTimeoutFilter)1