We are using Java validator as per https://docs.jboss.org/author/display/SWITCHYARD/Java+Validator If validation fails, the validator returns:
BaseValidator.invalidResult("Too many order quantity: " + order.getQuantity());
|
This will be wrapped in org.switchyard.validate.ValidationFailureException see org.switchyard.handlers.ValidateHandler.handleMessage(Exchange), resulting in the following:
org.switchyard.validate.ValidationFailureException: SWITCHYARD014000: Validator:[class=org.switchyard.validate.internal.ValidatorUtil$1', type='org.switchyard.quickstarts.bean.service.Order', name='java:org.switchyard.quickstarts.bean.service.Order'] failed: Too many order quantity: 1500
|
Assuming we have MessageComposer to convert exception into error response object, we would need to parse exception.getMessage and take last part of the string. Even worse if we have more than one Validation message, we have to encode list of messages in string, and in MesasageComposer decode it back My proposal would be to extend ValidateHandler and in case of error save the result of Validation in context, so any component interested in details can get it back in original form. |