Search code examples
web-servicesjaxbwsdlstub

(WS)Stubs generation - underscore not allowed?


I tried out to generate Stubs from this WSDL (not my webservice so I cannot change names!)

The problem is that I cant generate stubs successfully because in the wsdl are service names which differ only in that a service with "_" begins and the other not. Example: _registerTest and registerTest

Someone know how to fix that? Is it possible to generate the Stubs with Jaxb?

I tried with maven:

<plugin>
            <groupId>org.jvnet.jaxb2.maven2</groupId>
            <artifactId>maven-jaxb2-plugin</artifactId>
            <version>0.7.1</version>
            <executions>
                <execution>
                    <id>ws-source-gen-phase1</id>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <configuration>
                        <removeOldOutput>true</removeOldOutput>
                        <extension>true</extension>
                        <schemaDirectory>src/main/resources/</schemaDirectory>
                        <args>
                            <arg>-wsdl</arg>
                            <schemaFiles>src/main/resources/onyxexamservices.wsdl</schemaFiles>
                            <!-- <arg>-XautoNameResolution</arg>  -->
                        </args>
                        <generatePackage>com.onyx.player.ws</generatePackage>
                        <generateDirectory>${project.build.directory}/generated-sources/xjc1</generateDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>

And with wsimport:

wsimport onyxexamservices.wsdl

parsing WSDL...

Generating code...

Compiling code...

/Users/blub/Downloads/./de/bps/plugin/webservice/server/OnyxExamService.java:89: error: 
method registerTest(long,String,byte[],Mapwrapper) is already defined in interface 
OnyxExamService
public long registerTest(
            ^
/Users/blub/Downloads/./de/bps/plugin/webservice/server/OnyxExamService.java:114: error:  
method registerStudent(long,long,byte[],Mapwrapper) is already defined in interface    
OnyxExamService
public long registerStudent(
            ^
/Users/blub/Downloads/./de/bps/plugin/webservice/server/OnyxExamService.java:165: error:  
method testControl(long,StudentIdsWrapper,int,Mapwrapper) is already defined in interface 
OnyxExamService
public long testControl(
            ^
/Users/blub/Downloads/./de/bps/plugin/webservice/server/OnyxExamService.java:210: error: 
method deregisterTest(long,String,Mapwrapper) is already defined in interface 
OnyxExamService
public long deregisterTest(
            ^
4 errors
compilation failed, errors should have been reported

Solution

  • I think the underscores are removed in order to generate names that respect the Java code conventions (names like foo_bar get generated as fooBar in source).

    If you want to preserve the name, you can apply some customizations.

    Assuming I have the files I'm working on in c:\temp\src and I'm generating sources in c:\temp\dest, I can do (on one line):

    wsimport 
             -keep 
             -d c:\temp\dest 
             -b c:\temp\src\fix.xml 
    c:\temp\src\onyxexamservices.wsdl
    

    where fix.xml is my customization file:

    <jaxws:bindings wsdlLocation="C:\temp\src\onyxexamservices.wsdl"
                    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
                    xmlns:jaxws="http://java.sun.com/xml/ns/jaxws">
        <jaxws:bindings node="wsdl:definitions/wsdl:portType[@name='OnyxExamService']/wsdl:operation[@name='_registerStudent']">
            <jaxws:method name="_registerStudent" />
        </jaxws:bindings>
        <jaxws:bindings node="wsdl:definitions/wsdl:portType[@name='OnyxExamService']/wsdl:operation[@name='_registerTest']">
            <jaxws:method name="_registerTest" />
        </jaxws:bindings>
        <jaxws:bindings node="wsdl:definitions/wsdl:portType[@name='OnyxExamService']/wsdl:operation[@name='_testControl']">
            <jaxws:method name="_testControl" />
        </jaxws:bindings>
        <jaxws:bindings node="wsdl:definitions/wsdl:portType[@name='OnyxExamService']/wsdl:operation[@name='_deregisterTest']">
            <jaxws:method name="_deregisterTest" />
        </jaxws:bindings>
    </jaxws:bindings>