wsimport结果具有不同的运行时端点

时间:2015-05-22 09:05:07

标签: java maven wsdl endpoint wsimport

这是一个奇怪的。

我正在使用wsimport插件为这样的maven生成一个soap服务的客户端代码......

        <plugin>
          <groupId>org.jvnet.jax-ws-commons</groupId>
          <artifactId>jaxws-maven-plugin</artifactId>
          <version>2.1</version>
          <executions>
            <execution>
              <goals>
                <goal>wsimport</goal>
              </goals>
              <configuration>
                <wsdlUrls>
                  <wsdlUrl>${testWsdlLocationUrl}</wsdlUrl>
                </wsdlUrls>
                <destDir>${basedir}/target/jaxws</destDir>
              </configuration>
            </execution>
          </executions>
        </plugin>

...我已经参数化了外部wsdlUrl。我可以看到生成的客户端中定义了wsdl url(为匿名而捏造)的位置......

static {
    URL url = null;

    try {
        URL e = SpecialService.class.getResource(".");
        url = new URL(e, "http://theUrlThatIDefinedAbove:withTheCorrectPortNumber/blahblah?wsdl");
    } catch (MalformedURLException var2) {
        logger.warning("Failed to create URL for the wsdl Location: \'http://theUrlThatIDefinedAbove:withTheCorrectPortNumber/blahblah?wsdl\', retrying as a local file");
        logger.warning(var2.getMessage());
    }

    SPECIALSERVICE_WSDL_LOCATION = url;
}

...所以到目前为止看起来都很好。构建创建一个jar,其中只包含从wsimport生成的已编译代码。

但是,当我在代码中引用此生成的客户端来调用服务时,端点是不同的!这是(我的要点)我做的......

this.serviceEndpoint = new SpecialService().getSpecialServiceHttpSoap11Endpoint();

this.serviceEndpoint.callTheSpecialMethodOnTheService(withSomeDataOrOther)

够简单呃?但是,我收到超时异常。

当我像这样查看服务端点时:

System.out.println("Service Endpoint : " + this.serviceEndpoint.toString());

我得到(类似的东西)...

Service Endpoint : JAX-WS RI 2.2.4-b01: Stub for http://theCorrectUrlHere:8080/withTheCorrectPath/

...... 8080来自哪里?它不在我指定的wsdl网址上。

奇怪的是,如果我像这样手动更改服务端点......     ((BindingProvider)this.serviceEndpoint).getRequestContext()。put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,“theCorrectUrlAndPort”)

......一切正常,我可以愉快地访问远程服务。

我错过了一些明显的东西吗?我假设给wsimport wsdl位置会将正确的端点烘焙到客户端代码中,并且它看起来确实如此,主机和路径数据正确但端口错误。

我对wsimport插件做过愚蠢的事吗?我是否需要在wsimport中提供端口?

如果您能提供任何建议,我将不胜感激。

修改

按照Leo的建议,这是新的插件配置......

<testWsdlLocationUrl>http://editedOutHost:portThatIsNot8080/the/rest/of/the/path?wsdl</testWsdlLocationUrl>

...

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>jaxws-maven-plugin</artifactId>
            <executions>
                <execution>
                    <id>generate-stubs</id>
                    <phase>process-classes</phase>
                    <goals>
                        <goal>wsimport</goal>
                    </goals>
                    <configuration>
                        <wsdlUrls>
                            <wsdlUrl>${testWsdlLocationUrl}</wsdlUrl>
                        </wsdlUrls>
                        <wsdlLocation>${testWsdlLocationUrl}</wsdlLocation>
                    </configuration>
                </execution>
            </executions>
        </plugin>

请注意,它指的是远程wsdl位置,而不是注释示例中的本地位置。

插件的更改以与原始问题相同的方式生成类,在反编译时都指向正确的主机端口和路径,并且两者仍然表现出将端口默认返回到8080的相同问题。

*更新*

当我从命令行手动运行wsimport并生成结果类时,会出现同样的问题,所以我不认为使用maven是问题的根源。

2 个答案:

答案 0 :(得分:1)

是的,我回答了我自己的问题。我这样做是为了将来遇到这个问题的任何人的利益。

我刚从主持该服务的人那里听到回复,我一直试图与这个神秘变化的港口建立联系。

他们的服务器&#34; ...正在我们的内部网络上运行在端口8080和8443上,并且可以使用带端口转换的NAT从外部访问。因此,WSDL文件中显示的端口是服务器已知的(未)。&#34;

所以我们拥有它。可用于获取wsdls的端口可能无法用于服务调用。这不奇怪吗?

答案 1 :(得分:0)

尝试使用codehaus插件,将有助于对与wsdl location相关的问题进行排序

<plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>jaxws-maven-plugin</artifactId>
        <executions>
            <execution>
                <id>generate-wsdl</id>
                <phase>process-classes</phase>
                <goals>
                    <goal>wsgen</goal>
                </goals>
                <configuration>
                    <sei><!-- fully qualified class name goes here --></sei>
                    <genWsdl>true</genWsdl>
                </configuration>
            </execution>
            <execution>
                <id>generate-stubs</id>
                <phase>process-classes</phase>
                <goals>
                    <goal>wsimport</goal>
                </goals>
                <configuration>
                    <wsdlDirectory>target/jaxws/wsgen/wsdl</wsdlDirectory>
                    <wsdlFiles>                   
                        <wsdlFile><!-- class name goes here -->Service.wsdl</wsdlFile>
                    </wsdlFiles>
                    <!-- *** you need the next line to set the wsdlLocation in the generated stubs *** -->
                    <wsdlLocation>http://localhost:8080/test</wsdlLocation> 
                </configuration>
            </execution>
        </executions>
    </plugin>
相关问题