Я использую apache cxf 2.7.8 и создаю классы с помощью cxf-codegen-plugin.
Моя проблема в том, что в запросе cxf использует неправильное пространство имен.
Это был бы идеальный запрос:
<soap:Body>
<ns3:ImportFile xmlns="http://schemas.datacontract.org/2004/07/NDDWH.Model.Contracts" xmlns:ns2="http://schemas.datacontract.org/2004/07/Framework.Business.Contracts" xmlns:ns3="http://fakeaddress.hu/" xmlns:ns4="http://schemas.microsoft.com/2003/10/Serialization/">
<ns3:fileImportRequest>
<FileContent>cid:7f626b0b-d398-4513-8195-6752d0592807-1</FileContent>
<FileHash>3b1e9401209858c408103ded300e665c</FileHash>
<FileName>xml_1556265450288.zip</FileName>
</ns3:fileImportRequest>
</ns3:ImportFile>
И вот что я получаю сейчас:
<soap:Body>
<ns3:ImportFile xmlns="http://schemas.datacontract.org/2004/07/NDDWH.Model.Contracts" xmlns:ns2="http://schemas.datacontract.org/2004/07/Framework.Business.Contracts" xmlns:ns3="http://fakeaddress.hu/" xmlns:ns4="http://schemas.microsoft.com/2003/10/Serialization/">
<ns3:fileImportRequest>
<ns4:base64Binary>
<xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:ae4bba67-cb07-4740-9418-d12d04108b0b-1@schemas.microsoft.com"/>
</ns4:base64Binary>
<ns4:string>3b1e9401209858c408103ded300e665c</ns4:string>
<ns4:string>xml_1556265450288.zip</ns4:string>
</ns3:fileImportRequest>
</ns3:ImportFile>
Каким-то образом cxf использует пространство имен "http://schemas.microsoft.com/2003/10/Serialization/" вместо пространства имен" NDDWH.Model.Contracts ".
Поэтому вместо «FileHash» отображается «ns4: string».
У меня есть следующий фрагмент wsdl:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://schemas.microsoft.com/2003/10/Serialization/" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://schemas.microsoft.com/2003/10/Serialization/">
<xs:element name="anyType" nillable="true" type="xs:anyType" />
<xs:element name="anyURI" nillable="true" type="xs:anyURI" />
<xs:element name="base64Binary" nillable="true" type="xs:base64Binary" />
<xs:element name="boolean" nillable="true" type="xs:boolean" />
<xs:element name="byte" nillable="true" type="xs:byte" />
<xs:element name="dateTime" nillable="true" type="xs:dateTime" />
<xs:element name="decimal" nillable="true" type="xs:decimal" />
<xs:element name="double" nillable="true" type="xs:double" />
<xs:element name="float" nillable="true" type="xs:float" />
<xs:element name="int" nillable="true" type="xs:int" />
<xs:element name="long" nillable="true" type="xs:long" />
<xs:element name="QName" nillable="true" type="xs:QName" />
<xs:element name="short" nillable="true" type="xs:short" />
<xs:element name="string" nillable="true" type="xs:string" />
<xs:element name="unsignedByte" nillable="true" type="xs:unsignedByte" />
<xs:element name="unsignedInt" nillable="true" type="xs:unsignedInt" />
<xs:element name="unsignedLong" nillable="true" type="xs:unsignedLong" />
<xs:element name="unsignedShort" nillable="true" type="xs:unsignedShort" />
<xs:element name="char" nillable="true" type="tns:char" />
<xs:simpleType name="char">
<xs:restriction base="xs:int" />
</xs:simpleType>
<xs:element name="duration" nillable="true" type="tns:duration" />
<xs:simpleType name="duration">
<xs:restriction base="xs:duration">
<xs:pattern value="\-?P(\d*D)?(T(\d*H)?(\d*M)?(\d*(\.\d*)?S)?)?" />
<xs:minInclusive value="-P10675199DT2H48M5.4775808S" />
<xs:maxInclusive value="P10675199DT2H48M5.4775807S" />
</xs:restriction>
</xs:simpleType>
<xs:element name="guid" nillable="true" type="tns:guid" />
<xs:simpleType name="guid">
<xs:restriction base="xs:string">
<xs:pattern value="[\da-fA-F]{8}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{12}" />
</xs:restriction>
</xs:simpleType>
<xs:attribute name="FactoryType" type="xs:QName" />
<xs:attribute name="Id" type="xs:ID" />
<xs:attribute name="Ref" type="xs:IDREF" />
</xs:schema>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://schemas.datacontract.org/2004/07/NDDWH.Model.Contracts" elementFormDefault="qualified" targetNamespace="http://schemas.datacontract.org/2004/07/NDDWH.Model.Contracts">
<xs:import namespace="http://schemas.datacontract.org/2004/07/Framework.Business.Contracts" />
<xs:complexType name="FileImportRequestContract">
<xs:sequence>
<xs:element minOccurs="0" name="FileContent" nillable="true" type="xs:base64Binary" />
<xs:element minOccurs="0" name="FileHash" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="FileName" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="Id" type="xs:long" />
<xs:element minOccurs="0" name="OpFlag" nillable="true" type="xs:string" />
<xs:element xmlns:q1="http://schemas.datacontract.org/2004/07/Framework.Business.Contracts" minOccurs="0" name="OpMessages" nillable="true" type="q1:ArrayOfContractMessage" />
</xs:sequence>
</xs:complexType>
<xs:element name="FileImportRequestContract" nillable="true" type="tns:FileImportRequestContract" />
<xs:complexType name="FileImportResponseContract">
<xs:sequence>
<xs:element minOccurs="0" name="Id" type="xs:long" />
<xs:element minOccurs="0" name="Message" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="OpFlag" nillable="true" type="xs:string" />
<xs:element xmlns:q2="http://schemas.datacontract.org/2004/07/Framework.Business.Contracts" minOccurs="0" name="OpMessages" nillable="true" type="q2:ArrayOfContractMessage" />
<xs:element minOccurs="0" name="Success" type="xs:boolean" />
</xs:sequence>
</xs:complexType>
<xs:element name="FileImportResponseContract" nillable="true" type="tns:FileImportResponseContract" />
</xs:schema>
И сгенерированный класс запросов:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "FileImportRequestContract", propOrder = {
"fileContent",
"fileHash",
"fileName",
"id",
"opFlag",
"opMessages"
})
public class FileImportRequestContract {
@XmlElementRef(name = "FileContent", namespace = "http://schemas.datacontract.org/2004/07/NDDWH.Model.Contracts", type = JAXBElement.class, required = false)
protected JAXBElement<byte[]> fileContent;
@XmlElementRef(name = "FileHash", namespace = "http://schemas.datacontract.org/2004/07/NDDWH.Model.Contracts", type = JAXBElement.class, required = false)
protected JAXBElement<String> fileHash;
@XmlElementRef(name = "FileName", namespace = "http://schemas.datacontract.org/2004/07/NDDWH.Model.Contracts", type = JAXBElement.class, required = false)
protected JAXBElement<String> fileName;
@XmlElement(name = "Id")
protected Long id;
@XmlElementRef(name = "OpFlag", namespace = "http://schemas.datacontract.org/2004/07/NDDWH.Model.Contracts", type = JAXBElement.class, required = false)
protected JAXBElement<String> opFlag;
@XmlElementRef(name = "OpMessages", namespace = "http://schemas.datacontract.org/2004/07/NDDWH.Model.Contracts", type = JAXBElement.class, required = false)
protected JAXBElement<ArrayOfContractMessage> opMessages;
Сгенерированный класс выглядит нормально для меня. Правильное пространство имен установлено, и XmlElementRefs имеют правильные имена. Проблема возникает, когда cxf пытается создать тело мыла из кода Java. Есть идеи?