[英]Spring-ws: How to create Wsdl from an xsd with no “Request” element
[英]How to switch on validation according to WSDL - spring boot and spring-ws
在我的架构中,我有以下元素:
<xs:element name="deletePokemonsRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="pokemonId" type="xs:int" minOccurs="1" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
我有它的端点:
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "deletePokemonsRequest")
@ResponsePayload
public DeletePokemonsRequest deletePokemons(@RequestPayload DeletePokemonsRequest deletePokemons){
pokemonDAO.deletePokemons(deletePokemons.getPokemonId());
return deletePokemons;
}
当我发送此端点时:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:pok="www">
<soapenv:Header/>
<soapenv:Body>
<pok:deletePokemonsRequest>
</pok:deletePokemonsRequest>
</soapenv:Body>
</soapenv:Envelope>
它被接受,但在验证阶段应该被拒绝。 为什么? 因为我设置了minOccurs=1
,但它接受了包含0
元素的信封。
如何根据WSDL启用验证?
配置验证拦截器。
xml配置
<bean id="validatingInterceptor" class="org.springframework.ws.soap.server.endpoint.interceptor.PayloadValidatingInterceptor">
<property name="xsdSchema" ref="schema" />
<property name="validateRequest" value="true" />
<property name="validateResponse" value="true" />
</bean>
<bean id="schema" class="org.springframework.xml.xsd.SimpleXsdSchema">
<property name="xsd" value="your.xsd" />
</bean>
或者使用java配置
@Configuration
@EnableWs
public class MyWsConfig extends WsConfigurerAdapter {
@Override
public void addInterceptors(List<EndpointInterceptor> interceptors) {
PayloadValidatingInterceptor validatingInterceptor = new PayloadValidatingInterceptor();
validatingInterceptor.setValidateRequest(true);
validatingInterceptor.setValidateResponse(true);
validatingInterceptor.setXsdSchema(yourSchema());
interceptors.add(validatingInterceptor);
}
@Bean
public XsdSchema yourSchema(){
return new SimpleXsdSchema(new ClassPathResource("your.xsd"));
}
// snip other stuff
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.