【问题标题】:(WS)Stubs generation - underscore not allowed?(WS)存根生成 - 不允许下划线?
【发布时间】:2013-06-03 07:58:37
【问题描述】:

我尝试从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

【问题讨论】:

    标签: web-services jaxb wsdl stub


    【解决方案1】:

    我认为删除下划线是为了生成尊重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>
    

    【讨论】:

    • 下一个问题,我无法使用生成的存根调用 Web 服务。在 ObjectFactory.java 中缺少类似“createRegisterTest”的内容? (我正在使用 Spring-WS)。
    • @user1731299:我不熟悉 Spring-WS,但 ObjectFactory 提供了用于实例化表示 XML 标记的 Java 接口的方法。 registerTest 是一种方法,因此您不会在其中找到 createRegisterTest 方法。也许就您的新问题提出一个具体问题,以便其他人在 Spring-WS 上比我可以为您提供更多帮助。
    猜你喜欢
    • 2021-06-15
    • 1970-01-01
    • 2020-06-10
    • 1970-01-01
    • 1970-01-01
    • 2016-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多