Search in sources :

Example 1 with HttpServerFilter

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

the class BaseTestGrizzlyConfig method addStaticHttpHandler.

protected void addStaticHttpHandler(GenericGrizzlyListener listener, int count) {
    final String name = "target/tmp/" + Dom.convertName(getClass().getSimpleName()) + count;
    File dir = new File(name);
    dir.mkdirs();
    dir.deleteOnExit();
    FileWriter writer;
    try {
        final File file = new File(dir, "index.html");
        file.deleteOnExit();
        writer = new FileWriter(file);
        try {
            writer.write("<html><body>You've found the server on port " + listener.getPort() + "</body></html>");
            writer.flush();
        } finally {
            writer.close();
        }
    } catch (IOException e) {
        Assert.fail(e.getMessage());
    }
    final List<HttpServerFilter> httpServerFilters = listener.getFilters(HttpServerFilter.class);
    for (HttpServerFilter httpServerFilter : httpServerFilters) {
        httpServerFilter.setHttpHandler(new StaticHttpHandler(name));
    }
}
Also used : HttpServerFilter(org.glassfish.grizzly.http.server.HttpServerFilter) StaticHttpHandler(org.glassfish.grizzly.http.server.StaticHttpHandler) FileWriter(java.io.FileWriter) IOException(java.io.IOException) File(java.io.File)

Example 2 with HttpServerFilter

use of org.glassfish.grizzly.http.server.HttpServerFilter 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

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