user1397026
user1397026

Reputation: 51

Creating a CXF client from a remote WSDL which references localhost

I am using CXF to generate a client for connecting to a remote webservice. I do not have any control over the webservice or the wsdl definition.

The webservice's wsdl makes several references to localhost, for example:

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

I am trying to generate my client using the wsdl2java maven goal whilst pointing to the remote wsdl:

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

When I try to build the client, the goal fails because of the references to 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

Is there any way to make CXF understand that the localhost references are relevant to the wsdl host and automatically replace them with the appropriate hostname when generating a client?

I have managed to generate a client by copying the wsdl to a local file and manually replacing the localhost references with the appropriate hostnames. However, I need the client to be generated from the remote wsdl definition rather than a local file. Does anyone know of a way this can be achieved? I am currently using cxf version 2.6.0

Thanks in advance for any answers.

(I have replaced my actual service names with generic names such as remotehost)

Upvotes: 3

Views: 1860

Answers (1)

Cjxcz Odjcayrwl
Cjxcz Odjcayrwl

Reputation: 22847

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.

Upvotes: 1

Related Questions