Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are CXF client proxies thread safe?

I'm using CXF to generate SOAP client classes. In the CXF documentation, they write

Are JAX-WS client proxies thread safe?

Official JAX-WS answer: No. According to the JAX-WS spec, the client proxies are NOT thread safe. To write portable code, you should treat them as non-thread safe and synchronize access or use a pool of instances or similar.

CXF answer: CXF proxies are thread safe for MANY use cases. The exceptions are:

(I'm omitting their description of these use cases)

For most "simple" use cases, you can use CXF proxies on multiple threads. The above outlines the workarounds for the others.

Does anyone have any contrary experiences? Encountered multi-threading issues that aren't described in their faq? Or is their description accurate and they are basically safe to use?

like image 695
Eyal Avatar asked Oct 30 '12 09:10

Eyal


People also ask

What is CXF client?

CXF includes a Client interface which allows you to invoke operations and pass parameters for those operations. For instance: Client client = ....; Object[] result = client.

What is CXF used for?

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.

How do I run Apache CXF?

Running the HelloWorld Service This will generate the appropriate Apache CXF classes from your wsdl, compile your Apache CXF classes, deploy the server on the embedded jetty server and run your application. INFO: Setting the server's publish address to be http://localhost:9090/HelloServerPort Server ready...


2 Answers

We recently ran into similar discussion in our project. As specified in the FAQ you are referring to, except for the features that modify HTTP conduit on the fly (ex: session management and failover features), the CXF client proxy is thread safe. So if you do not use these features then it is okay to share the client proxy between threads.

like image 97
Srimathi Avatar answered Oct 12 '22 09:10

Srimathi


You're probably referring to runtime, but I don't think configuration time is meant to be threadsafe. I believe I've seen a race condition in JettyHTTPServerEngineFactory.

In a test harness we bring up multiple unrelated SOAP servers and when they share a Bus there's a potential for a race condition if multiple threads attempt to add JettyHTTPServerEngine instances at the same time. The specific race condition is in setTLSServerParametersForPort(), which you call when you want to use HTTPS for a port. That method adds elements to a HashMap with no locking.

I guess the reason others don't encounter this is that most people configure CXF via configuration files, and it's rare to have multiple ports/Jetty servers in one process.

like image 23
David Gladfelter Avatar answered Oct 12 '22 10:10

David Gladfelter