@Test public void testNoCompression() throws Exception { String test = "some content"; message.getResponseElements().setResponseContent(new ByteArrayInputStream(test.getBytes())); instance.execute(message); ByteArrayInputStream input = (ByteArrayInputStream)message.getResponseElements().getResponseBytes(); byte[] bytes = new byte[input.available()]; input.read(bytes); Assert.assertEquals(bytes, test.getBytes()); }
@Override public void execute(IntuitMessage intuitMessage) throws FMSException { LOG.debug("Enter DecompressInterceptor..."); ResponseElements responseElements = intuitMessage.getResponseElements(); String contentEncoding = responseElements.getEncodingHeader(); String decompressedData = null; boolean isCompressionEnabled = false; if (contentEncoding != null) { if (StringUtils.hasText(contentEncoding)) { isCompressionEnabled = true; LOG.info("compression format : " + contentEncoding); LOG.debug("compression format : " + contentEncoding); ICompressor compressor = CompressorFactory.getCompressor(contentEncoding); try { ByteArrayOutputStream bytes = (ByteArrayOutputStream)compressor.decompress(responseElements.getResponseContent()); responseElements.setResponseBytes( new ByteArrayInputStream(bytes.toByteArray()) ); decompressedData = new String(bytes.toByteArray()); } catch (IllegalStateException e) { LOG.error("IllegalStateException while get the content from HttpResponse.", e); throw new FMSException(e); } catch (Exception e) { LOG.error("IOException in DecompressInterceptor.", e); throw new FMSException(e); } } } if (!isCompressionEnabled) { BufferedReader br = null; String readLine = null; StringBuilder responseBody = new StringBuilder(); try { br = new BufferedReader(new InputStreamReader(responseElements.getResponseContent())); while (((readLine = br.readLine()) != null)) { responseBody.append(readLine).append(System.getProperty("line.separator")); } } catch (IllegalStateException e) { LOG.error("IllegalStateException while get the content from HttpResponse.", e); throw new FMSException(e); } catch (Exception e) { LOG.error("IOException in DecompressInterceptor.", e); throw new FMSException(e); } finally { if (br != null) { try { br.close(); } catch (Exception e) { LOG.warn("Unable to close BufferedReader", e); } } } try { responseElements.getResponseContent().reset(); }catch (IOException ex) { LOG.warn("Unable to reset ResponseContent for bytes without compression", ex); } decompressedData = responseBody.toString(); responseElements.setResponseBytes( responseElements.getResponseContent() ); } LOG.debug("Decompressed Response Body : " + decompressedData); LOG.debug("Exit DecompressInterceptor."); responseElements.setDecompressedData(decompressedData); }
DecompressionInterceptor implements Interceptor { @Override public void execute(IntuitMessage intuitMessage) throws FMSException { LOG.debug("Enter DecompressInterceptor..."); ResponseElements responseElements = intuitMessage.getResponseElements(); String contentEncoding = responseElements.getEncodingHeader(); String decompressedData = null; boolean isCompressionEnabled = false; if (contentEncoding != null) { if (StringUtils.hasText(contentEncoding)) { isCompressionEnabled = true; LOG.info("compression format : " + contentEncoding); LOG.debug("compression format : " + contentEncoding); ICompressor compressor = CompressorFactory.getCompressor(contentEncoding); try { ByteArrayOutputStream bytes = (ByteArrayOutputStream)compressor.decompress(responseElements.getResponseContent()); responseElements.setResponseBytes( new ByteArrayInputStream(bytes.toByteArray()) ); decompressedData = new String(bytes.toByteArray()); } catch (IllegalStateException e) { LOG.error("IllegalStateException while get the content from HttpResponse.", e); throw new FMSException(e); } catch (Exception e) { LOG.error("IOException in DecompressInterceptor.", e); throw new FMSException(e); } } } if (!isCompressionEnabled) { BufferedReader br = null; String readLine = null; StringBuilder responseBody = new StringBuilder(); try { br = new BufferedReader(new InputStreamReader(responseElements.getResponseContent())); while (((readLine = br.readLine()) != null)) { responseBody.append(readLine).append(System.getProperty("line.separator")); } } catch (IllegalStateException e) { LOG.error("IllegalStateException while get the content from HttpResponse.", e); throw new FMSException(e); } catch (Exception e) { LOG.error("IOException in DecompressInterceptor.", e); throw new FMSException(e); } finally { if (br != null) { try { br.close(); } catch (Exception e) { LOG.warn("Unable to close BufferedReader", e); } } } try { responseElements.getResponseContent().reset(); }catch (IOException ex) { LOG.warn("Unable to reset ResponseContent for bytes without compression", ex); } decompressedData = responseBody.toString(); responseElements.setResponseBytes( responseElements.getResponseContent() ); } LOG.debug("Decompressed Response Body : " + decompressedData); LOG.debug("Exit DecompressInterceptor."); responseElements.setDecompressedData(decompressedData); } }
DecompressionInterceptor implements Interceptor { @Override public void execute(IntuitMessage intuitMessage) throws FMSException { LOG.debug("Enter DecompressInterceptor..."); ResponseElements responseElements = intuitMessage.getResponseElements(); String contentEncoding = responseElements.getEncodingHeader(); String decompressedData = null; boolean isCompressionEnabled = false; if (contentEncoding != null) { if (StringUtils.hasText(contentEncoding)) { isCompressionEnabled = true; LOG.info("compression format : " + contentEncoding); LOG.debug("compression format : " + contentEncoding); ICompressor compressor = CompressorFactory.getCompressor(contentEncoding); try { ByteArrayOutputStream bytes = (ByteArrayOutputStream)compressor.decompress(responseElements.getResponseContent()); responseElements.setResponseBytes( new ByteArrayInputStream(bytes.toByteArray()) ); decompressedData = new String(bytes.toByteArray()); } catch (IllegalStateException e) { LOG.error("IllegalStateException while get the content from HttpResponse.", e); throw new FMSException(e); } catch (Exception e) { LOG.error("IOException in DecompressInterceptor.", e); throw new FMSException(e); } } } if (!isCompressionEnabled) { BufferedReader br = null; String readLine = null; StringBuilder responseBody = new StringBuilder(); try { br = new BufferedReader(new InputStreamReader(responseElements.getResponseContent())); while (((readLine = br.readLine()) != null)) { responseBody.append(readLine).append(System.getProperty("line.separator")); } } catch (IllegalStateException e) { LOG.error("IllegalStateException while get the content from HttpResponse.", e); throw new FMSException(e); } catch (Exception e) { LOG.error("IOException in DecompressInterceptor.", e); throw new FMSException(e); } finally { if (br != null) { try { br.close(); } catch (Exception e) { LOG.warn("Unable to close BufferedReader", e); } } } try { responseElements.getResponseContent().reset(); }catch (IOException ex) { LOG.warn("Unable to reset ResponseContent for bytes without compression", ex); } decompressedData = responseBody.toString(); responseElements.setResponseBytes( responseElements.getResponseContent() ); } LOG.debug("Decompressed Response Body : " + decompressedData); LOG.debug("Exit DecompressInterceptor."); responseElements.setDecompressedData(decompressedData); }  }
DecompressionInterceptor implements Interceptor { @Override public void execute(IntuitMessage intuitMessage) throws FMSException { LOG.debug("Enter DecompressInterceptor..."); ResponseElements responseElements = intuitMessage.getResponseElements(); String contentEncoding = responseElements.getEncodingHeader(); String decompressedData = null; boolean isCompressionEnabled = false; if (contentEncoding != null) { if (StringUtils.hasText(contentEncoding)) { isCompressionEnabled = true; LOG.info("compression format : " + contentEncoding); LOG.debug("compression format : " + contentEncoding); ICompressor compressor = CompressorFactory.getCompressor(contentEncoding); try { ByteArrayOutputStream bytes = (ByteArrayOutputStream)compressor.decompress(responseElements.getResponseContent()); responseElements.setResponseBytes( new ByteArrayInputStream(bytes.toByteArray()) ); decompressedData = new String(bytes.toByteArray()); } catch (IllegalStateException e) { LOG.error("IllegalStateException while get the content from HttpResponse.", e); throw new FMSException(e); } catch (Exception e) { LOG.error("IOException in DecompressInterceptor.", e); throw new FMSException(e); } } } if (!isCompressionEnabled) { BufferedReader br = null; String readLine = null; StringBuilder responseBody = new StringBuilder(); try { br = new BufferedReader(new InputStreamReader(responseElements.getResponseContent())); while (((readLine = br.readLine()) != null)) { responseBody.append(readLine).append(System.getProperty("line.separator")); } } catch (IllegalStateException e) { LOG.error("IllegalStateException while get the content from HttpResponse.", e); throw new FMSException(e); } catch (Exception e) { LOG.error("IOException in DecompressInterceptor.", e); throw new FMSException(e); } finally { if (br != null) { try { br.close(); } catch (Exception e) { LOG.warn("Unable to close BufferedReader", e); } } } try { responseElements.getResponseContent().reset(); }catch (IOException ex) { LOG.warn("Unable to reset ResponseContent for bytes without compression", ex); } decompressedData = responseBody.toString(); responseElements.setResponseBytes( responseElements.getResponseContent() ); } LOG.debug("Decompressed Response Body : " + decompressedData); LOG.debug("Exit DecompressInterceptor."); responseElements.setDecompressedData(decompressedData); }  @Override void execute(IntuitMessage intuitMessage); }
DecompressionInterceptor implements Interceptor { @Override public void execute(IntuitMessage intuitMessage) throws FMSException { LOG.debug("Enter DecompressInterceptor..."); ResponseElements responseElements = intuitMessage.getResponseElements(); String contentEncoding = responseElements.getEncodingHeader(); String decompressedData = null; boolean isCompressionEnabled = false; if (contentEncoding != null) { if (StringUtils.hasText(contentEncoding)) { isCompressionEnabled = true; LOG.info("compression format : " + contentEncoding); LOG.debug("compression format : " + contentEncoding); ICompressor compressor = CompressorFactory.getCompressor(contentEncoding); try { ByteArrayOutputStream bytes = (ByteArrayOutputStream)compressor.decompress(responseElements.getResponseContent()); responseElements.setResponseBytes( new ByteArrayInputStream(bytes.toByteArray()) ); decompressedData = new String(bytes.toByteArray()); } catch (IllegalStateException e) { LOG.error("IllegalStateException while get the content from HttpResponse.", e); throw new FMSException(e); } catch (Exception e) { LOG.error("IOException in DecompressInterceptor.", e); throw new FMSException(e); } } } if (!isCompressionEnabled) { BufferedReader br = null; String readLine = null; StringBuilder responseBody = new StringBuilder(); try { br = new BufferedReader(new InputStreamReader(responseElements.getResponseContent())); while (((readLine = br.readLine()) != null)) { responseBody.append(readLine).append(System.getProperty("line.separator")); } } catch (IllegalStateException e) { LOG.error("IllegalStateException while get the content from HttpResponse.", e); throw new FMSException(e); } catch (Exception e) { LOG.error("IOException in DecompressInterceptor.", e); throw new FMSException(e); } finally { if (br != null) { try { br.close(); } catch (Exception e) { LOG.warn("Unable to close BufferedReader", e); } } } try { responseElements.getResponseContent().reset(); }catch (IOException ex) { LOG.warn("Unable to reset ResponseContent for bytes without compression", ex); } decompressedData = responseBody.toString(); responseElements.setResponseBytes( responseElements.getResponseContent() ); } LOG.debug("Decompressed Response Body : " + decompressedData); LOG.debug("Exit DecompressInterceptor."); responseElements.setDecompressedData(decompressedData); }  @Override void execute(IntuitMessage intuitMessage);  }