gpt4 book ai didi

java - 在 wsdl 中自定义导入 xsd : how to get to the rootelement

转载 作者:行者123 更新时间:2023-12-01 17:47:43 25 4
gpt4 key购买 nike

我有一个导入 xsd 的 wsdl 文件。在我的 pom.xml 中,我使用 Apache-CXF 和 wsdl2java 来生成代理类,但需要更改名称。这应该是可能的,因为相反,从 xsd 文件生成,类名自定义可以工作。这里的困难是我不知道如何访问我导入的 xsd 根元素。为了简单起见,我使用了一个示例项目。wsdl:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap12/"
xmlns:tns="http://www.briansdevblog.com/Accounts/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="Accounts"
targetNamespace="http://www.briansdevblog.com/Accounts/"
xmlns:accounts="http://com/blog/demo/webservices/accountservice">
<wsdl:types>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:import
namespace="http://com/blog/demo/webservices/accountservice"
schemaLocation="../schema/AccountService.xsd">
</xsd:import>
</xsd:schema>
</wsdl:types>
<wsdl:message name="AccountDetailsRequest">
<wsdl:part element="accounts:AccountDetailsRequest"
name="parameters" />
</wsdl:message>
<wsdl:message name="AccountDetailsResponse">
<wsdl:part element="accounts:AccountDetailsResponse"
name="parameters" />
</wsdl:message>
<wsdl:portType name="AccountService">
<wsdl:operation name="GetAccountDetails">
<wsdl:input message="tns:AccountDetailsRequest" />
<wsdl:output message="tns:AccountDetailsResponse" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="AccountServiceSoapBinding"
type="tns:AccountService">
<soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="GetAccountDetails">
<soap:operation
soapAction="http://www.briansjavablog.com/Accounts/GetAccountDetails" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="AccountService">
<wsdl:port binding="tns:AccountServiceSoapBinding"
name="AccountsPort">
<soap:address
location="http://localhost:8080/apache-cfx-demo/services/accounts" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

xsd:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://com/blog/demo/webservices/accountservice"
xmlns:account="http://webservices.demo.blog.com"
targetNamespace="http://com/blog/demo/webservices/accountservice"
elementFormDefault="qualified">
<xsd:complexType name="Account">
<xsd:sequence>
<xsd:element name="AccountNumber" type="xsd:string"/>
<xsd:element name="AccountName" type="xsd:string"/>
<xsd:element name="AccountBalance" type="xsd:double"/>
<xsd:element name="AccountStatus" type="EnumAccountStatus"/>
</xsd:sequence>
</xsd:complexType>
<xsd:simpleType name="EnumAccountStatus">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="Active"/>
<xsd:enumeration value="Inactive"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:element name="AccountDetailsRequest">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="accountNumber" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="AccountDetailsResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="AccountDetails" type="Account"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>

pom插件代码:

<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>${cxf.version}</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<sourceRoot>${basedir}/target/generated/java</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>${basedir}/src/main/resources/wsdl/Accounts.wsdl</wsdl>
<bindingFiles>
<bindingFile>${basedir}/src/main/resources/custom/custom.xjb</bindingFile>
</bindingFiles>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>

以及包含我记录的尝试的 xjb 文件:

<?xml version="1.0" encoding="UTF-8"?>
<jaxws:bindings wsdlLocation="../wsdl/Accounts.wsdl"
xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<!-- option 2
<jaxws:bindings node="wsdl:definitions">
<jaxws:bindings node="wsdl:types" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb">
<jaxb:bindings schemaLocation="../schema/AccountService.xsd" node="/xsd:schema">
<jaxb:bindings node="//xsd:complexType[@name='Account']">
<jaxb:class name="AccountEx"/>
</jaxb:bindings>
</jaxb:bindings>
</jaxws:bindings>
</jaxws:bindings>
no errors but also no effect
-->
<!-- option 1
<jaxws:bindings node="wsdl:definitions">
<jaxws:bindings node="wsdl:types" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb">
<jaxb:bindings schemaLocation="../schema/AccountService.xsd" node="/xsd:schema">
<jaxb:bindings xmlns:xsd="http://www.w3.org/2001/XMLSchema" node="//schema/xs:import[@namespace='http://com/blog/demo/webservices/accountservice']/xsd:complexType[@name='Account']">
<jaxb:class name="AccountEx"/>
</jaxb:bindings>
</jaxb:bindings>
</jaxws:bindings>
</jaxws:bindings>
no errors but also no effect
-->
</jaxws:bindings>

最佳答案

好的,我解决了,感谢 https://stackoverflow.com/a/20245920/10017087这比我想象的要简单:1. jaxws:bindings 用于 wsdl 编辑,使用 jaxb:bindings 用于 xsd 编辑。2.您只需指明xsd位置(jaxb:绑定(bind)schemaLocation)

<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" jaxb:version="2.0">
<jaxb:bindings
schemaLocation="../schema/AccountService.xsd">
<jaxb:bindings node="//xsd:complexType[@name='Account']">
<jaxb:class name="AccountEx" />
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>

关于java - 在 wsdl 中自定义导入 xsd : how to get to the rootelement,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60836463/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com