该应用程序使用 spring ws 构建 SOAP Web 服务。有效负载的 XSD 包含另一个 XSD 架构文件,其中包含跨多个架构文件的可重用组件( header 等)。
我能够使用 JAXB 成功生成相应的 Java 对象。
调度程序 servlet 如下:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:sws="http://www.springframework.org/schema/web-services"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/web-services http://www.springframework.org/schema/web-services/web-services-2.0.xsd">
<import resource="service-context.xml" />
<sws:annotation-driven />
<context:component-scan
base-package="com.test.service" />
<!-- SOAP Fault Annotation Exception Resolver -->
<bean
class="org.springframework.ws.soap.server.endpoint.SoapFaultAnnotationExceptionResolver" />
<!-- ############## WSDL Definitions ################## -->
<sws:dynamic-wsdl id="sampleEndpoint"
portTypeName="sampleEndpoint" locationUri="/sampleEndpoint/">
<sws:xsd location="/WEB-INF/xsd/samplePayload.xsd" />
</sws:dynamic-wsdl>
</beans>
包含第二个架构的主 *.xsd 文件的片段:
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:abc="www.example.com">
<xsd:include schemaLocation="common.xsd"></xsd:include>
<element name="SampleRequest">
<complexType>
<sequence>
<element name="MsgRqHdr">
<complexType>
<sequence>
<element name="UID" type="string" minOccurs="1"
maxOccurs="1" />
</sequence>
</complexType>
</element>
.........
应用程序部署到 Apache Tomcat v9 服务器。 wsdl在浏览器上测试成功;我可以发现此 wsdl 中提供的所有操作,并且包含的 *.xsd 架构文件也可见:
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:sch="www.example.com" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="www.example.com" targetNamespace="www.example.com">
<wsdl:types>
<xsd:schema xmlns="www.example.com" xmlns:xsd="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="www.example.com">
**<xsd:include schemaLocation="common.xsd"/>**
<xsd:element name="SampleRq" type="SampleRq_Type"/>
<xsd:element name="SampleRs" type="SampleRs_Type"/>
<xsd:annotation>
<xsd:documentation source="DES">
..........
现在使用 SoapUI 进行测试。项目创建失败并出现以下注释:
加载时出错[ http://localhost:8080/sample/common.xsd] :org.apache.xmlbeans.XmlException:org.apache.xmlbeans.XmlException:错误:nul后出现意外的文件结束
我引用了之前提出的以下问题:
2- soapUI - issue with wsdl that includes xsd
这表明 WSDL 由于某种原因未能找到此架构文件。我在 StackOverflow 上搜索了类似的问题,这些问题几乎完全描述了我的情况,但没有明确的答案。至多,问题已经被诊断出来,没有关于如何正确修复它的附加信息。
如果我尝试在另一个浏览器选项卡中打开 *.xsd 文件,则无法打开它,因为无法找到它。所以问题在于定义文档的正确路径,我不知道该怎么做。
问题是,如何在另一个文件中正确定义和/或包含 *.xsd 架构文件,以便可以正确识别它?
提前谢谢您,
最佳答案
我还使用了包含的 . xsd 来自另一个,但我使用导入标签。我的主 .xsd 看起来像这样
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://My_WS_01_00_00.Local"
xmlns:tns="http://My_WS_01_00_00.Local"
xmlns:ts="http://jaxb2-commons.dev.java.net/basic/toString"
elementFormDefault="qualified" xmlns:pref="http://Types_WS_01_00_00">
<import schemaLocation="../../1.0.0/My_WS_Types.xsd" namespace="http://Types_WS_01_00_00"></import>
<element name="LoginRequest">
<complexType>
<sequence>
<element name="username" type="string" />
<element name="password" type="string" />
</sequence>
</complexType>
</element>
<element name="LoginResponse">
<complexType>
<sequence>
<element name="answer" type="int" />
<element name="operator" type="pref:WS_Operator" />
</sequence>
</complexType>
</element>
我包含的 .xsd 是这样的:
<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://Types_WS_01_00_00"
xmlns:tns="http://Types_WS_01_00_00"
elementFormDefault="qualified">
<complexType name="WS_Operator">
<sequence>
<element name="id" type="long" />
<element name="username" type="string" />
<element name="name" type="string" />
<element name="surname" type="string" />
<element name="language" type="long" />
</sequence>
</complexType>
希望对你有帮助
关于java - SoapUI 执行涉及 XSD 的 WSDL 时出现问题,其中包括 (<xsd :include/>) another XSD,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59244192/