Duplicate attributes generated in WSDL using @XmlMimeType() on CXF, Why?

StackOverflow https://stackoverflow.com/questions/12539330

  •  03-07-2021
  •  | 
  •  

سؤال

I've developed a CXF web services with MTOM enabled. I've added an annotation to my DTO to tell JAXB the field candidate for MTOM optimization:

@XmlType
public class FileDTO {

    private String Name;
    private String FileType;

    @XmlMimeType("application/octet-stream")
    private DataHandler Dfile;
    ...

when deploying the webservice, the DTO definition in the WSDL looks like:

<xs:complexType name="fileDTO"> 
  <xs:sequence> 
    <xs:element name="Dfile" type="xs:base64Binary" minOccurs="0" xmime:expectedContentTypes="application/octet-stream"/> 
    <xs:element name="dfile" type="xs:base64Binary" minOccurs="0"/> 
    <xs:element name="fileType" type="xs:string" minOccurs="0"/> 
    <xs:element name="name" type="xs:string" minOccurs="0"/> 
  </xs:sequence> 
</xs:complexType>

somehow the private member DFile seems to be DUPLICATED !!

why does it happen?

when I try to generate a java client with

wsdl2java -client d:\service.wsdl

I get the following error:

WSDLToJava Error: d:\service.wsdl [26,1]: Two declarations cause a collision in the ObjectFactory class.

Thank you !!

هل كانت مفيدة؟

المحلول

By default JAXB treats all public properties as being mapped. Since you be annotated a field and its name doesn't match the property you get a second mapping.

Solution

  1. Move the annotation from the field to the property (getter).
  2. Specify @XmlAceesorType(XmlAccessType.FIELD) on the class so that JAXB bases the mappings on the fields.
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top