lin*_*tto 5 java spring xsd wsdl spring-ws
我正在尝试基于多个xml模式为Spring WS Web服务动态生成WSDL。我有多个xsd文件,所有文件都使用xsd:import元素“连接”。
Spring WS参考说:
如果要使用包含或导入的多个模式,则需要将Commons XMLSchema放在类路径上。如果Commons XMLSchema位于类路径上,则上述元素将跟随所有XSD导入和包含,并将它们作为单个XSD内联到WSDL中。这极大地简化了架构的部署,仍然使分别编辑它们成为可能。
所以我添加了这个Maven依赖项:
<dependency>
<groupId>org.apache.ws.xmlschema</groupId>
<artifactId>xmlschema-core</artifactId>
<version>2.2.1</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
并以这种方式配置WSDL构建器:
@Bean(name="updateContactService")
public DefaultWsdl11Definition defaultWsdl11Definition() throws Exception {
DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
wsdl11Definition.setPortTypeName("updateContactPort");
wsdl11Definition.setLocationUri("/ws/updateContact");
wsdl11Definition.setTargetNamespace("http://spring.io/guides/gs-producing-web-service");
wsdl11Definition.setSchema(updateContactXsd());
return wsdl11Definition;
}
@Bean
public XsdSchemaCollection updateContactXsd() throws Exception {
return new SimpleXsdSchema(new ClassPathResource("xsds/contact/outboundMessage.xsd"));
}
Run Code Online (Sandbox Code Playgroud)
但是生成的WSDL仅包含一个架构元素(并以错误的位置显示了导入)。
<xs:import namespace="http://xmlns.oracle.com/apps/cdm/foundation/parties/personService/" schemaLocation="personService.xsd"/>
Run Code Online (Sandbox Code Playgroud)
有小费吗?Spring WS版本是2.3.1
<?xml version="1.0" encoding="UTF-8" standalone="no"?><wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:sch="http://xmlns.oracle.com/apps/crmCommon/content/outboundMessage/types/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://spring.io/guides/gs-producing-web-service" targetNamespace="http://spring.io/guides/gs-producing-web-service">
<wsdl:types>
<xs:schema xmlns="http://xmlns.oracle.com/apps/crmCommon/content/outboundMessage/types/" xmlns:ns2="http://xmlns.oracle.com/apps/cdm/foundation/parties/personService/" xmlns:tns0="http://xmlns.oracle.com/apps/crmCommon/content/outboundMessage/types/" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://xmlns.oracle.com/apps/crmCommon/content/outboundMessage/types/">
<xs:import namespace="http://xmlns.oracle.com/apps/cdm/foundation/parties/personService/" schemaLocation="personService.xsd"/>
<xs:element name="process" type="tns0:processType"/>
<xs:complexType name="processType">
<xs:sequence>
<xs:element maxOccurs="unbounded" minOccurs="0" name="Person" type="ns2:Person"/>
</xs:sequence>
</xs:complexType>
<xs:element name="processResponse" type="tns0:processResponseType"/>
<xs:complexType name="processResponseType">
<xs:sequence>
<xs:element maxOccurs="unbounded" minOccurs="0" name="Person" type="ns2:Person"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
</wsdl:types>
<wsdl:message name="processResponse">
<wsdl:part element="sch:processResponse" name="processResponse">
</wsdl:part>
</wsdl:message>
<wsdl:portType name="updateContactPort">
<wsdl:operation name="process">
<wsdl:output message="tns:processResponse" name="processResponse">
</wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="updateContactPortSoap11" type="tns:updateContactPort">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="process">
<soap:operation soapAction=""/>
<wsdl:output name="processResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="updateContactPortService">
<wsdl:port binding="tns:updateContactPortSoap11" name="updateContactPortSoap11">
<soap:address location="https://localhost:4440/ws/updateContact"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
Run Code Online (Sandbox Code Playgroud)
解决了!
我不得不使用XsdSchemaCollection而不是SimpleXsdSchema。另外,我必须将集合的“内联”参数设置为true。
@Bean(name="updateContactService")
public DefaultWsdl11Definition defaultWsdl11Definition() throws Exception {
DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
wsdl11Definition.setPortTypeName("updateContactPort");
wsdl11Definition.setLocationUri("/ws/updateContact");
wsdl11Definition.setTargetNamespace("http://spring.io/guides/gs-producing-web-service");
wsdl11Definition.setSchemaCollection(updateContactXsd());
return wsdl11Definition;
}
@Bean
public XsdSchemaCollection updateContactXsd() throws Exception {
CommonsXsdSchemaCollection xsds = new CommonsXsdSchemaCollection(new ClassPathResource("xsds/contact/outboundMessage.xsd"));
xsds.setInline(true); <-------------------
return xsds;
}
Run Code Online (Sandbox Code Playgroud)
注意 :
xsds.setInline(true);
我将在Jira上发表一个问题,因为我认为该参考文献不清楚!
归档时间: |
|
查看次数: |
4299 次 |
最近记录: |