I didn't use it for MessageContext, but code may look like :
// Little helper class
public class MessageContextHelper {
private static ThreadLocal context = new ThreadLocal();
public static MessageContext getContext() {
return (MessageContext) context.get();
}
public static void setContext(MessageContext ctx) {
context.set(ctx);
}
// Handler which setup MessageContext before service execution
public class ContextSetupHandler extends AbstractHandler {
public void invoke(MessageContext context) throws Exception {
MessageContextHelper.setContext(context);
}
}
// Service class
public class MyServiceImpl {
public void doSomething(){
MessageContext ctx = MessageContextHelper.getContext();
// Do something with MessageContext
}
}
And remeber to close ThreadLocal when you are done.
On 10/20/06, Michel Drescher <[EMAIL PROTECTED]> wrote:
Tomek,
Tomek Sztelak wrote:
> On 10/20/06, Chris Thatcher <[EMAIL PROTECTED]> wrote:
>>
>> Just spouting this off the top of my head (or pulling it out of my
>> ...;) but
>> there is always an implementing class for the service, and somewhere
>> in the
>> handler chain that class is resolved to an instance, which may be new for
>> each call, live across a session, or be a persistent instance of the
>> service.
>> Regardless, what about putting a getter/setter for message context in the
>> service impl class and then shouldn't it be possible to create a
>> handler that
>> is invoked after the servicecall-to-instance resolution (is the the
>> 'dispatch' phase? Anyone know for sure?) that injects the message context
>> into the service impl for you?
>
> I'm not sure if setting MessageContext on service instance is a good
> idea, too many thradsafty problems.
>
> I also'don't like modifying service signature do get access to
> MessageContext, i prefer using ThreadLocal variable to get access to
> some required data. So one handler put MessageContext in ThreadLocal,
> then inside your service you just get context and no methods must be
> changed :)
Interesting ... do you have some code snippets for me?
Cheers,
Michel
>
>
>> Micheal, this is probably close to what you annotation does? If so I
>> actually be interested the details of how it is accomplished.
>>
>> Thanks,
>> Thatch
--
Michel <dot> Drescher <at> uk <dot> fujitsu <dot> com
Fujitsu Laboratories of Europe
+44 20 8606 4834
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email
--
-----
When one of our products stops working, we'll blame another vendor
within 24 hours.
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email