You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by "Kessel, Christopher" <ck...@transunion.com> on 2010/03/02 16:47:35 UTC

jaxws endpoint threadsafe as a Spring singleton?

I've defined my bean in Spring as per some examples in the CXF tutorial
pages:

<bean id="fooImpl" class="FooServerImpl"></bean>
<jaxws:endpoint id="foo" implementor="#fooImpl"
address="/foo"></jaxws:endpoint>

My FooServerImpl has a reference to the WebServiceContext (because I
have to get to the SerlvetContext for historical reasons).

    @Resource
    private WebServiceContext _wsContext;

The javadoc on WebServiceContext says that _wsContext is relative to the
request being served:

 *  A <code>WebServiceContext</code> makes it possible for
 *  a web service endpoint implementation class to access
 *  message context and security information relative to
 *  a request being served.

So, my question is, if FooServerImpl is a Spring singleton (which I
think is the default, at least in the application I'm working on), would
that mean the _wsContext isn't thread safe since it's related to each
request? If I had 2 requests come in simultaneously, the _wsContext for
the 2nd one would clobber the value set for the first request. Yes?

Thanks,
Chris

RE: jaxws endpoint threadsafe as a Spring singleton?

Posted by Ron Grimes <rg...@sinclairoil.com>.
I've used the WebServiceContext for purposes such as to retrieve the client's IP address. Never had a problem with it. Also, if you look at the source code for WebServiceContextImpl, you'll see that it uses a ThreadLocal type for the context. And, if you look at the source on ThreadLocal, you'll see that the documentation reads:

"**
 * This class provides thread-local variables.  These variables differ from
 * their normal counterparts in that each thread that accesses one (via its
 * <tt>get</tt> or <tt>set</tt> method) has its own, independently initialized
 * copy of the variable."


Ron Grimes


-----Original Message-----
From: Kessel, Christopher [mailto:ckessel@transunion.com] 
Sent: Tuesday, March 02, 2010 8:48 AM
To: users@cxf.apache.org
Subject: jaxws endpoint threadsafe as a Spring singleton?

I've defined my bean in Spring as per some examples in the CXF tutorial
pages:

<bean id="fooImpl" class="FooServerImpl"></bean>
<jaxws:endpoint id="foo" implementor="#fooImpl"
address="/foo"></jaxws:endpoint>

My FooServerImpl has a reference to the WebServiceContext (because I
have to get to the SerlvetContext for historical reasons).

    @Resource
    private WebServiceContext _wsContext;

The javadoc on WebServiceContext says that _wsContext is relative to the
request being served:

 *  A <code>WebServiceContext</code> makes it possible for
 *  a web service endpoint implementation class to access
 *  message context and security information relative to
 *  a request being served.

So, my question is, if FooServerImpl is a Spring singleton (which I
think is the default, at least in the application I'm working on), would
that mean the _wsContext isn't thread safe since it's related to each
request? If I had 2 requests come in simultaneously, the _wsContext for
the 2nd one would clobber the value set for the first request. Yes?

Thanks,
Chris