PayloadValidatingInterceptor没有为@Endpoint触发?

时间:2016-01-21 19:49:56

标签: java validation spring-ws

我有一个应用程序,我想自动验证收到和发送的邮件。我已经附加了@EnableWs @Configuration public class WebServiceConfig extends WsConfigurerAdapter { @Autowired private ApplicationContext ctx; @Bean public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) { MessageDispatcherServlet servlet = new MessageDispatcherServlet(); servlet.setApplicationContext(applicationContext); // modifies the wsdl to serve the correct locations servlet.setTransformWsdlLocations(true); return new ServletRegistrationBean(servlet, "/*"); } @Bean protected PayloadValidatingInterceptor getValidatingInterceptor() { PayloadValidatingInterceptor validatingInterceptor = new PayloadValidatingInterceptor(); validatingInterceptor.setSchema(getResource("classpath:CARetriever.xsd")); validatingInterceptor.setValidateRequest(true); validatingInterceptor.setValidateResponse(true); return validatingInterceptor; } private Resource getResource(String resource) { return ctx.getResource(resource); } } 并设置了我希望使用的架构:

2016-01-21 14:22:08 INFO  org.springframework.ws.soap.server.endpoint.interceptor.PayloadValidatingInterceptor,164 - Validating using class path resource [CARetriever.xsd]

我可以看到拦截器正在加载

NullPointerException

但是,当我针对它抛出无效的SOAP消息时,我得到/* add product subhead custom field to woocommerce product dashboard */ add_action( 'woocommerce_product_options_general_product_data', 'woo_add_custom_general_fields' ); function woo_add_custom_general_fields() { global $woocommerce, $post; echo '<div class="options_group">'; woocommerce_wp_text_input( array( 'id' => '_text_field', 'label' => __( 'MY-LABEL', 'woocommerce' ), 'placeholder' => 'Author', 'desc_tip' => 'true', 'description' => __( 'This text will show below the product title.', 'woocommerce' ) ) ); echo '</div>'; } /* Save woo custom field */ add_action( 'woocommerce_process_product_meta', 'woo_add_custom_general_fields_save' ); function woo_add_custom_general_fields_save( $post_id ){ $woocommerce_text_field = $_POST['_text_field']; if( !empty( $woocommerce_text_field ) ) update_post_meta( $post_id, '_text_field', esc_attr( $woocommerce_text_field ) ); } /* add author below title on single product */ function cn_add_subhead_to_title() { global $woocommerce, $post; $meta = get_post_meta( $post->ID, '_text_field', true ); if( $meta != '' ) { ?> <div class="cn-subhead"> by <?php echo get_post_meta( $post->ID, '_text_field', true ); ?> </div> <?php } } add_action( 'woocommerce_single_product_summary', 'cn_add_subhead_to_title', 6 ); 而不是验证消息。所以,我的配置或期望都是错误的。有人可以指出哪个?

1 个答案:

答案 0 :(得分:0)

我得到了同样的错误:内部有NPE且没有堆栈跟踪的SOAPFault。在调试时我注意到PayloadValidatingInterceptor中使用的验证器实例为null,因为setSchema没有初始化它。但是有方法setXsdSchema, 初始化它。所以,我可以使用该方法而不是setSchema来修复NPE,如下所示:

payloadValidatingInterceptor.setXsdSchema(new SimpleXsdSchema(new ClassPathResource("test.xsd")));

有关完整示例,可以查看此示例:http://memorynotfound.com/spring-ws-validate-soap-request-response-xsd-schema/

希望有所帮助。