Search code examples
javaserializationjaxbwsdlcxf

How to tell cxf to keep the wrapper types in methods?


In my WSDL I have an operation

<wsdl:operation name="theMethod">
    <wsdl:input message="input1" name="input1"></wsdl:input>
    <wsdl:output message="tns:classNumber1" name="classNumber1"></wsdl:output>
</wsdl:operation>

in my xsd, classNumber1 is a complex type and it is a wrapper for another type: classNumber2

<xs:complexType name="classNumber1">
  <xs:sequence>
   <xs:element minOccurs="0" name="arg0" type="tns:classNumber2"/>
  </xs:sequence>
</xs:complexType>

when I generate classes with cxf (I use cxf maven plugin), I expected that theMethod to return a ClassNumber1 but it was a ClassNumber2.

@WebMethod
@ResponseWrapper(localName="classNumber1" , className="com.model.ClassNumber")
public ClassNumber2 theMethod (Input1 input1){
    ...
}

Is there a way to tell cxf to generate the method with the wrapper CLassNumber1. Thanks.


Solution

  • I find the solution in this doc, question "How can I switch my generated web service method calls from wrapper style to non wrapper-style (or vice-versa)?"

    The solution to keep wrappers with cxf generation is to add a binding file in the pom.xml:

    <defaultOptions>
    <bindingFiles>
        <bindingFile>${basedir}/src/main/resources/bindings.xjb</bindingFile>
    </bindingFiles>
    <noAddressBinding>true</noAddressBinding>
    </defaultOptions>
    

    In the binding file you set enableWrapperStyle to false:

    <jaxws:bindings
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
        xmlns="http://java.sun.com/xml/ns/jaxws"
        xmlns:jaxws="http://java.sun.com/xml/ns/jaxws">
        <enableWrapperStyle>false</enableWrapperStyle>
    </jaxws:bindings>