Basically, if you set all the conduit properties ONCE up front and also don't 
use http sessions and all use either http or https, but not both, then you can 
do this.   Do:

((BindingProvider)proxy).getRequestContext().put("thread.local.request.context",
 
"true");

as part of the setup.   That will make the RequestContext thread local.  Then, 
each thread can do:


((BindingProvider)proxy).getRequestContext().put(
    BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
    "http://my.url.to.somplace";);

and that will be fine.

If you need to setup unique valued per request other than just the URL, then I 
suggest using a pool of client proxies.   Create a few and pool them.

Dan




On Fri February 6 2009 1:17:55 pm Marc Giger wrote:
> Hi,
>
> Is the following code (copied from the user-docs) thread safe?
>
> import org.apache.cxf.endpoint.Client;
>   import org.apache.cxf.frontend.ClientProxy;
>   import org.apache.cxf.transport.http.HTTPConduit;
>   import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
>   ...
>
>   URL wsdl = getClass().getResource("wsdl/greeting.wsdl");
>   SOAPService service = new SOAPService(wsdl, serviceName);
>   Greeter greeter = service.getPort(portName, Greeter.class);
>
>   // Okay, are you sick of configuration files ?
>   // This will show you how to configure the http conduit dynamically
>   Client client = ClientProxy.getClient(greeter);
>   HTTPConduit http = (HTTPConduit) client.getConduit();
>
>   HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
>
>   httpClientPolicy.setConnectionTimeout(36000);
>   httpClientPolicy.setAllowChunking(false);
>   httpClientPolicy.setReceiveTimeout(32000);
>
>   http.setClient(httpClientPolicy);
>
>   ...
>   greeter.sayHi("Hello");
>
>
> Not that I have found any issue with it, but I want to
> be sure that it's intended to be.
>
> The requirement is to invoke multiple Endpoints in parallel where
> every EP has its own configuration (SSL-Client-Authentication,
> timeouts, url, expect-100-continue, etc). The whole configuration
> must be made at runtime, because the EP aren't known at startup time.
>
> Thank you!
>
> Marc

-- 
Daniel Kulp
[email protected]
http://www.dankulp.com/blog

Reply via email to