Hi
Okay thanks Sergey, I may do that then.
Although this will make testing quite painful (mocking out the webclient copy
then not really possible)
I see...
Commons HttpClient 3.x has a nice way of injecting a MultithreadedHttpConnectionManager into the client to make it threadsafe,
and allowing easy testing too
To some extent, the CXF ConduitInitiator (used internally) will act as a connection manager...What is really thread-unsafe at the
moment is that a WebClient persists the latest response details and the currentURI until the next invocation so the problems may
arise in deserializing the per request specific response input streams. I'll be looking into this issue later on...
cheers, Sergey
Cheers
Paul
-----Original Message-----
From: Sergey Beryozkin [mailto:[email protected]]
Sent: 09 February 2010 11:16
To: [email protected]
Subject: Re: is webclient thread safe ?
Hi
Unfortuntately not, not yet.
However, you can do the following on every request, after it has been injected :
public class SomeService {
private WebClient injectedWc = ...
@POST
public void doIt() {
// copy-constructor-like creation
WebClient currentWc = WebClient.fromClient(injectedWc, true);
// or just WebClient.fromClient(injectedWc);
currentWc.post(...)
}
}
The currentWc will get all the configuration the injectWc has, including the headers which might've been set on it on the init
time
(the 2nd 'true' parameter). WebClient.fromClient() can be used to 'convert'
proxies into WebClients too. I've been thinking about
the tread-safety of a single client earlier on and at a time I chose to have
methods like WebClient.getResponse() or
WebClient.back() working well. I reckon WebClient.fromClient() can be quite a cheap alternative (albeit with some extra effort
from
a user) to making sure a proxy/client is thread-safe internally, however, I'll be looking into this issue with more attention once
I
get into working on enhancing the client api (on the map)...
Hope it helps, Sergey
Hi
How thread safe is WebClient. Can it be injected (spring wired) into a
bean, and reused on a per request basis to call a downstream web service
?
Thanks for any guidance
Paul
This e-mail (and any attachments) is confidential and may contain personal
views which are not the views of the BBC unless
specifically stated. If you have received it in error, please delete it from
your system. Do not use, copy or disclose the
information in any way nor act in reliance on it and notify the sender
immediately.
Please note that the BBC monitors e-mails sent or received. Further
communication will signify your consent to this
This e-mail has been sent by one of the following wholly-owned subsidiaries of
the BBC:
BBC Worldwide Limited, Registration Number: 1420028 England, Registered
Address: BBC Media Centre, 201 Wood Lane, London, W12 7TQ
BBC World News Limited, Registration Number: 04514407 England, Registered Address: BBC Media Centre, 201 Wood Lane, London, W12
7TQ
BBC World Distribution Limited, Registration Number: 04514408, Registered Address: BBC Media Centre, 201 Wood Lane, London, W12
7TQ