我正在从事SpringBoot SOAP WS项目,我必须对传入的请求进行xsd验证,我有3个WSDL(意味着要验证3个URL),但不幸的是,我能够做一个。在下面的代码中,addInterceptors()添加了hotelDirectUpdateSchema(),与此类似,我还有2个xsd。 如何处理3个请求验证?
@EnableWs
@Configuration
public class WSConfiguration extends WsConfigurerAdapter {
@Bean
public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) {
MessageDispatcherServlet servlet = new MessageDispatcherServlet();
servlet.setApplicationContext(applicationContext);
servlet.setTransformWsdlLocations(true);
return new ServletRegistrationBean(servlet, "/service/*");
}
@Override
public void addInterceptors(List<EndpointInterceptor> interceptors) {
PayloadValidatingInterceptor validatingInterceptor = new PayloadValidatingInterceptor();
validatingInterceptor.setValidateRequest(true);
validatingInterceptor.setValidateResponse(true);
validatingInterceptor.setXsdSchema(hotelDirectUpdateSchema());
interceptors.add(validatingInterceptor);
}
}
答案 0 :(得分:0)
我能够在下面将其修复为解决方案
@Override
public void addInterceptors(List<EndpointInterceptor> interceptors) {
HotelDirectUpdateRQValidator validatingInterceptor = new HotelDirectUpdateRQValidator();
validatingInterceptor.setValidateRequest(true);
validatingInterceptor.setValidateResponse(false);
validatingInterceptor.setXsdSchemaCollection(new XsdSchemaCollection() {
@Override
public XsdSchema[] getXsdSchemas() {
return null;
}
@Override
public XmlValidator createValidator() {
try {
return XmlValidatorFactory.createValidator(getSchemas(), "http://www.w3.org/2001/XMLSchema");
} catch (Exception e) {
LOGGER.error("Failed to create validator e={}", e);
}
return null;
}
public Resource[] getSchemas() {
return new Resource[]{
new ClassPathResource("/schemas/OTA/OTA_HotelRateAmountNotifAndHotelAvailNotifRQValidate.xsd"),
new ClassPathResource("/schemas/HotelDirectUpdateRQ.xsd")
};
}
});
interceptors.add(validatingInterceptor);
}