You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Julian Hagenauer <ch...@gmx.de> on 2006/12/17 14:26:03 UTC

Exception on accesing MessageContext during initalization of ws-service

Hi,
i am pretty new to axis.
I am trying to modify the initialize()-function of a webservice of the globus-container.

The origin initialize()-Function looks like that:
public synchronized void initialize() {
	try { 
		MessageContext ctx = MessageContext.getCurrentContext(); 
		globusLocation = (String) ctx.getProperty(org.apache.axis.Constants.MC_CONFIGPATH);
	} catch(Exception e) { ...

This works well as exspected.
I am now trying to rewrite a new initalize-funktion that usees threads:
public synchronized void initialize() throws Exception {
    	class InitThread extends Thread {
		InitThread() { super(); }
		public void run() {
			try { 
				MessageContext ctx = MessageContext.getCurrentContext(); 
				String globusLocation = (String) ctx.getProperty(org.apache.axis.Constants.MC_CONFIGPATH);
			} catch(Exception e) { System.err.println("3:"+e.getMessage()); }
		}

		public void test() {
			try { 
				MessageContext ctx = MessageContext.getCurrentContext(); 
				String globusLocation = (String) ctx.getProperty(org.apache.axis.Constants.MC_CONFIGPATH);
			} catch(Exception e) { System.err.println("2:"+e.getMessage()); }
		};
	};
	try { 
		MessageContext ctx = MessageContext.getCurrentContext(); 
		String globusLocation = (String) ctx.getProperty(org.apache.axis.Constants.MC_CONFIGPATH);
	} catch(Exception e) { System.err.println("1:"+e.getMessage()); }
	InitThread initThread = new InitThread();
	initThread.test();
	initThread.start();
}

If i start the globus-container, i get "3:null". The exception itself is null, i can't get further information about it.
So, if you look at the code, all ctx.getProperty()-calls finish with success, only the one in the run()-method fails.
Why that? Is there a simple way around that?

Thank you,
Julian


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: Exception on accesing MessageContext during initalization of ws-service

Posted by Martin Gainty <mg...@hotmail.com>.
Julian-

the only way (i know how) to handle this scenario  is to setup a listener which will incorporate access to threads and thread management in your start method
a good starting point is to view the listener class org.apache.axis2.transport.mail.SimpleMailListener and look at the start method way to access worker threads and manage those threads thru ThreadPoolExecutor
BTW if you can ping dims he would know a better way to implement these thread management scenarios 

HTH,
M-
--------------------------------------------------------------------------- 
This e-mail message (including attachments, if any) is intended for the use of the individual or entity to which it is addressed and may contain information that is privileged, proprietary , confidential and exempt from disclosure. If you are not the intended recipient, you are notified that any dissemination, distribution or copying of this communication is strictly prohibited.


> Hi,
> i am pretty new to axis.
> I am trying to modify the initialize()-function of a webservice of the globus-container.
> 
> The origin initialize()-Function looks like that:
> public synchronized void initialize() {
> try { 
> MessageContext ctx = MessageContext.getCurrentContext(); 
> globusLocation = (String) ctx.getProperty(org.apache.axis.Constants.MC_CONFIGPATH);
> } catch(Exception e) { ...
> 
> This works well as exspected.
> I am now trying to rewrite a new initalize-funktion that usees threads:
> public synchronized void initialize() throws Exception {
>    class InitThread extends Thread {
> InitThread() { super(); }
> public void run() {
> try { 
> MessageContext ctx = MessageContext.getCurrentContext(); 
> String globusLocation = (String) ctx.getProperty(org.apache.axis.Constants.MC_CONFIGPATH);
> } catch(Exception e) { System.err.println("3:"+e.getMessage()); }
> }
> 
> public void test() {
> try { 
> MessageContext ctx = MessageContext.getCurrentContext(); 
> String globusLocation = (String) ctx.getProperty(org.apache.axis.Constants.MC_CONFIGPATH);
> } catch(Exception e) { System.err.println("2:"+e.getMessage()); }
> };
> };
> try { 
> MessageContext ctx = MessageContext.getCurrentContext(); 
> String globusLocation = (String) ctx.getProperty(org.apache.axis.Constants.MC_CONFIGPATH);
> } catch(Exception e) { System.err.println("1:"+e.getMessage()); }
> InitThread initThread = new InitThread();
> initThread.test();
> initThread.start();
> }
> 
> If i start the globus-container, i get "3:null". The exception itself is null, i can't get further information about it.
> So, if you look at the code, all ctx.getProperty()-calls finish with success, only the one in the run()-method fails.
> Why that? Is there a simple way around that?
> 
> Thank you,
> Julian
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
> 
>

Re: Exception on accesing MessageContext during initalization of ws-service

Posted by Jeff Greif <je...@gmail.com>.
See java.lang.ThreadLocal javadoc

Julian Hagenauer wrote:
> On Mon, 18 Dec 2006 06:43:41 -0800
> "Jeff Greif" <jg...@alumni.princeton.edu> wrote:
>
>   
>> In Axis 1.x, MessageContext.getCurrentContext() retrieves a value from
>> ThreadLocal storage.  The same thing may be done in Axis 2.  To make
>> this call available in some thread you create, you would have to know
>> its exact implementation and set the ThreadLocal storage of the thread
>> you create accordingly..
>>
>> Jeff
>>     
>
> Hi,
> i am using Axis 1.x.
> Can you give some further instructions how to set the ThreadLocal storage?
>
> Thank you,
> Julian
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
>
>
>   

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: Exception on accesing MessageContext during initalization of ws-service

Posted by Julian Hagenauer <ch...@gmx.de>.
On Mon, 18 Dec 2006 06:43:41 -0800
"Jeff Greif" <jg...@alumni.princeton.edu> wrote:

> In Axis 1.x, MessageContext.getCurrentContext() retrieves a value from
> ThreadLocal storage.  The same thing may be done in Axis 2.  To make
> this call available in some thread you create, you would have to know
> its exact implementation and set the ThreadLocal storage of the thread
> you create accordingly..
> 
> Jeff

Hi,
i am using Axis 1.x.
Can you give some further instructions how to set the ThreadLocal storage?

Thank you,
Julian

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: Exception on accesing MessageContext during initalization of ws-service

Posted by Jeff Greif <jg...@alumni.princeton.edu>.
In Axis 1.x, MessageContext.getCurrentContext() retrieves a value from
ThreadLocal storage.  The same thing may be done in Axis 2.  To make
this call available in some thread you create, you would have to know
its exact implementation and set the ThreadLocal storage of the thread
you create accordingly..

Jeff


On 12/17/06, Julian Hagenauer <ch...@gmx.de> wrote:
> Hi,
> i am pretty new to axis.
> I am trying to modify the initialize()-function of a webservice of the globus-container.
>
> The origin initialize()-Function looks like that:
> public synchronized void initialize() {
>         try {
>                 MessageContext ctx = MessageContext.getCurrentContext();
>                 globusLocation = (String) ctx.getProperty(org.apache.axis.Constants.MC_CONFIGPATH);
>         } catch(Exception e) { ...
>
> This works well as exspected.
> I am now trying to rewrite a new initalize-funktion that usees threads:
> public synchronized void initialize() throws Exception {
>         class InitThread extends Thread {
>                 InitThread() { super(); }
>                 public void run() {
>                         try {
>                                 MessageContext ctx = MessageContext.getCurrentContext();
>                                 String globusLocation = (String) ctx.getProperty(org.apache.axis.Constants.MC_CONFIGPATH);
>                         } catch(Exception e) { System.err.println("3:"+e.getMessage()); }
>                 }
>
>                 public void test() {
>                         try {
>                                 MessageContext ctx = MessageContext.getCurrentContext();
>                                 String globusLocation = (String) ctx.getProperty(org.apache.axis.Constants.MC_CONFIGPATH);
>                         } catch(Exception e) { System.err.println("2:"+e.getMessage()); }
>                 };
>         };
>         try {
>                 MessageContext ctx = MessageContext.getCurrentContext();
>                 String globusLocation = (String) ctx.getProperty(org.apache.axis.Constants.MC_CONFIGPATH);
>         } catch(Exception e) { System.err.println("1:"+e.getMessage()); }
>         InitThread initThread = new InitThread();
>         initThread.test();
>         initThread.start();
> }
>
> If i start the globus-container, i get "3:null". The exception itself is null, i can't get further information about it.
> So, if you look at the code, all ctx.getProperty()-calls finish with success, only the one in the run()-method fails.
> Why that? Is there a simple way around that?
>
> Thank you,
> Julian
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org