3

我正在使用 CXF 生成用于连接到远程 Web 服务的客户端。我无法控制 web 服务或 wsdl 定义。

Web 服务的 wsdl 对 localhost 进行了多次引用,例如:

<soap12:address location="http://localhost:8002/request" />
<wsa10:EndPointReference>
    <wsa10:Address>http://localhost:8002/request</wsa10:Address>
</wsa10:EndPointReference>

我正在尝试使用 wsdl2java maven 目标生成我的客户端,同时指向远程 wsdl:

...
<wsdlOptions>
<wsdlOption>
<wsdl>http://remotehost:8002/?wsdl</wsdl>
<wsdlOption>
<wsdlOptions>
...

当我尝试构建客户端时,由于对 localhost 的引用,目标失败:

org.apache.cxf.wsd11.WSDLRuntimeException: Fail to create wsdl definition from :       http://remotehost:8002/?wsdl [ERROR] caused by : WSDLException (at  
/wsdldefinitions/wsdl:import) faultCode=PARSER_ERROR: Problem parsing  
'http://localhost:8002/?wsdl=wsdl0'.: java.net.ConnectionException: Connection refused: connect

有什么方法可以让 CXF 了解 localhost 引用与 wsdl 主机相关,并在生成客户端时自动将它们替换为适当的主机名?

我设法通过将 wsdl 复制到本地文件并用适当的主机名手动替换本地主机引用来生成客户端。但是,我需要从远程 wsdl 定义而不是本地文件生成客户端。有谁知道可以实现的方法?我目前正在使用 cxf 版本 2.6.0

提前感谢您的任何答案。

(我已将我的实际服务名称替换为通用名称,例如远程主机)

4

1 回答 1

1

You want to make CXF understand that the localhost references are relevant to the wsdl host but this is not something that should be understood by any tool, since the WSDL can import other WSDL from any location, and this could be in some cases the correct reference. Simply it is not in your case, it is configuration error from the site you want to connect to.

I understand you're giving the URL to WSDL as an argument to the tool making proxy dynamically, so you can't just download it and change references.

The workaround I suggest is to write simple proxy, a servlet that would connect to remote URL (given as argument) and would return WSDL, changing localhost references to the correct ones. And you would give the URL of this servlet as argument to your proxy factory. It isn't nice, but the only nice solution is that the provider fixes its own WSDL.

于 2012-05-23T10:43:30.210 回答