简体   繁体   中英

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);
        }
    }

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM