简体   繁体   English

Spring将文件映射到Url / URI

[英]Spring Map a file to a Url / URI

I have a spring webservice for which I have the schema in a directory as: 我有一个春季网络服务,其目录中的架构如下:

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

Where sub-person.xsd is included in person.xsd that is: 其中sub-person.xsd包含在person.xsd中,即:

in Person.xsd: 在Person.xsd中:

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

I have defined the wsdl as: 我已经将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>

I can access the wsdl file using: 我可以使用以下方式访问wsdl文件:

http://localhost:8080/myapp/ws/personnelService/personserv.wsdl HTTP://本地主机: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 但是,使用此wsdl时,客户端可以获取person.xsd,而无法获取sub-person.xsd,从而导致错误加载失败

http://localhost:8080/myapp/ws/personnelService/sub-person.xsd HTTP://本地主机:8080 / MyApp的/ WS / personnelService /子person.xsd

my question is how can I make sub-person.xsd available at the that URI location ? 我的问题是如何在该URI位置提供sub-person.xsd?

I have also changed the location specified in person.xsd as: 我也将person.xsd中指定的位置更改为:

<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: 然后客户端尝试在以下位置找到sub-person.xsd:

http://localhost:8080/sub-person.xsd which isn't correct. http:// localhost:8080 / sub-person.xsd不正确。

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: 然后客户端尝试在以下位置找到sub-person.xsd:

http://localhost:8080/myapp/ws/personnelService/DataContract/sub-person.xsd HTTP://本地主机:8080 / MyApp的/ WS / personnelService / DataContract /子person.xsd

Spring-WS has this really nice facility for handling this, making use of the Apache XML Commons project: 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>

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. inline属性是关键-它读取每个模式文件,并且每当找到一个importinclude从另一个到另一个的引用时,它将用引用文件的内容替换引用。

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. 这样的效果是,WSDL生成控制器的输出是一个单个文件,其中内联了所有模式信息,同时仍将各种模式文件保留在服务器上。 You then don't have to worry about if the client can chase the references and resolve them properly, since there are no references. 然后,您不必担心如果客户端可以追逐的引用,妥善解决他们,因为没有引用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM