You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Paul Baker <pb...@mindspring.com> on 2012/01/16 13:00:35 UTC
Re: Thread Local Storage not working in CXF Interceptors
Hi Daniel,
Two Questions:
Questions:
For R&R services, is the same thread used for all phases: inbound
interceptores, service invokation, outbound?
If not, what would be the best pattern to make sure that a context object is
available during the entire invokation lifecycle? (Same context available to
inbound interceptors, service invocation, and outbound interceptors.)
Background:
I have a similar question regarding the use of interceptor threads. I have
inbound and outbound interceptors used for auditing. The inbound
interceptor captures the inbound soap message and creates a service context
object and stores it in the TLS. During the service processing I have other
objects stored in the TLS (i.e. from Hibernate Interceptors). The outbound
audit interceptor captures the outbound soap (fault) message and then
persists all of the audit events that have occured for this service
invocation.
My assumption has been that the same thread will be used for inbound,
service, and outbound interceptors. All of the services are Request/Reply.
I am new to cxf but so far is has done everything I have needed.
FYI My Context Factory Class looks Like:
public class ContextFactory {
private ThreadLocal<Context> userThreadLocal = new
ThreadLocal<Context>() {
protected Context initialValue() {
Context serviceContext = new Context();
// Generate and set transaction ID
serviceContext.setTxnUUID(UUID.randomUUID());
return serviceContext;
}
};
private static ContextFactory instance = new ContextFactory();
public static ContextFactory getFactory() {
return instance;
}
/**
* Get the service context.
* <p>
* On the initial call the service context is initialized.
*
* @since Oct 8, 2010
* @return ServiceContext
* @return
*/
public Context getContext() {
return userThreadLocal.get();
}
/**
* Remove the service context.
*
* @since Oct 8, 2010
* @return void
*/
public void unsetContext() {
userThreadLocal.remove();
}
Paul
--
View this message in context: http://cxf.547215.n5.nabble.com/Thread-Local-Storage-not-working-in-CXF-Interceptors-tp4439646p5148525.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: Thread Local Storage not working in CXF Interceptors
Posted by Daniel Kulp <dk...@apache.org>.
On Monday, January 16, 2012 4:00:35 AM Paul Baker wrote:
> Hi Daniel,
>
> Two Questions:
>
> Questions:
> For R&R services, is the same thread used for all phases: inbound
> interceptores, service invokation, outbound?
In the absence of WS-Addressing or WS-RM (which implies WS-Addressing), then
yes. One-Way invokations and certain uses of WS-RM/WS-A can result in the
request moving to different threads.
> If not, what would be the best pattern to make sure that a context object is
> available during the entire invokation lifecycle? (Same context available
> to inbound interceptors, service invocation, and outbound interceptors.)
If possible, use the CXF message object (or the Exchange object that it holds
onto). You can always call PhaseInterceptorChain.getCurrentMessage() to get
the current message being processed. If the message needs to flip threads,
everything it holds onto would go with it.
Dan
>
> Background:
> I have a similar question regarding the use of interceptor threads. I have
> inbound and outbound interceptors used for auditing. The inbound
> interceptor captures the inbound soap message and creates a service context
> object and stores it in the TLS. During the service processing I have other
> objects stored in the TLS (i.e. from Hibernate Interceptors). The outbound
> audit interceptor captures the outbound soap (fault) message and then
> persists all of the audit events that have occured for this service
> invocation.
>
> My assumption has been that the same thread will be used for inbound,
> service, and outbound interceptors. All of the services are Request/Reply.
>
> I am new to cxf but so far is has done everything I have needed.
>
> FYI My Context Factory Class looks Like:
>
> public class ContextFactory {
>
> private ThreadLocal<Context> userThreadLocal = new
> ThreadLocal<Context>() {
> protected Context initialValue() {
> Context serviceContext = new Context();
> // Generate and set transaction ID
> serviceContext.setTxnUUID(UUID.randomUUID());
>
> return serviceContext;
> }
> };
>
> private static ContextFactory instance = new ContextFactory();
>
> public static ContextFactory getFactory() {
> return instance;
> }
>
> /**
> * Get the service context.
> * <p>
> * On the initial call the service context is initialized.
> *
> * @since Oct 8, 2010
> * @return ServiceContext
> * @return
> */
> public Context getContext() {
> return userThreadLocal.get();
> }
>
> /**
> * Remove the service context.
> *
> * @since Oct 8, 2010
> * @return void
> */
> public void unsetContext() {
> userThreadLocal.remove();
> }
>
>
> Paul
>
> --
> View this message in context:
> http://cxf.547215.n5.nabble.com/Thread-Local-Storage-not-working-in-CXF-Int
> erceptors-tp4439646p5148525.html Sent from the cxf-user mailing list archive
> at Nabble.com.
--
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com