I'm sending requests to SOAP WS from Java project. By wsdl I have generated required sources using:
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>3.1.6</version>
WSDL that I use has following fields:
<xs:complexType name="HitOffers">
<xs:sequence>
<xs:element minOccurs="0" name="Comment" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="Offers" nillable="true" type="tns:ArrayOfHitOfferBase"/>
</xs:sequence>
</xs:complexType>
<xs:element name="HitOffers" nillable="true" type="tns:HitOffers"/>
<xs:complexType name="ArrayOfHitOfferBase">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="HitOfferBase" nillable="true"
type="tns:HitOfferBase"/>
</xs:sequence>
</xs:complexType>
<xs:element name="ArrayOfHitOfferBase" nillable="true" type="tns:ArrayOfHitOfferBase"/>
<xs:complexType name="HitOfferBase">
<xs:sequence>
<xs:element minOccurs="0" name="Id" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="IsExported" type="xs:boolean"/>
<xs:element minOccurs="0" name="IsRequired" type="xs:boolean"/>
<xs:element minOccurs="0" name="Order" type="xs:int"/>
<xs:element minOccurs="0" name="Status" nillable="true" type="tns:OfferStatus"/>
</xs:sequence>
</xs:complexType>
So, in the request I want to see something like:
<b:Offers xmlns:c="http://schemas.datacontract.org/2004/07/TCSBank.Common.Model.Applications.Offers">
<c:Comment i:nil="true"/>
<c:Offers>
<c:HitOfferBase
xmlns:d="http://schemas.datacontract.org/2004/07/TCSBank.Common.Model.Applications.PreCollection.Offers.Mail"
i:type="d:PreCollectionMailOffer">
<c:Id>xxx</c:Id>
<c:IsExported>false</c:IsExported>
<c:IsRequired>true</c:IsRequired>
<c:Order>1</c:Order>
<c:Status i:nil="true"/>
<d:Mail xmlns:e="http://schemas.datacontract.org/2004/07/TCSBank.Common.Model.Applications.Offers.Blocks">
<c:BlockResult i:nil="true"/>
<c:IsWithClarify>false</c:IsWithClarify>
<c:Name>xxx</c:Name>
<c:OriginalValue>mail123@yandex.ru</c:OriginalValue>
<e:Value i:nil="true"/>
</d:Mail>
</c:HitOfferBase>
</c:Offers>
</b:Offers>
But my request looks a bit different:
<ns28:Offers>
<ns10:ArrayOfHitOfferBase>
<ns10:HitOfferBase xsi:type="ns26:PreCollectionMailOffer">
<ns10:Id>425100970</ns10:Id>
<ns10:IsExported>false</ns10:IsExported>
<ns10:IsRequired>true</ns10:IsRequired>
<ns10:Order>1</ns10:Order>
<ns20:MailOfferBlock>
<ns10:IsWithClarify>false</ns10:IsWithClarify>
<ns10:Name>??????? email</ns10:Name>
<ns10:OriginalValue xsi:nil="true"/>
</ns20:MailOfferBlock>
</ns10:HitOfferBase>
</ns10:ArrayOfHitOfferBase>
As you can see we got ArrayOfHitOfferBase tag name instead of Offers, which is wrong (The Comment param is null so there is no tag). My generated sources are fine. Top class HitOffers source looks fine:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "HitOffers", namespace = "http://schemas.datacontract.org/2004/07/TCSBank.Common.Model.Applications.Offers", propOrder = {
"comment",
"offers"
})
public class HitOffers {
@XmlElementRef(name = "Comment", namespace = "http://schemas.datacontract.org/2004/07/TCSBank.Common.Model.Applications.Offers", type = JAXBElement.class)
protected JAXBElement<String> comment;
@XmlElementRef(name = "Offers", namespace = "http://schemas.datacontract.org/2004/07/TCSBank.Common.Model.Applications.Offers", type = JAXBElement.class)
protected JAXBElement<ArrayOfHitOfferBase> offers;
As you see the field @XmlElementRef attribute name = "Offers" which is right. Can anybody help me to understand the reathon of the problem and how to get rid of this wrong naming?
Thanx in advance!
Found my mistake. cxf-codegen-plugin
creates ObjectFactory class containing methods for creating WSDL objects as well as JAXBElement objects. So I was creating
ArrayOfHitOfferBase arrayOfHitOfferBase1 = factoryData.createArrayOfHitOfferBase()
instean of
JAXBElement hitOffersOffers = factoryData.createHitOffersOffers(arrayOfHitOfferBase)
Unfortinately HitOffers
object after being generated with plugin accepts ArrayOfHitOfferBase
as well as JAXBElement<ArrayOfHitOfferBase>