Cxf-codegen-plugin creating portmethods with raw types instead of wrapper request and response objects

I am working on a cxf webservice client and I pull down the wsdl directly in the codegen plugin. Ignore all the urls and namespaces, I changed those for this post. The plugin is configured as such:

    <plugin>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-codegen-plugin</artifactId>
        <version>3.5.1</version>
        <executions>
            <execution>
                <id>generate-sources</id>
                <phase>generate-sources</phase>
                <configuration>
                    <sourceRoot>${project.build.directory}/generated-sources/cxf</sourceRoot>
                    <wsdlOptions>
                        <wsdlOption>
                            <wsdl>https://mywsdlurl/web-services/MyWebservice?wsdl</wsdl>
                            <extraargs>
                                <extraarg>-client</extraarg>
                            </extraargs>
                        </wsdlOption>
                    </wsdlOptions>
                </configuration>
                <goals>
                    <goal>wsdl2java</goal>
                </goals>
            </execution>
        </executions>
    </plugin>

The section of wsdl, which I am unable to edit, being referred to:

<operation name="getInstanceAsOfDates">
<input wsam:Action="http://webserviceurl.com/MyServiceType/getInstanceAsOfDatesRequest" message="tns:getInstanceAsOfDates"/>
<output wsam:Action="http://webserviceurl.com/MyServiceType/getInstanceAsOfDatesResponse" message="tns:getInstanceAsOfDatesResponse"/>
</operation>

The port method generated, and where the problem is:

    @WebService(targetNamespace = "http://webserviceurl.com", name = "MyServiceType")
    @XmlSeeAlso({ObjectFactory.class})
    public interface MyServiceType {
...
    @WebMethod
    @Action(input = "http://webserviceurl/getInstanceAsOfDatesRequest", output = "http://webserviceurl/getInstanceAsOfDatesResponse")
    @RequestWrapper(localName = "getInstanceAsOfDates", targetNamespace = "http://webserviceurl.com", className = "com.webservice.GetInstanceAsOfDates")
    @ResponseWrapper(localName = "getInstanceAsOfDatesResponse", targetNamespace = "http://webserviceurl.com", className = "com.webservice.GetInstanceAsOfDatesResponse")
    @WebResult(name = "instanceXmlAsIOMWrapperBean", targetNamespace = "")
    public java.lang.String getInstanceAsOfDates(
    
        @WebParam(name = "w3cVersionDate", targetNamespace = "http://webserviceurl.com")
        java.lang.String w3CVersionDate,
        @WebParam(name = "w3cEndorsementDate", targetNamespace = "http://webserviceurl.com")
        java.lang.String w3CEndorsementDate,
        @WebParam(name = "fulfilledCode", targetNamespace = "http://webserviceurl.com")
        java.lang.String fulfilledCode,
        @WebParam(name = "path", targetNamespace = "http://webserviceurl.com")
        java.util.List<java.lang.String> path,
        @WebParam(name = "concepts", targetNamespace = "http://webserviceurl.com")
        java.util.List<java.lang.String> concepts,
        @WebParam(name = "ids", targetNamespace = "http://webserviceurl.com")
        java.util.List<java.lang.String> ids
    );

The plugin is correctly generating the request and response objects but how can I get the parameter for the getInstanceAsOfDates(…) to be the @RequestWrapper class and the response to be the @ResponseWrapper class like so: GetInstanceAsOfDatesResponse getInstanceAsOfDates(GetInstanceAsOfDates request)

You’re seeing the getInstanceAsOfDates(...) method generated with individual parameters instead of a method signature like:

GetInstanceAsOfDatesResponse getInstanceAsOfDates(GetInstanceAsOfDates request);

This happens because by default, CXF WSDL to Java code generation (wsdl2java) uses the “bare” parameter style, unless it detects that the WSDL operation uses a document/literal wrapped style, which is a specific WSDL pattern.


Your Goal:

Use the wrapper classes (GetInstanceAsOfDates and GetInstanceAsOfDatesResponse) as the sole input and output parameters.


The Problem:

Your WSDL likely uses document/literal bare or RPC style, or it’s structured in a way that CXF doesn’t detect it as document/literal wrapped. As a result, it expands the input message parts into individual method parameters.


Solution: Force wrapped parameter style using -wrap option

Update your cxf-codegen-plugin to add the -wrap extraarg, which forces the “wrapped” style for method signatures.

Updated plugin configuration:

<plugin>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-codegen-plugin</artifactId>
    <version>3.5.1</version>
    <executions>
        <execution>
            <id>generate-sources</id>
            <phase>generate-sources</phase>
            <configuration>
                <sourceRoot>${project.build.directory}/generated-sources/cxf</sourceRoot>
                <wsdlOptions>
                    <wsdlOption>
                        <wsdl>https://mywsdlurl/web-services/MyWebservice?wsdl</wsdl>
                        <extraargs>
                            <extraarg>-client</extraarg>
                            <extraarg>-wrap</extraarg> <!-- 👈 Add this -->
                        </extraargs>
                    </wsdlOption>
                </wsdlOptions>
            </configuration>
            <goals>
                <goal>wsdl2java</goal>
            </goals>
        </execution>
    </executions>
</plugin>

Expected Outcome:

With the -wrap option, the generated method should change to:

@WebMethod
public GetInstanceAsOfDatesResponse getInstanceAsOfDates(GetInstanceAsOfDates request);

This matches what you’re aiming for.


Additional Notes:

  • If -wrap doesn’t take effect, double-check that your WSDL input and output messages each refer to a single part of an element type, which is the key condition for document/literal wrapped style.
  • Use -verbose during codegen to verify how CXF interprets the WSDL.

Let me know if you want help verifying if your WSDL structure supports wrapped style, or if you’d like to override the codegen behavior more directly.