Java 如何根据WSDL-SpringBoot和SpringWS打开验证
在我的模式中,我有以下元素:Java 如何根据WSDL-SpringBoot和SpringWS打开验证,java,web-services,spring-boot,soap,spring-ws,Java,Web Services,Spring Boot,Soap,Spring Ws,在我的模式中,我有以下元素: <xs:element name="deletePokemonsRequest"> <xs:complexType> <xs:sequence> <xs:element name="pokemonId" type="xs:int" minOccurs="1" maxOccurs="unbounded"/> </xs:sequence>
<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>
当我在此端点上发送时:
<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
}
@配置
@使能
公共类MyWsConfig扩展了WsConfigurerAdapter{
@凌驾
公共void附加侦听器(列表侦听器){
PayloadValidatingInterceptor validatingInterceptor=新的PayloadValidatingInterceptor();
validatingInterceptor.setValidateRequest(true);
validatingInterceptor.setValidateResponse(true);
验证interceptor.setXsdSchema(yourSchema());
添加(验证Interceptor);
}
@豆子
公共XsdSchema yourSchema(){
返回新的simplexsdsdschema(新的类路径资源(“your.xsd”);
}
//剪其他东西
}
@HaskellFun PayloadValidatingInterceptor还为模式列表设置了xsdschemacollection()方法。我对许多文件有问题。您能用许多xsd文件附加示例吗?您使用@Override覆盖了您所覆盖的内容?配置类扩展了。
@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
}