protected void validateMessageContent ( Message receivedMessage , Message controlMessage , XmlMessageValidationContext validationContext , TestContext context ) { if ( controlMessage == null || controlMessage . getPayload ( ) == null ) { log . debug ( "Skip message payload validation as no control message was defined" ) ; return ; } if ( ! ( controlMessage . getPayload ( ) instanceof String ) ) { throw new IllegalArgumentException ( "DomXmlMessageValidator does only support message payload of type String, " + "but was " + controlMessage . getPayload ( ) . getClass ( ) ) ; } String controlMessagePayload = controlMessage . getPayload ( String . class ) ; if ( receivedMessage . getPayload ( ) == null || ! StringUtils . hasText ( receivedMessage . getPayload ( String . class ) ) ) { Assert . isTrue ( ! StringUtils . hasText ( controlMessagePayload ) , "Unable to validate message payload - received message payload was empty, control message payload is not" ) ; return ; } else if ( ! StringUtils . hasText ( controlMessagePayload ) ) { return ; } log . debug ( "Start XML tree validation ..." ) ; Document received = XMLUtils . parseMessagePayload ( receivedMessage . getPayload ( String . class ) ) ; Document source = XMLUtils . parseMessagePayload ( controlMessagePayload ) ; XMLUtils . stripWhitespaceNodes ( received ) ; XMLUtils . stripWhitespaceNodes ( source ) ; if ( log . isDebugEnabled ( ) ) { log . debug ( "Received message:\n" + XMLUtils . serialize ( received ) ) ; log . debug ( "Control message:\n" + XMLUtils . serialize ( source ) ) ; } validateXmlTree ( received , source , validationContext , namespaceContextBuilder . buildContext ( receivedMessage , validationContext . getNamespaces ( ) ) , context ) ; }
Validate message payloads by comparing to a control message .