Spring WS: How to get and save XSD validation errors

后端 未结 1 1803
深忆病人
深忆病人 2021-01-11 13:06

I use SpringWS for my soap service and validate it like this;

 
    

        
相关标签:
1条回答
  • 2021-01-11 13:53

    you can extend PayloadValidationInterceptor and redefine the method

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

    If you look at the standard implementation (available here) you can see how it dumps all the parsing errors; you can also dump the incoming message since you have access to messageContext and its getRequest() method. Your class xould be something like

    public class PayloadValidationgInterceptorCustom extends
    PayloadValidatingInterceptor {
    
    @Override
    protected boolean handleRequestValidationErrors(MessageContext messageContext, SAXParseException[] errors)
            throws TransformerException {
        messageContext.getRequest().writeTo(/*place your Outputstream here something like a ByteArrayOutputStream*/); //use this if you want to dump the message
        for (SAXParseException error : errors) {
            //dump the each error on the db o collect the stack traces in a single string and dump only one or to the database
           /*you can use something like this
             StringWriter sw = new StringWriter();
             PrintWriter pw = new PrintWriter(sw);
             error.printStackTrace(pw);
             sw.toString();
             to get the stack trace
            */
    
        }
        return super.handleRequestValidationErrors(messageContext,errors);
    
    }
    
    0 讨论(0)
提交回复
热议问题