How to enable compression of server's http response in JBoss EAP 6? Use GZIP
Environment
- Red Hat JBoss Enterprise Application Platform (EAP)
- 6.x
Issue
- How can we enable the Http Compression for HttpServletResponse in JBoss EAP6?
- Is GZIP compression still supported in EAP 6, and if so, how should implement it?
- Is GZIP for JSON response can be done using
-Dorg.apache.coyote.http11.Http11Protocol.COMPRESSION=ON? - How to enable
gzip compressionin JBoss EAP 6? - GZIP Compression not working. JSON responses returned from the servlets in the application is not compressed even when I have added the following to the standalon-full.xml:
<property name="org.apache.coyote.http11.Http11Protocol.COMPRESSION" value="force"/>
<property name="org.apache.coyote.http11.Http11Protocol.COMPRESSION_MIME_TYPES" value="text/javascript,text/css,text/html,text/xml,text/json,application/json,text/plain"/>
Resolution
Use the following system properties in order to enable the compression in JBoss EAP 6:
-
org.apache.coyote.http11.Http11Protocol.COMPRESSION
Allows using simple compression with the HTTP connector. The default value isoff, and compression can be enabled using the valueonto enable it conditionally, orforceto always enable it. -
org.apache.coyote.http11.Http11Protocol.COMPRESSION_MIME_TYPES
Content type prefixes of compressible content. The default value is text/html,text/xml,text/plain. -
org.apache.coyote.http11.Http11Protocol.COMPRESSION_MIN_SIZE
The minimum size of the content that will be compressed. The default value is 2048 bytes. -
Note that the compression will work only when the response contains the data more than the COMPRESSION_MIN_SIZE which is default to 2048
Standalone mode
- Enable these System properties via
"$JBOSS_HOME/bin/standalone.conf"file by adding the JAVA_OPTS including the mentioned system properties.
Or
- Enable it into the standalone(-*).xml file like as following:
<system-properties>
<property name="org.apache.coyote.http11.Http11Protocol.COMPRESSION" value="on"/>
<property name="org.apache.coyote.http11.Http11Protocol.COMPRESSION_MIME_TYPES" value="text/javascript,text/css,text/html"/>
</system-properties>
Domain mode
- The following system properties can be enabled for individual server instances as well. like following in the "host.xml"
<servers>
<server name="server-one" group="main-server-group">
<system-properties>
<property name="org.apache.coyote.http11.Http11Protocol.COMPRESSION" value="on"/>
<property name="org.apache.coyote.http11.Http11Protocol.COMPRESSION_MIME_TYPES" value="text/javascript,text/css,text/html"/>
</system-properties>
</server>
</servers>
- Via CLI commands
[domain@localhost:9999 /] /host=master/server-config=server-one/system-property=org.apache.coyote.http11.Http11Protocol.COMPRESSION:add(value=on)
{
"outcome" => "success",
"result" => undefined,
"server-groups" => {"main-server-group" => {"host" => {"master" => {"server-one" => {"response" => {"outcome" => "success"}}}}}}
}
[domain@localhost:9999 /] /host=master/server-config=server-one/system-property=org.apache.coyote.http11.Http11Protocol.COMPRESSION_MIME_TYPES:add(value="text/javascript,text/css,text/html")
{
"outcome" => "success",
"result" => undefined,
"server-groups" => {"main-server-group" => {"host" => {"master" => {"server-one" => {"response" => {"outcome" => "success"}}}}}}
}
-
Setup system properties per "profile"/"host"/"server-group"/"server"
Setup these properties per "server", "host" or "server-group".There is another solution How to configure the maximum packet size for HTTP JBoss connectors showing how to setup system properties on specific "host" or "server-group".
Below is a sample of setting this per "server"
The following system properties can be enabled for individual server instances as well. like following in the "host.xml"
<servers>
<server name="server-one" group="main-server-group">
<system-properties>
<property name="org.apache.coyote.http11.Http11Protocol.COMPRESSION" value="on"/>
<property name="org.apache.coyote.http11.Http11Protocol.COMPRESSION_MIME_TYPES" value="text/javascript,text/css,text/html"/>
</system-properties>
</server>
</servers>
[domain@localhost:9999 /] /host=master/server-config=server-one/system-property=org.apache.coyote.http11.Http11Protocol.COMPRESSION:add(value=on)
{
"outcome" => "success",
"result" => undefined,
"server-groups" => {"main-server-group" => {"host" => {"master" => {"server-one" => {"response" => {"outcome" => "success"}}}}}}
}
[domain@localhost:9999 /] /host=master/server-config=server-one/system-property=org.apache.coyote.http11.Http11Protocol.COMPRESSION_MIME_TYPES:add(value="text/javascript,text/css,text/html")
{
"outcome" => "success",
"result" => undefined,
"server-groups" => {"main-server-group" => {"host" => {"master" => {"server-one" => {"response" => {"outcome" => "success"}}}}}}
}
NOTE: As these are system properties, the JBoss EAP should be restarted after making the system properties changes.
Internet Explorer:
It has been seen that IE 11.0.9600.18283 on Windows 7 does send the "gzip, deflated" header, but subsequently refuses to work with a gzipped response and continues in non-gzip mode. Simulating with a test tool using identical request headers showed that EAP properly served gzip.
At the same time, testing with IE 11.0.10240.16384 on Windows 10 shows a success.
If this behavior is seen with IE, then we kindly suggest to contact Microsoft and/or upgrade IE.
NOTE : How to enable GZIP compression of server's http responses in JBoss EAP 7?
Diagnostic Steps
Testing the compression
$ curl --raw -s http://localhost:8080/<app_context_root> -o - | wc -c
1274
$ curl --raw --compressed -s http://localhost:8080/<app_context_root> -o - | wc -c
706
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.