Search code examples
apache-camelcxfwsdl2java

Camel CXF Wsdl2java issue


I'm trying to call a third party SOAP web service by using Camel & CXF. Here is an excerpt from the wsdl

<message name="setDeviceDetailsv4">
        <part name="parameters" element="tns:setDeviceDetailsv4"></part>
        <part name="gdspHeader" element="tns:gdspHeader"></part>
    </message>
    <message name="setDeviceDetailsv4Response">
        <part name="result" element="tns:setDeviceDetailsv4Response"></part>
    </message>
    <portType name="SetDeviceDetailsv4">
        <operation name="setDeviceDetailsv4" parameterOrder="parameters gdspHeader">
            <input message="tns:setDeviceDetailsv4"></input>
            <output message="tns:setDeviceDetailsv4Response"></output>
        </operation>
    </portType>
    <binding name="SetDeviceDetailsv4PortBinding" type="tns:SetDeviceDetailsv4">
        <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"></soap:binding>
        <operation name="setDeviceDetailsv4">
            <soap:operation soapAction=""></soap:operation>
            <input>
                <soap:body use="literal" parts="parameters"></soap:body>
                <soap:header message="tns:setDeviceDetailsv4" part="gdspHeader" use="literal"></soap:header>
            </input>
            <output>
                <soap:body use="literal"></soap:body>
            </output>
        </operation>
    </binding>
    <service name="SetDeviceDetailsv4Service">
        <port name="SetDeviceDetailsv4Port" binding="tns:SetDeviceDetailsv4PortBinding">
            <soap:address location="http://localhost:${HttpDefaultPort}/GDSPWebServices/SetDeviceDetailsv4Service"></soap:address>
        </port>
    </service>

As one can see, the soap body uses the "parameters" part which is mentioned in the wsdl above, related to tns:setDeviceDetailsv4.

The example client code looks like this:

 System.out.println("Invoking setDeviceDetailsv4...");
        SetDeviceDetailsv4_Type _setDeviceDetailsv4_parameters = null;
        GdspHeader _setDeviceDetailsv4_gdspHeader = null;
        SetDeviceDetailsv4Response _setDeviceDetailsv4__return = port.setDeviceDetailsv4(_setDeviceDetailsv4_parameters, _setDeviceDetailsv4_gdspHeader);
        System.out.println("setDeviceDetailsv4.result=" + _setDeviceDetailsv4__return);

When I make a call through my camel route that matches the client code above, I was expecting CXF / Camel to append the "gdspHeader" to the soap header but it's not, it's sending it as a parameter to the web method. A separate developer hand coded the SOAP call and here is what he had and it works perfectly !!

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.gdsp.xxxxxxx.com/">
    <soapenv:Header>
        <ws:gdspHeader>
            <gdspCredentials>
                <userId>xxxx</userId>
                <password>xxxx</password>
            </gdspCredentials>
        </ws:gdspHeader>
    </soapenv:Header>
    <soapenv:Body>
        <ws:setDeviceDetailsv4>
            <deviceId>xxxxxx</deviceId>
            <state>x</state>
        </ws:setDeviceDetailsv4>
    </soapenv:Body>
</soapenv:Envelope>

Yet when I make a call through Camel, here is what I get as the SOAP message:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Header>
        <ns2:gdspHeader xmlns:ns2="http://ws.gdsp.xxxx.com/">
            <gdspCredentials>
                <password>xxxx</password>
                <userId>xxxx</userId>
            </gdspCredentials>
        </ns2:gdspHeader>
    </soap:Header>
    <soap:Body>
        <ns1:setDeviceDetailsv4 xmlns:ns1="http://ws.gdsp.Xxxxx.com/">
            <ns2:arg0 xmlns:ns2="http://ws.gdsp.xxx.com/">
                <deviceId>xxxx</deviceId>
                <state>x</state>
            </ns2:arg0>
            <ns2:arg1 xmlns:ns2="http://ws.gdsp.xxxx.com/">
                <gdspCredentials>
                    <password>xxxx</password>
                    <userId>xxxx</userId>
                </gdspCredentials>
            </ns2:arg1>
        </ns1:setDeviceDetailsv4>
    </soap:Body>
</soap:Envelope>

and it FAILS. I've tried to make the gdspCredentials NULL and that doesn't work and if I only pass in one parameter, CXF throws a soap fault stating that the method requires two parameters.

Here is a portion of my pom.xml file

<build>
    <plugins>
      <plugin>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-codegen-plugin</artifactId>
        <version>2.7.7</version>
        <executions>
          <execution>
            <id>generate-sources</id>
            <phase>generate-sources</phase>
            <configuration>
              <wsdlOptions>
                <wsdlOption>
                  <frontEnd>jaxws21</frontEnd>
                  <faultSerialVersionUID>1</faultSerialVersionUID>
                  <wsdl>src/main/resources/wsdl/extWebServices.wsdl</wsdl>
                  <extraargs>
                    <extraarg>-client</extraarg>
                  </extraargs>
                </wsdlOption>
              </wsdlOptions>
            </configuration>
            <goals>
              <goal>wsdl2java</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

How can I get my Camel / CXF call to match what the other developer had done?


Solution

  • The wsdl didn't work out of the box for my needs. I was able to modify the wsdl to remove the "header" option and use an interceptor for handle the header portion and a processor to handle the response & request marshalling / unmarshalling.