Die BPC Version 4.1 wird nicht mehr gewartet.

Sollten Sie diese BPC Version nutzen, empfehlen wir Ihnen eine Migration auf eine aktuelle Version. Die Dokumentation zur neusten BPC Version finden Sie hier. Sollten Sie Fragen haben, wenden Sie sich bitte an unseren Support.

Jetty with gzip compression

Karaf uses the Jetty web server to serve web resources. By default, Jetty does not use compression, but it can be enabled.

For Karaf installation files downloaded after September 28, 2021 (BPC 3.4.x and BPC 4.0.0), the jetty.xml file listed below has already been updated.

Enabling

To ensure that Karaf/Jetty serves the web resources in compressed form, you must insert the following fragment at the end of [karaf]/etc/jetty.xml ein GzipHandler installiert werden. Dazu in der <INLINE_CODE_1/>`.

Karaf must be restarted after modifying `jetty.xml.

[karaf]/etc/jetty.xml
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">

    ...

    <!-- ====================== -->
    <!-- Insert the GzipHandler -->
    <!-- ====================== -->
    <Call name="insertHandler">
        <Arg>
            <New id="GzipHandler" class="org.eclipse.jetty.server.handler.gzip.GzipHandler">
                <Set name="minGzipSize"><Property name="jetty.gzip.minGzipSize" default="1024"/></Set>
                <Set name="checkGzExists"><Property name="jetty.gzip.checkGzExists" default="false"/></Set>
                <Set name="compressionLevel"><Property name="jetty.gzip.compressionLevel" default="-1"/></Set>
                <Set name="inflateBufferSize"><Property name="jetty.gzip.inflateBufferSize" default="0"/></Set>
                <Set name="syncFlush"><Property name="jetty.gzip.syncFlush" default="false" /></Set>
                <Set name="excludedAgentPatterns">
                    <Array type="String">
                        <!-- IE 6 has known bugs related to GZIP compression -->
                        <Item><Property name="jetty.gzip.excludedUserAgent" default=".*MSIE.6\.0.*"/></Item>
                    </Array>
                </Set>
                <Set name="includedMethodList"><Property name="jetty.gzip.includedMethodList" default="GET" /></Set>
                <Set name="excludedMethodList"><Property name="jetty.gzip.excludedMethodList" default="" /></Set>
                <!--
                    <Set name="includedMethods">
                        <Array type="String">
                            <Item>GET</Item>
                        </Array>
                    </Set>
                    <Set name="includedPaths">
                        <Array type="String">
                            <Item>/*</Item>
                        </Array>
                    </Set>
                    <Set name="excludedPaths">
                        <Array type="String">
                            <Item>*.gz</Item>
                        </Array>
                    </Set>
                    <Call name="addIncludedMimeTypes">
                        <Arg>
                            <Array type="String">
                                <Item>some/type</Item>
                            </Array>
                        </Arg>
                    </Call>
                    <Call name="addExcludedMimeTypes">
                        <Arg>
                            <Array type="String">
                                <Item>some/type</Item>
                            </Array>
                        </Arg>
                    </Call>
                -->
            </New>
        </Arg>
    </Call>
</Configure>

Syntax

The syntax used in jetty.xml takes a little getting used to. Two things are essential here:

  1. The individual XML elements are converted directly into Java calls at runtime. Therefore, it can’t hurt to familiarize yourself with the Jetty XML syntax.

  2. The individual XML elements all refer to the Java methods of the GzipHandler class. The values set above are not the only ones that can be set. It’s worth taking a look at the GzipHandler JavaDoc.

Important GzipHandler configurations

  • minGzipSize The minimum size in bytes that a response must have before compression is triggered. It is set to 1024 bytes above. This means that responses smaller than 1024 bytes will not be compressed.

  • compressionLevel The Gzip compression level: 0–9, with -1 as the default, which currently corresponds to compression level 6. This is a good compromise between speed and response size.

Prerequisite: the jetty.xml file must be used

Ensure that the following line is included in [karaf]/etc/org.ops4j.pax.web.cfg.

org.ops4j.pax.web.config.file=${karaf.etc}/jetty.xml

Keywords: