The problem is that the current MessageContext is store in a ThreadLocal of
the thread that received the Web service request. It is possible that this
is not the same thread that is running within the EJB. The EJB is within the
control of the AppServer. The AppServer maintains a pool of bean instances
and handles thread allocation. Therefore, the thread that received the Web
service request, and the EJB thread that runs you bean are two different
threads. So MessageContext.getCurrentMessageContext() will return null
within the EJB implementation object.

May I ask, why are you trying to access the MessageContext within an EJB?
MessageContext is an Axis2 level concept. Why are you burning that into your
EJB, which should be independent from the Axis2 Web service framework.

HTH
Azeez

On Jan 22, 2008 8:29 PM, Etches, Adam (GE Infra, Energy) <[EMAIL PROTECTED]>
wrote:

>  Hi,
>
> The Axis jars are in the lib directory of the axis2 project and the ejb
> jar definition has a class path property in the manifest.mf to load them
> from <axis2_home>/lib directory.
>
> The call to the ejb is from the same JVM as the web service so the calls
> are all 'ejb local'.
>
> I have followed the steps documented in the guide
> http://ws.apache.org/axis2/1_2/ejb-provider.html and I have reproduced the
> problem on this example. All I did was to add the messagecontext call to the
> HelloBean.java sayHello method :
>
>     MessageContext msgCtx = MessageContext.*getCurrentMessageContext*();
>     System.err.print(msgCtx);
>
> Then I modified the HelloBean's ejb manifest.mf to include a class path
> for axis2-kernel-1.3.jar and  axiom-api-1.2.5.jar and deployed this bean
> in JBOSS.
>
> When I execute this service the print from STDOUT reports the msgCtx as
> null.
>
> It's getting a bit frustrating now.
>
>
> Adam
>
>
>  ------------------------------
> *From:* Andreas Veithen [mailto:[EMAIL PROTECTED]
> *Sent:* 21 January 2008 21:49
> *To:* axis-user@ws.apache.org
> *Subject:* Re: getCurrentMessageContext() returns null when invoked from
> an EJB?
>
>  Hi,
>
> MessageContext stores the current message context in a ThreadLocal. To be
> able to retrieve it, two conditions must be met:
>
> 1) The Axis JARs must be loaded from the same class loader.
> 2) MessageContext#getCurrentMessageContext must be called from within the
> thread that received the request.
>
> For point 1: Where did you put the Axis JARs?
> For point 2: I'm not very familiar with EJBs, but it might be that this is
> the case only if the EJB is called through its local interface.
>
> Regards,
>
> Andreas
>
>  On 21 Jan 2008, at 15:39, Etches, Adam (GE Infra, Energy) wrote:
>
>  Hi all first time posting…
>  I have been looking at implementing web services in axis2-1.3 with EJB
> 2.1. I need to get a handle on the message from with in the service
> implementation.  I believe the correct approach for this is to invoke the
> method getCurrentMessageContext() on MessageContext from with in the service
> .
>
>
> I have tried this in a test pojo service which correctly returns the
> message context but when called *BUT* when invoking this method from 
> anEJBnull is returned
> .
>  Does anyone know why the getCurrentMessageContext()  returns null when
> invoked from an EJB?
>
>
> thanks
> Adam
>
>
>
>


-- 
Thanks
Afkham Azeez

http://www.wso2.org
GPG Fingerprint: 643F C2AF EB78 F886 40C9  B2A2 4AE2 C887 665E 0760

Reply via email to