[
https://issues.apache.org/jira/browse/CXF-7062?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15533656#comment-15533656
]
Randy Leonard commented on CXF-7062:
------------------------------------
I've refactored my WSDL to use 'ref' instead of 'type', and get the expected
results, as you have stated.
But there remains a twist:
- The wsdl generated by CXF uses 'type', whereas the original wsdl used 'ref'
- A snippet of a CXF-generated wsdl document is given below.
- It would follow that pointing wsdl2java at a published CXF service would
*not* result in expected Java code, as I would get issues outlined at start of
this thread
Functional difference between Axis2 and CXF:
- Axis2 does leverage the alias/namespace found in 'type' parameter and would
generate the correct Java code.
- CXF ignores the alias/namespace in the 'type' parameter and generates
incorrect code (per spec?).
In other words:
- Apache Axis2: I can round-trip from WSDL to Java, then generate equivalent
Java code from the published WSDL
- Apache CXF: I cannot round-trop from WSDL, to Java, and back to WSDL
WSDL generated by a running CXF-based service:
--------
<wsdl:types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:ns2="http://v1_0_0.datatypes.provider.soap.foundation.rps.com"
xmlns:ns1="http://v1_0_0.datatypes.provider.soap.common.masterdata.rps.com"
targetNamespace="http://v1_0_0.parameters.provider.soap.common.masterdata.rps.com"
version="1.0">
<xs:import
namespace="http://v1_0_0.datatypes.provider.soap.common.masterdata.rps.com"/>
<xs:import
namespace="http://v1_0_0.datatypes.provider.soap.foundation.rps.com"/>
<xs:element name="consumerChannelFetchRequest">
<xs:complexType>
<xs:sequence>
<xs:element form="qualified" maxOccurs="unbounded" name="consumerChannelId"
type="xs:string"/>
<xs:element form="qualified" minOccurs="0" name="channelCode" type="xs:string"/>
<xs:element form="qualified" minOccurs="0" name="displayName" type="xs:string"/>
<xs:element form="qualified" minOccurs="0" name="lifecycleState"
type="xs:string"/>
<xs:element form="qualified" minOccurs="0" name="consumerChannelDetail"
type="ns1:ConsumerChannelDetail"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://v1_0_0.datatypes.provider.soap.common.masterdata.rps.com"
xmlns:ns1="http://v1_0_0.datatypes.provider.soap.foundation.rps.com"
targetNamespace="http://v1_0_0.datatypes.provider.soap.common.masterdata.rps.com"
version="1.0">
<xs:import
namespace="http://v1_0_0.datatypes.provider.soap.foundation.rps.com"/>
<xs:element name="consumerChannelDetail" type="tns:ConsumerChannelDetail"/>
<xs:complexType name="ConsumerChannelDetail">
<xs:sequence>
<xs:element form="qualified" maxOccurs="unbounded" minOccurs="0" name="code"
type="xs:string"/>
<xs:element form="qualified" name="channelLifecycle" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
</wsdl:types>
--------
> wsdl2java generates incorrect @XmlElement(namespace=“…”)
> --------------------------------------------------------
>
> Key: CXF-7062
> URL: https://issues.apache.org/jira/browse/CXF-7062
> Project: CXF
> Issue Type: Bug
> Components: Soap Binding
> Affects Versions: 3.1.7
> Environment: MacOSX 10.11, Java v1.8
> Reporter: Randy Leonard
> Assignee: Daniel Kulp
> Priority: Blocker
> Fix For: Invalid
>
>
> I am using Apache CXF 3.1.7, and the wsdl2java command is generating code
> with missing/incorrect namespace attributes on the @XMLEment annotation.
> Note I generally use four distinct namespaces within each WSDL document,
> which are as follows:
> • Shared data types across many WSDL documents
> (http://v1_0_0.datatypes.provider.soap.foundation.rps.com)
> • Domain-specific data types
> (http://v1_0_0.datatypes.provider.soap.common.masterdata.rps.com)
> • Parameter types
> (http://v1_0_0.parameters.provider.soap.common.masterdata.rps.com)
> • Service types (http://v1_0_0.provider.soap.common.masterdata.rps.com)
> This gives a nice separation of data types, and has worked quite well for me
> with Axis2. I am having issues, however, when applying this approach to CXF.
> Below is an example WSDL document with the namespaces defined above:
> ———————————————
> <?xml version="1.0" encoding="UTF-8"?>
> <wsdl:definitions
> targetNamespace="http://v1_0_0.provider.soap.common.masterdata.rps.com"
> xmlns:foundationTypes="http://v1_0_0.datatypes.provider.soap.foundation.rps.com"
>
> xmlns:masterdataCommonTypes="http://v1_0_0.datatypes.provider.soap.common.masterdata.rps.com"
> xmlns:parameter="http://v1_0_0.parameters.provider.soap.common.masterdata.rps.com"
> xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
> xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
> xmlns:tns="http://v1_0_0.provider.soap.common.masterdata.rps.com"
> xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
> xmlns:xs="http://www.w3.org/2001/XMLSchema"
> xmlns:wsoap12="http://schemas.xmlsoap.org/wsdl/soap12/"
> xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
> xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/">
> <wsdl:types>
> <xs:schema attributeFormDefault="unqualified"
> elementFormDefault="qualified"
> targetNamespace="http://v1_0_0.parameters.provider.soap.common.masterdata.rps.com"
> >
> <xs:import
> namespace="http://v1_0_0.datatypes.provider.soap.foundation.rps.com"
> schemaLocation="schemas/FoundationTypes.xsd" />
> <xs:import
> namespace="http://v1_0_0.datatypes.provider.soap.common.masterdata.rps.com"
> schemaLocation="schemas/MasterDataCommonTypes.xsd" />
> <xs:element name="consumerChannelFetchRequest">
> <xs:annotation>
> </xs:annotation>
> <xs:complexType>
> <xs:sequence>
> <xs:element
> name="paymentSchemeId" type="xs:string" minOccurs="0" />
> <xs:element name="bin"
> type="xs:string" minOccurs="0" />
> </xs:sequence>
> </xs:complexType>
> </xs:element>
> <xs:element name="consumerChannelFetchResponse">
> <xs:annotation>
> </xs:annotation>
> <xs:complexType>
> <xs:sequence>
> <xs:element name="status"
> type="foundationTypes:Status" />
> <xs:element name="channels"
> type="masterdataCommonTypes:ConsumerChannel" minOccurs="0"
> maxOccurs="unbounded" />
> </xs:sequence>
> </xs:complexType>
> </xs:element>
> <xs:element name="consumerChannelUpdateRequest">
> <xs:annotation>
> </xs:annotation>
> <xs:complexType>
> <xs:sequence>
> <xs:element
> name="paymentSchemeId" type="xs:string" minOccurs="0" />
> <xs:element name="bin"
> type="xs:string" minOccurs="0" />
> </xs:sequence>
> </xs:complexType>
> </xs:element>
> <xs:element name="consumerChannelUpdateResponse">
> <xs:annotation>
> </xs:annotation>
> <xs:complexType>
> <xs:sequence>
> <xs:element name="status"
> type="foundationTypes:Status" />
> </xs:sequence>
> </xs:complexType>
> </xs:element>
> </xs:schema>
> </wsdl:types>
> <wsdl:message name="consumerChannelFetchMessageRequest">
> <wsdl:part element="parameter:consumerChannelFetchRequest"
> name="request" />
> </wsdl:message>
> <wsdl:message name="consumerChannelFetchMessageResponse">
> <wsdl:part element="parameter:consumerChannelFetchResponse"
> name="response" />
> </wsdl:message>
> <wsdl:message name="consumerChannelUpdateMessageRequest">
> <wsdl:part element="parameter:consumerChannelUpdateRequest"
> name="request" />
> </wsdl:message>
> <wsdl:message name="consumerChannelUpdateMessageResponse">
> <wsdl:part element="parameter:consumerChannelUpdateResponse"
> name="response" />
> </wsdl:message>
> <wsdl:portType name="ConsumerChannelPortType">
> <wsdl:operation name="consumerChannelFetch">
> <wsdl:input
> message="tns:consumerChannelFetchMessageRequest"
> name="consumerChannelFetchMessageRequest" />
> <wsdl:output
> message="tns:consumerChannelFetchMessageResponse"
> name="consumerChannelFetchMessageResponse" />
> </wsdl:operation>
> <wsdl:operation name="consumerChannelUpdate">
> <wsdl:input name="consumerChannelUpdateMessageRequest"
> message="tns:consumerChannelUpdateMessageRequest" />
> <wsdl:output
> name="consumerChannelUpdateMessageResponse"
> message="tns:consumerChannelUpdateMessageResponse" />
> </wsdl:operation>
> </wsdl:portType>
> <wsdl:binding name="ConsumerChannelSoap12Binding"
> type="tns:ConsumerChannelPortType">
> <wsoap12:binding style="document"
> transport="http://schemas.xmlsoap.org/soap/http" />
> <wsdl:operation name="consumerChannelFetch">
> <soap:operation soapAction="" style="document" />
> <wsdl:input name="consumerChannelFetchMessageRequest">
> <wsoap12:body use="literal" />
> </wsdl:input>
> <wsdl:output name="consumerChannelFetchMessageResponse">
> <wsoap12:body use="literal" />
> </wsdl:output>
> </wsdl:operation>
> <wsdl:operation name="consumerChannelUpdate">
> <soap:operation soapAction="" style="document" />
> <wsdl:input name="consumerChannelUpdateMessageRequest">
> <wsoap12:body use="literal" />
> </wsdl:input>
> <wsdl:output
> name="consumerChannelUpdateMessageResponse">
> <wsoap12:body use="literal" />
> </wsdl:output>
> </wsdl:operation>
> </wsdl:binding>
> <wsdl:service name="ConsumerChannelService">
> <wsdl:port name="ConsumerChannelSoap12Endpoint"
> binding="tns:ConsumerChannelSoap12Binding">
> <wsoap12:address
> location="http://localhost:8080/axis2/services/ConsumerChannelService" />
> </wsdl:port>
> </wsdl:service>
> </wsdl:definitions>
> ———————————————
> The following generated ConsumerChannelFetchResponse class contains no
> namespace attribute for @XmlElement annotations, unless I include '-xjc-npa'
> in the wsdl2java command. When including '-xjc-npa', I then get the incorrect
> namespaces in the @XmlElement annotation. Both scenarios result in
> unmarshaling errors on the client side:
> ———————————————
> /**
> * <p>Java class for anonymous complex type.
> *
> * <p>The following schema fragment specifies the expected content contained
> within
> this class.
> *
> * <pre>
> * <complexType>
> * <complexContent>
> * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
> * <sequence>
> * <element name="status"
> type="{http://v1_0_0.datatypes.provider.soap.foundation.rps.com}Status"/>
> * <element name="channels"
> type="{http://v1_0_0.datatypes.provider.soap.common.masterdata.rps.com}ConsumerChannel"
> maxOccurs="unbounded" minOccurs="0"/>
> * </sequence>
> * </restriction>
> * </complexContent>
> * </complexType>
> * </pre>
> *
> *
> */
> @XmlAccessorType(XmlAccessType.FIELD)
> @XmlType(name = "", propOrder = {
> "status",
> "channels"
> })
> @XmlRootElement(name = "consumerChannelFetchResponse", namespace =
> "http://v1_0_0.parameters.provider.soap.common.masterdata.rps.com")
> public class ConsumerChannelFetchResponse {
> @XmlElement(namespace =
> "http://v1_0_0.parameters.provider.soap.common.masterdata.rps.com",
> required = true)
> protected Status status;
> @XmlElement(namespace =
> "http://v1_0_0.parameters.provider.soap.common.masterdata.rps.com")
> protected List<ConsumerChannel> channels;
> ……….
> ———————————————
> Note the namespace in the 'Status' variable @XmlElement annotation for the
> above code should be:
> • http://v1_0_0.datatypes.provider.soap.foundation.rps.com
> But is the following instead:
> • http://v1_0_0.parameters.provider.soap.common.masterdata.rps.com
> A close examination of the comment block prior to the
> ConsumerChannelFetchResponse class declaration indicates wsdl2java cleary
> understands the Status type is from the correct class, but the namespace
> attribute in the @XmlElement does not reflect this.
> I've tried generating this class using both the cxf-codegen-plugin plugin,
> and executing wsdl2java directly from the command line. Both to no avail.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)