'Validator Exception Spring Integration: returning an error message in validator

Does anybody has an idea about how I can return an error message. I am trying to return an specific xml error message in my validator. This is my code:

 @Override
    public void validate(Object target, Errors errors) {
        try {
            ValidationClassUtil.validateDocument(new String((byte[]) target), xmlVersionEnum);
            (//should the error be returned here when I send an invalid xml file over http?)
        } catch (Exception exc) {
            errors.reject(errorCode);
        }
    }


Solution 1:[1]

This is not what Validator contract is for. You cannot return from it anything. You can use such a validate() in other wrapper service and then in the end you consult that errors to be able to return whatever you want via its hasErrors() and getAllErrors().

I have showed you some way in this answer: Validator Spring integration

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Artem Bilan