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 Juha Kononen <Ju...@savonia-amk.fi> on 2005/08/17 12:28:04 UTC
Using global variables in Axis (HttpSession and
ServletContext)
Thanks for advise!
Too bad that it's not possible to get an access to MessageContext in
user's own threads.
Does this mean that the session mechanism can be used only partially in
axis (because there is no
way to get HttpSession in threads)? I had an idea to use HttpSession as
a global variable in each session where to
store session-specific information (data sent by a client) for each
client. This global
session-specific storage would help me to get data directly instead of
passing it
to objects and threads via many function parameters (in contrast to
HttpSession I use ServletContext as a global variable
for storing a reference to a database pool). Of course, I could get the
data sent by a client via a static class variable
in my DSServiceSOAPBindingImpl class. But unfortunately class variables
are shared with all sessions, so that will not work if
I want my class variables to be session-spefic. So is there any way I
can use a global, session-specific variable anywhere in
my server-side code (including those threads)? Java doesn't have global
variables, but don't we still need them? :)
Juha
>>> jgreif@alumni.princeton.edu 08/16 4:18 >>>
The message context returned from this method is held in a thread-local
variable of the thread handling the web service request. This is the
way a
static method can be used to return a message context correctly for
simultaneously-handled web service requests of various kinds. However,
it
only works in the request-handling threads (i.e., the ones in which the
implementation method of the web service operation is called).
Jeff
----- Original Message -----
From: Juha Kononen
To: axis-user@ws.apache.org
Sent: Tuesday, August 16, 2005 4:03 AM
Subject: The static MessageContext.getCurrentContext method
doesn'twork
Hi, I have a problem with using the MessageContext.getCurrentContext
method
in my server-side code.
I would like to get the current context to able to get an access to the
current session. Well, everything works just fine if I use the
getCurrentContext method in one of my own objects, but something
strange
happends when I'm trying to use this method inside a thread. Everytime
I
call the MessageContext.getCurrentContext method in a thread it returns
only
null. Is this a bug? As I told, the the
MessageContext.getCurrentContext
method works great, I can get my MessageContext object, if I don't use
the
method in threads. Have you guys got this method working in threads?
Even if
I can pass a MessageContext reference into a thread via a static
variable
the getCurrentContext doesn't work. There's got to be something wrong
with
this method. Because of this problem it's impossible to make use of the
session mechanism in threads.
Re: Using global variables in Axis (HttpSession and ServletContext)
Posted by Jeff Greif <jg...@alumni.princeton.edu>.
You can get access to the MessageContext in your threads IF you put it
there yourself instead of depending on the static method
MessageContext.getCurrentContext(). Having invoked that method where it
works (the thread handling the web service request), you can place the
result in a thread local of other threads.
That is, if your thread lives for the processing of a single request,
you can copy the message context reference to it when you create the
thread. Otherwise you copy it to the thread each time it starts
processing a request.
Jeff
Juha Kononen wrote:
>Thanks for advise!
>
> Too bad that it's not possible to get an access to MessageContext in
>user's own threads.
>Does this mean that the session mechanism can be used only partially in
>axis (because there is no
>way to get HttpSession in threads)? I had an idea to use HttpSession as
>a global variable in each session where to
>store session-specific information (data sent by a client) for each
>client. This global
>session-specific storage would help me to get data directly instead of
>passing it
>to objects and threads via many function parameters (in contrast to
>HttpSession I use ServletContext as a global variable
>for storing a reference to a database pool). Of course, I could get the
>data sent by a client via a static class variable
>in my DSServiceSOAPBindingImpl class. But unfortunately class variables
>are shared with all sessions, so that will not work if
>I want my class variables to be session-spefic. So is there any way I
>can use a global, session-specific variable anywhere in
>my server-side code (including those threads)? Java doesn't have global
>variables, but don't we still need them? :)
>
>Juha
>
>
>