【问题标题】:Spring WS How to get all error messages when validation failsSpring WS验证失败时如何获取所有错误消息
【发布时间】:2015-06-05 16:07:25
【问题描述】:

当 xsd 验证失败时,我会尝试获取所有错误消息(SOAP 详细信息元素)并保存它们。下面的代码有效,但只带来第一个错误,我怎样才能得到所有这些错误?

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            
}

}

【问题讨论】:

    标签: java spring saxparser spring-ws


    【解决方案1】:

    响应同here;你可以看看

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

    你有一个 ParseException 数组,你可以转储所有的。

    【讨论】:

      猜你喜欢
      • 2020-05-10
      • 2022-01-04
      • 1970-01-01
      • 2013-06-24
      • 1970-01-01
      • 1970-01-01
      • 2021-10-23
      • 2012-07-28
      • 1970-01-01
      相关资源
      最近更新 更多