private void buildOutMessage ( Exchange exchange , Message message ) { org . apache . camel . Message reply = exchange . getOut ( ) ; for ( Map . Entry < String , Object > header : message . getHeaders ( ) . entrySet ( ) ) { if ( ! header . getKey ( ) . startsWith ( MessageHeaders . PREFIX ) ) { reply . setHeader ( header . getKey ( ) , header . getValue ( ) ) ; } } if ( message . getHeader ( CitrusCamelMessageHeaders . EXCHANGE_EXCEPTION ) != null ) { String exceptionClass = message . getHeader ( CitrusCamelMessageHeaders . EXCHANGE_EXCEPTION ) . toString ( ) ; String exceptionMsg = null ; if ( message . getHeader ( CitrusCamelMessageHeaders . EXCHANGE_EXCEPTION_MESSAGE ) != null ) { exceptionMsg = message . getHeader ( CitrusCamelMessageHeaders . EXCHANGE_EXCEPTION_MESSAGE ) . toString ( ) ; } try { Class < ? > exception = Class . forName ( exceptionClass ) ; if ( exceptionMsg != null ) { exchange . setException ( ( Throwable ) exception . getConstructor ( String . class ) . newInstance ( exceptionMsg ) ) ; } else { exchange . setException ( ( Throwable ) exception . newInstance ( ) ) ; } } catch ( RuntimeException e ) { log . warn ( "Unable to create proper exception instance for exchange!" , e ) ; } catch ( Exception e ) { log . warn ( "Unable to create proper exception instance for exchange!" , e ) ; } } reply . setBody ( message . getPayload ( ) ) ; }
Builds response and sets it as out message on given Camel exchange .