HttpAsyncClient 5 | Best recipe to handle Gzip content as response

407 Views Asked by At

from link we understand that automatic content decompression. is not supported.
So is below recipe good way to handle the gzip content ?

httpclient.execute(this.post, new FutureCallback<SimpleHttpResponse>() {
                @Override
                public void completed(SimpleHttpResponse response) {                                        
                        String resXML = null;
                        
                        Header contentEncoding = response.getHeader("Content-Encoding");

                        if(contentEncoding != null 
                              && "gzip".equalsIgnoreCase(contentEncoding.getValue())){

                            HttpEntity entity = new GzipDecompressingEntity(new ByteArrayEntity(response.getBodyBytes(), ContentType.APPLICATION_XML));
                            resXML = EntityUtils.toString(entity, "UTF-8");

                        }else{
                            resXML = response.getBodyText();
                        }                   
                    
                }

0

There are 0 best solutions below