Spring-WS:如何在响应中捕获`XML验证错误?

时间:2017-11-16 12:38:56

标签: spring validation exception spring-boot spring-ws

Collegues,在我的网络服务配置中,我有inteceptor验证肥皂请求和响应:

@EnableWs
@Configuration
@EnableAutoConfiguration
@ComponentScan(basePackages = {"com.facepital"})
@PropertySource("classpath:application-${env}.properties")

public class StmWsConfig extends WsConfigurerAdapter {

    @Bean
    public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) {
        MessageDispatcherServlet servlet = new MessageDispatcherServlet();
        servlet.setApplicationContext(applicationContext);
        return new ServletRegistrationBean(servlet, "/checks/ws/*");
    }


    @Bean(name = "checks")
    public Wsdl11Definition defaultWsdl11Definition() {
        SimpleWsdl11Definition wsdl11Definition = new SimpleWsdl11Definition();
        wsdl11Definition.setWsdl(new ClassPathResource("/wsdl/checks.wsdl"));
        return wsdl11Definition;
    }



    @Override
    public void addInterceptors(List<EndpointInterceptor> interceptors) {
        PayloadValidatingInterceptor validatingInterceptor = new PayloadValidatingInterceptor();
        validatingInterceptor.setValidateRequest(true);
        validatingInterceptor.setValidateResponse(true);
        validatingInterceptor.setXsdSchema(checksXsdSchema());
        interceptors.add(validatingInterceptor);
    }


    @Bean
    public XsdSchema checksXsdSchema(){
        return new SimpleXsdSchema(new ClassPathResource("/xsds/checks.wsdl#schema1.xsd"));
    }

}

我的问题是,在XML validation error on response的情况下,Web服务会返回响应,但不会这样做。如果它无效,则无法返回响应。

登录错误如下:

14:53:49.731 ERROR [http-nio-8083-exec-1] o.s.w.s.s.e.i.PayloadValidatingInterceptor - XML validation error on response: cvc-pattern-valid: Value '2017-11-16T14:53:49.713+03:00' is not facet-valid with respect to pattern '((000[1-9])|(00[1-9][0-9])|(0[1-9][0-9]{2})|([1-9][0-9]{3}))-((0[1-9])|(1[012]))-((0[1-9])|([12][0-9])|(3[01]))T(([01][0-9])|(2[0-3]))(:[0-5][0-9])(:[0-5][0-9])' for type '#AnonType_responseTimestampResponseHeaderType'.
14:53:49.732 ERROR [http-nio-8083-exec-1] o.s.w.s.s.e.i.PayloadValidatingInterceptor - XML validation error on response: cvc-type.3.1.3: The value '2017-11-16T14:53:49.713+03:00' of element 'ns2:responseTimestamp' is not valid.
14:53:49.732 ERROR [http-nio-8083-exec-1] o.s.w.s.s.e.i.PayloadValidatingInterceptor - XML validation error on response: cvc-length-valid: Value '' with length = '0' is not facet-valid with respect to length '34' for type 'checkMsgId'.
14:53:49.732 ERROR [http-nio-8083-exec-1] o.s.w.s.s.e.i.PayloadValidatingInterceptor - XML validation error on response: cvc-type.3.1.3: The value '' of element 'ns2:checkMsgId' is not valid.

如何抓住XML validation error on response?例如,如果responseTimestamp无效,则程序应引发异常。

0 个答案:

没有答案