Sagnik Chatterjee
Sagnik Chatterjee

Reputation: 127

Mismatch in java classes generated from online WSDL files

I have an application where I am trying out few plugins to generate Java classes from an online WSDL file. Previously, the below plugin was being used:

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>jaxws-maven-plugin-upd</artifactId>
  <version>2.5</version>
  <dependencies>
    <dependency>
      <groupId>org.jvnet.jaxb2_commons</groupId>
      <artifactId>jaxb2-basics</artifactId>
      <version>0.11.1</version>
    </dependency>
    <dependency>
     <groupId>org.jvnet.jaxb2_commons</groupId>
     <artifactId>jaxb2-basics-annotate</artifactId>
     <version>1.1.0</version>
    </dependency>
  </dependencies>
  <executions>
    <execution>
        <id>wsimport</id>
      <goals>
        <goal>wsimport</goal>
      </goals>
      <configuration>
        <wsdlUrls>
            <wsdlUrl>http://url-for-file.wsdl</wsdlUrl>
        </wsdlUrls>
        <bindingDirectory>src/main/resources</bindingDirectory>
        <bindingFiles>
            <bindingFile>jaxb.xjb</bindingFile>
        </bindingFiles>
        <sourceDestDir>target/generated-sources/wsimport</sourceDestDir>
      </configuration>
    </execution>
  </executions>
</plugin>

Now the above plugin seems to be not compatible with Java 17, hence I am trying the below plugin, which is also working fine:

<plugin>
  <groupId>org.apache.cxf</groupId>
  <artifactId>cxf-codegen-plugin</artifactId>
  <version>4.0.3</version>
  <dependencies>
    <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-spring-boot-starter-jaxws</artifactId>
      <version>4.0.3</version>
      <scope>compile</scope>
    </dependency>
  </dependencies>
  <executions>
    <execution>
      <id>generate-sources</id>
      <phase>generate-sources</phase>
      <goals>
        <goal>wsdl2java</goal>
      </goals>
      <configuration>
        <sourceRoot>target/generated-sources/wsimport</sourceRoot>
        <wsdlOptions>
          <wsdlOption>
            <wsdl>http://url-for-file.wsdl</wsdl>
            <bindingFiles>
              <bindingFile>src/main/resources/jaxb.xjb</bindingFile>
            </bindingFiles>
          </wsdlOption>
        </wsdlOptions>
      </configuration>
    </execution>
  </executions>
</plugin>

Here is small portion of the WSDL file that I am using:

<?xml version="1.0" encoding="UTF-8"?><wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" name="WSDL-name" targetNamespace=""  xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
<wsdl:binding name="AccountsSOAPBinding" type="wstns:AccountsPortType">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="Service">
        <soap:operation soapAction="Service" style="document"/>
        <wsdl:input name="ServiceInput">
            <soap:body use="literal"/>
            <soap:header message="wstns:ContextMessage" part="Context" use="literal"/>
        </wsdl:input>
        <wsdl:output name="ServiceOutput">
            <soap:body use="literal"/>
        </wsdl:output>
        <wsdl:fault name="TechnicalFault">
            <soap:fault use="literal" name="TechnicalFault"/>
        </wsdl:fault>
        <wsdl:fault name="FunctionalFault">
            <soap:fault use="literal" name="FunctionalFault"/>
        </wsdl:fault>
    </wsdl:operation>
</wsdl:binding>

But the structure of classes is bit different, meaning, the class generated from former plugin has methods with 2 parameters (ServiceInput and Context which is header parameter), but the class generated from second plugin has exactly same method, but with 1 parameter (ServiceInput). Below are the 2 methods from the generated classes

@WebMethod(operationName = "Service", action = "Service")
@WebResult(name = "ResponseDataService", targetNamespace = "", partName = "ServiceResponseMessagePart")
public ResponseDataServiceType checkService(
    @WebParam(name = "RequestDataService", targetNamespace = "", partName = "ServiceRequestMessagePart")
    RequestDataServiceType serviceRequestMessagePart,
    @WebParam(name = "Context", targetNamespace = "", header = true, partName = "Context")
    Context context)
    throws FunctionalFaultMessage, TechnicalFaultMessage

@WebMethod(operationName = "Service", action = "Service")
@WebResult(name = "ResponseDataService", targetNamespace = "", partName = "ServiceResponseMessagePart")
public ResponseDataServiceType checkService(
    @WebParam(name = "RequestDataService", targetNamespace = "", partName = "ServiceRequestMessagePart")
    RequestDataServiceType serviceRequestMessagePart)
    throws FunctionalFaultMessage, TechnicalFaultMessage

Can someone let me know if there any configuration changes to be done in the new plugin that can help in resolution, or any other plugin that I can use for the same. Thanks in advance.

Upvotes: 0

Views: 217

Answers (1)

Sagnik Chatterjee
Sagnik Chatterjee

Reputation: 127

Solution found out for the issue, from below page: https://cxf.apache.org/docs/wsdl-to-java.html

<configuration>
  <sourceRoot>./target/generated-sources/wsimport</sourceRoot>
  <defaultOptions>
    <extraargs>
      <extraarg>-exsh</extraarg>
      <extraarg>true</extraarg>
    </extraargs>
  </defaultOptions>
  <wsdlOptions>
    <wsdlOption>
      <wsdl>${rosy.wsdl.location}/ssr/FWS/SVC/Accounts/1.1/FWS-SVC-Accounts-1.1-standard-http_binding.wsdl</wsdl>
    </wsdlOption>
  </wsdlOptions>
</configuration>

Upvotes: 0

Related Questions