public List < MessageValidator < ? extends ValidationContext > > findMessageValidators ( String messageType , Message message ) { List < MessageValidator < ? extends ValidationContext > > matchingValidators = new ArrayList <> ( ) ; for ( MessageValidator < ? extends ValidationContext > validator : messageValidators ) { if ( validator . supportsMessageType ( messageType , message ) ) { matchingValidators . add ( validator ) ; } } if ( matchingValidators . isEmpty ( ) || matchingValidators . stream ( ) . allMatch ( validator -> DefaultMessageHeaderValidator . class . isAssignableFrom ( validator . getClass ( ) ) ) ) { // try to find fallback message validator for given message payload if ( message . getPayload ( ) instanceof String && StringUtils . hasText ( message . getPayload ( String . class ) ) ) { String payload = message . getPayload ( String . class ) . trim ( ) ; if ( payload . startsWith ( "<" ) && ! messageType . equals ( MessageType . XML . name ( ) ) ) { matchingValidators = findFallbackMessageValidators ( MessageType . XML . name ( ) , message ) ; } else if ( ( payload . trim ( ) . startsWith ( "{" ) || payload . trim ( ) . startsWith ( "[" ) ) && ! messageType . equals ( MessageType . JSON . name ( ) ) ) { matchingValidators = findFallbackMessageValidators ( MessageType . JSON . name ( ) , message ) ; } else if ( ! messageType . equals ( MessageType . PLAINTEXT . name ( ) ) ) { matchingValidators = findFallbackMessageValidators ( MessageType . PLAINTEXT . name ( ) , message ) ; } } } if ( matchingValidators . isEmpty ( ) || matchingValidators . stream ( ) . allMatch ( validator -> DefaultMessageHeaderValidator . class . isAssignableFrom ( validator . getClass ( ) ) ) ) { throw new CitrusRuntimeException ( "Could not find proper message validator for message type '" + messageType + "', please define a capable message validator for this message type" ) ; } if ( log . isDebugEnabled ( ) ) { log . debug ( String . format ( "Found %s message validators for message type: %s" , matchingValidators . size ( ) , messageType ) ) ; } return matchingValidators ; }
Finds matching message validators for this message type .