Spring 将文件映射到 Url / URI

发布于 2024-08-23 23:46:44 字数 2236 浏览 2 评论 0原文

我有一个 Spring Web 服务,其架构在目录中为:

  • WebRoot/DataContract/person.xsd
  • WebRoot/DataContract/sub-person.xsd

其中 sub-person.xsd 包含在 person.xsd 中,即:

在 Person 中。 xsd:

<xsd:import     namespace="http://www.mynamespace.org/xml/sub-person" 
                schemaLocation="sub-person.xsd"/>

我已将 wsdl 定义为:

<bean id="personserv" class="org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition">   
  <property name="schemaCollection" ref="schemaCollection"/>                                               
  <property name="portTypeName" value="personserv"/>                                
  <property name="locationUri" value="/ws/personnelService/"/>                              
  <property name="targetNamespace" value="http://www.mynamespace.org/definitions"/>       
</bean>

我可以使用以下方式访问 wsdl 文件:

http:// /localhost:8080/myapp/ws/personnelService/personserv.wsdl

但是,当使用此 wsdl 时,客户端可以获取 person.xsd,但无法获取 sub-person.xsd,并给出错误 failed to load

http://localhost:8080/myapp/ws/personnelService/sub-person.xsd

我的问题是如何使 sub-person.xsd 在该 URI 位置可用?

我还将 person.xsd 中指定的位置更改为:

<xsd:import     namespace="http://www.mynamespace.org/xml/sub-person" 
                schemaLocation="/DataContract/sub-person.xsd"/>

客户端然后尝试在以下位置找到 sub-person.xsd:

http://localhost:8080/sub-person.xsd 这是不正确的。

另一种尝试是:

<xsd:import     namespace="http://www.mynamespace.org/xml/sub-person" 
                schemaLocation="DataContract/sub-person.xsd"/>

客户端随后尝试在以下位置找到 sub-person.xsd:

http://localhost:8080/myapp/ws/personnelService/DataContract/sub-person.xsd

I have a spring webservice for which I have the schema in a directory as:

  • WebRoot/DataContract/person.xsd
  • WebRoot/DataContract/sub-person.xsd

Where sub-person.xsd is included in person.xsd that is:

in Person.xsd:

<xsd:import     namespace="http://www.mynamespace.org/xml/sub-person" 
                schemaLocation="sub-person.xsd"/>

I have defined the wsdl as:

<bean id="personserv" class="org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition">   
  <property name="schemaCollection" ref="schemaCollection"/>                                               
  <property name="portTypeName" value="personserv"/>                                
  <property name="locationUri" value="/ws/personnelService/"/>                              
  <property name="targetNamespace" value="http://www.mynamespace.org/definitions"/>       
</bean>

I can access the wsdl file using:

http://localhost:8080/myapp/ws/personnelService/personserv.wsdl

However, when making use of this wsdl the client can fetch person.xsd and cannot fetch sub-person.xsd giving an error failed to load

http://localhost:8080/myapp/ws/personnelService/sub-person.xsd

my question is how can I make sub-person.xsd available at the that URI location ?

I have also changed the location specified in person.xsd as:

<xsd:import     namespace="http://www.mynamespace.org/xml/sub-person" 
                schemaLocation="/DataContract/sub-person.xsd"/>

which the client then tried to find sub-person.xsd at:

http://localhost:8080/sub-person.xsd which isn't correct.

Another attempt was:

<xsd:import     namespace="http://www.mynamespace.org/xml/sub-person" 
                schemaLocation="DataContract/sub-person.xsd"/>

which the client then tried to find sub-person.xsd at:

http://localhost:8080/myapp/ws/personnelService/DataContract/sub-person.xsd

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月朦胧 2024-08-30 23:46:44

Spring-WS 有这个 处理这个问题的非常好的工具,利用 Apache XML Commons 项目:

<bean id="schemaCollection" class="org.springframework.xml.xsd.commons.CommonsXsdSchemaCollection">
    <property name="xsds">
        <list>
            <value>/DataContract/person.xsd</value>
            <value>/DataContract/sub-person.xsd</value>
        </list>
    </property>
    <property name="inline" value="true"/>
</bean>

inline 属性是关键 - 它会读取每个模式文件,并且每当它找到 importinclude 从一个到另一个的引用,它会将引用替换为引用文件的内容。

这样做的效果是,WSDL 生成控制器的输出是一个单个文件,其中内联了所有模式信息,同时仍然使各种模式文件在服务器上保持独立。然后,您不必担心客户端是否可以追踪引用并正确解决它们,因为没有引用。

Spring-WS has this really nice facility for handling this, making use of the Apache XML Commons project:

<bean id="schemaCollection" class="org.springframework.xml.xsd.commons.CommonsXsdSchemaCollection">
    <property name="xsds">
        <list>
            <value>/DataContract/person.xsd</value>
            <value>/DataContract/sub-person.xsd</value>
        </list>
    </property>
    <property name="inline" value="true"/>
</bean>

The inline property is the key - it reads in each schema file, and whenever it finds an import or include reference from one to the other, it replaces the reference with the content of the referenced file.

The effect of this is that the output of the WSDL-generation controller is a single file with all schema information inlined within it, while still keeping the various schema files separate on the server. You then don't have to worry about if the client can chase the references and resolve them properly, since there are no references.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文