I have a project that exposes several SOAP endpoints. I want to use PayloadValiditatingInterceptor provided by Spring WS to validate only a particular end-point. However, my current implementation is applying validation to each and every SOAP endpoint.
The source code is as follows:
@Bean(name = "requestMessage")
public SimpleXsdSchema requestMessage()
{
return new SimpleXsdSchema(new ClassPathResource("com/schemas/2_0/requestMessage.xsd"));
}
@Override
public void addInterceptors(List<EndpointInterceptor> interceptors)
{
PayloadValidatingInterceptor validatingInterceptor = new PayloadValidatingInterceptor();
validatingInterceptor.setValidateRequest(true);
validatingInterceptor.setXsdSchema(requestMessage());
interceptors.add(validatingInterceptor);
}
I was able to get this working by removing the addInterceptors method and adding the following lines in Configuration class.
public class SoapConfig extends WsConfigurerAdapter
{
@Bean
PayloadValidatingInterceptor myEndpointValidatingInterceptor() {
PayloadValidatingInterceptor interceptor = new
PayloadValidatingInterceptor();
interceptor.setValidateRequest(true);
interceptor.setXsdSchema(requestMessage());
return interceptor;
}
@Bean
PayloadRootSmartSoapEndpointInterceptor myEndpointValidator() {
return new
PayloadRootSmartSoapEndpointInterceptor(myEndpointValidatingInterceptor(),
RequestEndPoint.NAMESPACE, RequestEndPoint.REQUEST_LOCAL_PART);
}
}