Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a CXF webservice client with dynamic endpoint?

We have a central WSDL file that describes a web service. We use CXF to generate client code, but this code seems to be bound to 1 endpoint. How can i create a CXF client that uses the WSDL, but where I can specify the endpoint? Is there are way in changing the endpoint to a URL that implements the same WSD:?

like image 490
Marco Avatar asked Sep 16 '11 16:09

Marco


People also ask

How do I create a CXF client?

By setting up the pom. xml file, Maven can automatically generate the Java CXF client. Alternatively, you can directly use the WebClient APIs to develop a Java CXF client.

What is a CXF client?

CXF includes a Client interface which allows you to invoke operations and pass parameters for those operations.

How do I generate a class from WSDL using Apache CXF?

You will have to make sure that you create an appropriate directory structure for your project and add the earlier shown hello. wsdl file to the specified folder. The wsdl2java plugin will compile this wsdl and create Apache CXF classes in a pre-defined folder.

How do I change the endpoint of a dynamic address in Java?

You can use BindingProvider. ENDPOINT_ADDRESS_PROPERTY to set the endpoint address in your client application code. you can also get the currently used endpoint url at runtime.


1 Answers

If the other service implements the same WSDL, when you create the MyClientService object, you can pass the URL to the new service's WSDL right to the constructor and it will us it. Most services would expose its wsdl on ?wsdl so using that may "just work".

Alternatively, you can override the endpoint URL via:

((BindingProvider)proxy).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_URL, "http://my.service.url.com/...")

where proxy is the MyClientService object.

like image 109
Daniel Kulp Avatar answered Sep 17 '22 10:09

Daniel Kulp