Home » Java » java – Apache CXF java2wsdl: Custom symbol names-Exceptionshub

java – Apache CXF java2wsdl: Custom symbol names-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment

Questions:

Our java application needs to communicate with a SOAP service. We use Apache CXF to implement a jaxws client. The classes are generated by wsdl2java from the WSDL file we received from the service provider.

Unfortunately the symbol names provided by the service are all uppercase and underscore delimited (e.g. PRODUCT_ATTACHMENT). This is very confusing as it differs from the typical “CamelCase” java coding convention (e.g. ProductAttachment).

I know you could define custom mappings for each class. But as there is a huge number of classes and members, I’d like to automate the symbol name conversion.

So I wonder if there is a way to provide some kind of rules or piece of java code (as hook) for wsdl2java which tells it to convert a symbol name ABC_DEF to AbcDef in the generated java classes.

If not, maybe there are alternative solutions instead of Apache CXF which allow this.

How to&Answers:

You could try to use camelcase-always plugin. There were examples on stackoverflow of its integration with maven-jaxb2-plugin.

Example configuration for cxf-codegen-plugin:

    <dependencies>
        <dependency>
            <groupId>org.andromda.thirdparty.jaxb2_commons</groupId>
            <artifactId>camelcase-always</artifactId>
            <version>1.0</version>
        </dependency>
    </dependencies>


    <plugins>
            <plugin>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-codegen-plugin</artifactId>
                <version>3.3.5</version>
                <executions>
                    <execution>
                        <id>generate-sources</id>
                        <phase>generate-sources</phase>
                        <configuration>
                            <sourceRoot>${project.build.directory}/generated-sources/cxf</sourceRoot>
                            <wsdlOptions>
                                <wsdlOption>
                                    <wsdl>${basedir}/src/main/resources/wsdl/customer-service.wsdl</wsdl>
                                    <wsdlLocation>classpath:wsdl/customer-service.wsdl</wsdlLocation>
                                    <extraargs>
                                        <extraarg>-verbose</extraarg>
                                        <extraarg>-xjc-camelcase-always</extraarg>
                                    </extraargs>
                                </wsdlOption>
                                <bindingFiles>
                                    <bindingFile>${basedir}/src/main/resources/wsdl/bindings/customer-service-bindings.xjb</bindingFile>
                                </bindingFiles>
                            </wsdlOptions>
                        </configuration>
                        <goals>
                            <goal>wsdl2java</goal>
                        </goals>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>org.andromda.thirdparty.jaxb2_commons</groupId>
                        <artifactId>camelcase-always</artifactId>
                        <version>1.0</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>