MessageContentUtil { public static void decryptContent( SecurityManager securityManager, Message message, String hostIdSource, String hostIdTarget ) { InputStream is = message.getContent( InputStream.class ); if( is == null ) { LOG.error( "Error decrypting content: No content: " + message.getExchange() ); return; } CachedOutputStream os = new CachedOutputStream(); LOG.debug( String.format( "Decrypting IDs: %s -> %s", hostIdSource, hostIdTarget ) ); try { int copied = IOUtils.copyAndCloseInput( is, os ); os.flush(); byte[] data = copied > 0 ? decryptData( securityManager, hostIdSource, os.getBytes() ) : null; org.apache.commons.io.IOUtils.closeQuietly( os ); if ( !ArrayUtils.isEmpty( data ) ) { LOG.debug( String.format( "Decrypted payload: \"%s\"", new String( data ) ) ); message.setContent( InputStream.class, new ByteArrayInputStream( data ) ); } else { LOG.debug( "Decrypted data is NULL!!!" ); } } catch ( Exception e ) { LOG.error( "Error decrypting content", e ); } } private  MessageContentUtil(); static void abortChain( Message message, Throwable ex ); static void abortChain( Message message, int errorStatus, String errorMessage ); static void decryptContent( SecurityManager securityManager, Message message, String hostIdSource,
                                       String hostIdTarget ); static void encryptContent( SecurityManager securityManager, String hostIdSource, String hostIdTarget,
                                       Message message );  }
@Test public void testDecryptContent() throws Exception { doReturn( "OK".getBytes() ).when( encryptionTool ) .decrypt( isA( byte[].class ), isA( PGPSecretKeyRing.class ), anyString() ); MessageContentUtil.decryptContent( securityManager, message, SRC, TARGET ); verify( encryptionTool ).decrypt( isA( byte[].class ), isA( PGPSecretKeyRing.class ), anyString() ); verify( message ).setContent( any( Class.class ), Matchers.anyObject() ); doReturn( null ).when( encryptionTool ) .decrypt( isA( byte[].class ), isA( PGPSecretKeyRing.class ), anyString() ); MessageContentUtil.decryptContent( securityManager, message, SRC, TARGET ); }