0

目前我正在使用 Spring-ws 实现 Web 服务。在这里,我对 xsd 验证感到震惊。对于 xsd 验证,我使用以下配置

    <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="/WEB-INF/ProductSchema.xsd" />
  </bean>

在这里,我在 bean 初始化期间传递 xsd 文件。有什么方法可以让我动态发送这个(ProductSchema.xsd)xsd 文件。因为我会根据输入的有效负载知道需要发送哪个 xsd 文件。

请帮我。提前致谢

4

2 回答 2

0

我不知道您有多少 XSD,但也许您可以在 ProductSchema.xsd 中定义导入以包含其他 XSD。至少我是这样设置的。

例如:

<import namespace="http://namespace" schemaLocation="data.xsd" />
于 2012-07-02T14:09:44.847 回答
0

我不太确定您要做什么。

但是您可以通过使用与有效负载中的元素名称匹配的 localPart 注释处理程序方法来创建与不同有效负载匹配的不同端点/方法:

@Endpoint
public class MyEndpoint {

    @PayloadRoot(namespace = NAMESPACE_URI, localPart = "NameOfMyXmlRequestElement")     
    @ResponsePayload
    public MyResponse handleMyRequest(@RequestPayload MyRequest MyRequest) throws Exception {
    ...

然后可以使用特定模式对接收到的请求进行解组/验证:

<bean id="myJaxb2Marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
    <property name="classesToBeBound">
        <list>
            <value>mydomain.model.oxm.MyRequest</value>
            <value>mydomain.model.oxm.MyResponse</value>
        </list>
    </property>
    <property name="schema" ref="MyServiceSchema" />
</bean>

<bean id="MyServiceSchema" class="org.springframework.core.io.ClassPathResource">
    <constructor-arg value="WEB-INF/schemas/MyService.xsd" />
</bean>

必须注释 MyRequest 类才能与 Jaxb2marshaller、@XmlRootElement(name="MyRequest") 等一起使用...

于 2012-08-07T08:23:38.497 回答