Spring WS How to get all error messages when validation fails

走远了吗. 提交于 2019-12-13 07:14:37

问题


When xsd validation fails I am trying to get all the error messages (SOAP detail element) and save them. Code below works but only brings the first error, how can I get all of them ?

public class PayloadValidationgInterceptorCustom extends
    PayloadValidatingInterceptor {

 @Override
protected Source getValidationRequestSource(WebServiceMessage  webSerMessage)   {
     source = webSerMessage.getPayloadSource();
     validateSchema(source);
     return source;  
}

private void validateSchema(Source source) throws Exception {        
  SchemaFactory schemaFactory =   
        SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
  Schema schema = schemaFactory.newSchema(getSchemas()[0].getFile());

  Validator validator = schema.newValidator();
  DOMResult result = new DOMResult();
 try {
     validator.validate(source, result);          
 } catch (SAXException _exception) {

      //?????? 
      //save error mesg to database
      //but this exception only has one error message            
}

}


回答1:


The response is the same as here; you can look at

protected boolean handleRequestValidationErrors(MessageContext messageContext, SAXParseException[] errors)

you have an array of ParseException and you can dump all of them.



来源:https://stackoverflow.com/questions/30671052/spring-ws-how-to-get-all-error-messages-when-validation-fails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!