protected void validateMessage(Message receivedMessage, TestContext context) throws IOException {
        // extract variables from received message content
        for (VariableExtractor variableExtractor : variableExtractors) {
            variableExtractor.extractVariables(receivedMessage, context);
        }

        if (validationCallback != null) {
            if (StringUtils.hasText(receivedMessage.getName())) {
                context.getMessageStore().storeMessage(receivedMessage.getName(), receivedMessage);
            } else {
                context.getMessageStore().storeMessage(context.getMessageStore().constructMessageName(this, getOrCreateEndpoint(context)), receivedMessage);
            }

            validationCallback.validate(receivedMessage, context);
        } else {
            Message controlMessage = createControlMessage(context, messageType);
            if (StringUtils.hasText(controlMessage.getName())) {
                context.getMessageStore().storeMessage(controlMessage.getName(), receivedMessage);
            } else {
                context.getMessageStore().storeMessage(context.getMessageStore().constructMessageName(this, getOrCreateEndpoint(context)), receivedMessage);
            }

            if (!CollectionUtils.isEmpty(validators)) {
                for (MessageValidator<? extends ValidationContext> messageValidator : validators) {
                    messageValidator.validateMessage(receivedMessage, controlMessage, context, validationContexts);
                }

                if (validators.parallelStream()
                                .map(Object::getClass)
                                .noneMatch(DefaultMessageHeaderValidator.class::isAssignableFrom)) {
                    MessageValidator defaultMessageHeaderValidator = context.getMessageValidatorRegistry().getDefaultMessageHeaderValidator();
                    if (defaultMessageHeaderValidator != null) {
                        defaultMessageHeaderValidator.validateMessage(receivedMessage, controlMessage, context, validationContexts);
                    }
                }
            } else {
                List<MessageValidator<? extends ValidationContext>> validators =
                        context.getMessageValidatorRegistry().findMessageValidators(messageType, receivedMessage);

                if (validators.isEmpty()) {
                    if (controlMessage.getPayload() instanceof String &&
                            StringUtils.hasText(controlMessage.getPayload(String.class))) {
                        throw new CitrusRuntimeException(String.format("Unable to find proper message validator for message type '%s' and validation contexts '%s'", messageType, validationContexts));
                    } else if (validationContexts.stream().anyMatch(item -> JsonPathMessageValidationContext.class.isAssignableFrom(item.getClass())
                            || XpathMessageValidationContext.class.isAssignableFrom(item.getClass())
                            || ScriptValidationContext.class.isAssignableFrom(item.getClass()))) {
                        throw new CitrusRuntimeException(String.format("Unable to find proper message validator for message type '%s' and validation contexts '%s'", messageType, validationContexts));
                    } else {
                        log.warn(String.format("Unable to find proper message validator for message type '%s' and validation contexts '%s'", messageType, validationContexts));
                    }
                }

                for (MessageValidator<? extends ValidationContext> messageValidator : validators) {
                    messageValidator.validateMessage(receivedMessage, controlMessage, context, validationContexts);
                }
            }
        }
    }
protected void validateMessage ( Message receivedMessage , TestContext context ) throws IOException { for ( VariableExtractor variableExtractor : variableExtractors ) { variableExtractor . extractVariables ( receivedMessage , context ) ; } if ( validationCallback != null ) { if ( StringUtils . hasText ( receivedMessage . getName ( ) ) ) { context . getMessageStore ( ) . storeMessage ( receivedMessage . getName ( ) , receivedMessage ) ; } else { context . getMessageStore ( ) . storeMessage ( context . getMessageStore ( ) . constructMessageName ( this , getOrCreateEndpoint ( context ) ) , receivedMessage ) ; } validationCallback . validate ( receivedMessage , context ) ; } else { Message controlMessage = createControlMessage ( context , messageType ) ; if ( StringUtils . hasText ( controlMessage . getName ( ) ) ) { context . getMessageStore ( ) . storeMessage ( controlMessage . getName ( ) , receivedMessage ) ; } else { context . getMessageStore ( ) . storeMessage ( context . getMessageStore ( ) . constructMessageName ( this , getOrCreateEndpoint ( context ) ) , receivedMessage ) ; } if ( ! CollectionUtils . isEmpty ( validators ) ) { for ( MessageValidator < ? extends ValidationContext > messageValidator : validators ) { messageValidator . validateMessage ( receivedMessage , controlMessage , context , validationContexts ) ; } if ( validators . parallelStream ( ) . map ( Object :: getClass ) . noneMatch ( DefaultMessageHeaderValidator . class :: isAssignableFrom ) ) { MessageValidator defaultMessageHeaderValidator = context . getMessageValidatorRegistry ( ) . getDefaultMessageHeaderValidator ( ) ; if ( defaultMessageHeaderValidator != null ) { defaultMessageHeaderValidator . validateMessage ( receivedMessage , controlMessage , context , validationContexts ) ; } } } else { List < MessageValidator < ? extends ValidationContext > > validators = context . getMessageValidatorRegistry ( ) . findMessageValidators ( messageType , receivedMessage ) ; if ( validators . isEmpty ( ) ) { if ( controlMessage . getPayload ( ) instanceof String && StringUtils . hasText ( controlMessage . getPayload ( String . class ) ) ) { throw new CitrusRuntimeException ( String . format ( "Unable to find proper message validator for message type '%s' and validation contexts '%s'" , messageType , validationContexts ) ) ; } else if ( validationContexts . stream ( ) . anyMatch ( item -> JsonPathMessageValidationContext . class . isAssignableFrom ( item . getClass ( ) ) || XpathMessageValidationContext . class . isAssignableFrom ( item . getClass ( ) ) || ScriptValidationContext . class . isAssignableFrom ( item . getClass ( ) ) ) ) { throw new CitrusRuntimeException ( String . format ( "Unable to find proper message validator for message type '%s' and validation contexts '%s'" , messageType , validationContexts ) ) ; } else { log . warn ( String . format ( "Unable to find proper message validator for message type '%s' and validation contexts '%s'" , messageType , validationContexts ) ) ; } } for ( MessageValidator < ? extends ValidationContext > messageValidator : validators ) { messageValidator . validateMessage ( receivedMessage , controlMessage , context , validationContexts ) ; } } } }
Override this message if you want to add additional message validation
@param receivedMessage