JAX-RS Web Services are not returning GZIP responses after upgrading to JBoss EAP 6.4.14
Environment
- Red Hat JBoss Enterprise Application Platform (EAP)
- 6.4.14
Issue
After upgrading to JBoss EAP 6.4.14 we are seeing that our JAX-RS resources are not returning ZIP content anymore. It happens even when we have the org.jboss.resteasy.annotations.GZIP annotation on the JAX-RS methods.
When we use RESTEasy client we have an exception:
org.jboss.resteasy.spi.ReaderException: java.util.zip.ZipException: Not in GZIP format
at org.jboss.resteasy.client.core.BaseClientResponse.readFrom(BaseClientResponse.java:466)
at org.jboss.resteasy.client.core.BaseClientResponse.getEntity(BaseClientResponse.java:376)
at org.jboss.resteasy.client.core.BaseClientResponse.getEntity(BaseClientResponse.java:351)
at org.jboss.resteasy.client.core.extractors.BodyEntityExtractor.extractEntity(BodyEntityExtractor.java:62)
at org.jboss.resteasy.client.core.ClientInvoker.invoke(ClientInvoker.java:127)
at org.jboss.resteasy.client.core.ClientProxy.invoke(ClientProxy.java:89)
at com.sun.proxy.$Proxy24.echo(Unknown Source)
(....)
Caused by: java.util.zip.ZipException: Not in GZIP format
at java.util.zip.GZIPInputStream.readHeader(GZIPInputStream.java:165)
at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:79)
at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:91)
at org.jboss.resteasy.plugins.interceptors.encoding.GZIPDecodingInterceptor$FinishableGZIPInputStream.<init>(GZIPDecodingInterceptor.java:30)
at org.jboss.resteasy.plugins.interceptors.encoding.GZIPDecodingInterceptor.read(GZIPDecodingInterceptor.java:47)
at org.jboss.resteasy.core.interception.MessageBodyReaderContextImpl.proceed(MessageBodyReaderContextImpl.java:109)
at org.jboss.resteasy.client.core.BaseClientResponse.readFrom(BaseClientResponse.java:430)
... 31 more
Resolution
Register the GZIP interceptors on server side. There are two main ways to do this:
- Create a file named
META-INF/services/javax.ws.rs.ext.Providerswith the following content:
org.jboss.resteasy.plugins.interceptors.encoding.GZIPDecodingInterceptor
org.jboss.resteasy.plugins.interceptors.encoding.GZIPEncodingInterceptor
Notice that if you don't want to modify your deployment, you can add this file using a deployment overlay. Notice that this file should be in your application classpath, not exactly on your deployment, so a JAR in app.warWEB-INF/lib (or in a custom module that your application is dependent) that contains this file should also work.
- Use Java code (it can be called from any part of your application and a single call should work):
import org.jboss.resteasy.spi.ResteasyProviderFactory;
ResteasyProviderFactory.getInstance().registerProvider(org.jboss.resteasy.plugins.interceptors.encoding.GZIPDecodingInterceptor.class);
ResteasyProviderFactory.getInstance().registerProvider(org.jboss.resteasy.plugins.interceptors.encoding.GZIPEncodingInterceptor.class)
It is also possible to make changes in the resteasy modules to include this provider, but it is not recommended.
Root Cause
This behavior is caused by the This content is not included.CVE-2016-6346 fix. It disables the GZIP interceptors by default and creates the resteasy.gzip.max.input parameter that allow us to configure the max GZIP size.
A This content is not included.bugzilla was created to make easy to activate GZIP support again and it is targeted for a later JBoss EAP 6.4 CP release.
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.