Larry Larry - 1 year ago 143
Java Question

Uncompress GZIP http-response (using jersey client api, java)

Could someone tell me what I need to do in order to uncompress a GZIP content when getting the response from some Http-call.

To make the call I use the Jersey Client API, see code below:

String baseURI = "";
ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
WebResource wr = client.resource(baseURI);
ClientResponse response = null;
response = wr.get(ClientResponse.class);
String response_data = response.getEntity(String.class);


However the output is GZIP’d and looks like:


It would be good if I could implement the following:

  • being able to detect whether content is GZIP’d or not;

  • If not, process like normal in a String; if, so uncompress and get the content in String

Answer Source

Simply add GZIPContentEncodingFilter to your client:

client.addFilter(new GZIPContentEncodingFilter(false));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download