Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache CXF Client for Dynamic Endpoints

I'm now using Apache CXF as a web services client for a .NET service to get around NTLM authentication. It works great, but I'm wondering why I can't seem to be able to set the web service target endpoint. CXF seems to want the WSDL at runtime for some strange reason - not sure. It takes the physical endpoint from the WSDL, which works fine in test environments I guess, but at deployment time it's sure to change.

Here's some code to demonstrate:

        MyWebServices service = new MyWebServices ();         MyWebServicesSoap port = service.getMyWebServicesSoap12();          // Turn off chunking so that NTLM can occur         Client client = ClientProxy.getClient(port);         HTTPConduit http = (HTTPConduit) client.getConduit();         HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();         httpClientPolicy.setConnectionTimeout(36000);         httpClientPolicy.setAllowChunking(false);         http.setClient(httpClientPolicy);          port.doSomethingUseful(); 

Again, there is no place that I can see in the CXF client API that allows me to set the service endpoint. Not that I can see anyway. In this case, the target is http://localhost/integration/webservices/mywebservices.asmx, but I could be anywhere. Surely this pedestrian problem is solved somehow?

like image 505
andyczerwonka Avatar asked Jun 10 '10 22:06

andyczerwonka


People also ask

What is CXF endpoint?

In Apache Camel, the Camel CXF component is the key to integrating routes with Web services. You can use the Camel CXF component to create a CXF endpoint, which can be used in either of the following ways: Consumer — (at the start of a route) represents a Web service instance, which integrates with the route.

What is Apache CXF used for?

Apache CXF™ is an open source services framework. CXF helps you build and develop services using frontend programming APIs, like JAX-WS and JAX-RS. These services can speak a variety of protocols such as SOAP, XML/HTTP, RESTful HTTP, or CORBA and work over a variety of transports such as HTTP, JMS or JBI.

Is CXF Webclient thread safe?

Proxies and web clients (clients) are not thread safe by default.


1 Answers

Try the following:

MyWebServicesSoap port = service.getMyWebServicesSoap12(); BindingProvider provider = (BindingProvider) port; provider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpoint);  

Alternatively, MyWebServices might have other getXXX methods that take a URL for the WSDL location

like image 93
Kevin Avatar answered Oct 08 '22 00:10

Kevin