我尝试从this WSDL生成存根(不是我的网络服务,因此我无法更改名称!)
问题是我无法成功生成存根,因为在wsdl中是服务名称,区别仅在于具有“_”的服务开始而另一个不是。 示例:_registerTest和registerTest
有人知道如何解决这个问题吗?是否可以使用Jaxb生成存根?
我试着用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>
使用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
答案 0 :(得分:3)
我认为删除下划线是为了生成尊重Java code conventions的名称(foo_bar
之类的名称在源代码中生成为fooBar
。
如果您想保留名称,可以应用一些customizations。
假设我有c:\temp\src
中正在处理的文件,并且我在c:\temp\dest
中生成了源代码,我可以(在一行上):
wsimport
-keep
-d c:\temp\dest
-b c:\temp\src\fix.xml
c:\temp\src\onyxexamservices.wsdl
其中fix.xml
是我的自定义文件:
<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>