My recommendation is to use paramters as much as you can, but if you can
not solve your problem with paramters then you have to use other types.

If you want have that variable access only for single execution, then do
not use ConfigurationContext, use MesageContext of OperationContext.

Deepal

J. Hondius wrote:
> Thanks again Deepal!
>
> Thats the exactly the point.
> I *want* it to be for single execution/one invocation.
> The problem is that static variables behave badly in axis!
> They get shared between invocations and persist from one invocation to
> the next.
>
> In my book thats weird behaviour, altough i think i understand why
> axis behaves that way:
> Axis' classloader loads once, but every invocation gets a fresh instance.
> The static var is part of a the class, not of the fresh instance however.
>
> So statics can be used instead of ConfigurationContext params ;)
> (not advisable?)
>
> Please reply if you think i'm reasoning incorrectly, more code will
> rely on this solution.
>
> Greetings, Joek
>
>
> Deepal jayasinghe schreef:
>> Nope, that is not going to work. The reason is MessageContext has very
>> limited lifetime, and that is only for single execution. So if you want
>> to share something in one invocation then messageContext is fine, but if
>> you want to have the "static nature" then you need to store the value in
>> the ConfigurationContext.
>>
>> Deepal
>>  
>>> I think i found a way.
>>> See below.
>>> Please comment on it.
>>>
>>>
>>> J. Hondius schreef:
>>>    
>>>> Hi,
>>>>
>>>> Please help.
>>>> I have a need for a variable that is globally accessible from my
>>>> service implementation.
>>>> The normal way to do this in java is using statics AFAIK.
>>>>
>>>> I am however painfully aware that i cannot use static variables in
>>>> axis2.
>>>> They will be shared across all service instances, and persist after
>>>> the service call is done.
>>>> I believe this has to do with the axis2 classloader.
>>>>
>>>> I really need to use some globally accessible variable in my service
>>>> implementation though! How do i go about?
>>>>
>>>> My service implementation is a pojo BTW.
>>>>
>>>> Greetings from Holland, Joek
>>>>       
>>> Im registring the "global variable" as a property in the
>>> messagecontext.
>>> Access to this "global variable/messagecontect property" is via a
>>> getter and setter in a obeject that is a static itself.
>>> Because its a static its acessible from anywhere in the code.
>>> Testing reveils that the values do not get messed up.
>>>
>>> PS a am aware that using globals is not a nice thing.
>>>
>>> Example code:
>>>
>>> the wrapper class for the get/set access
>>> ---------------------------------------
>>> public class GlobalHolder{
>>>    // staticly instantiate itself
>>>    public static GlobalHolder globalholder = new GlobalHolder();
>>>
>>>    public int getGlobalVar() {
>>>        MessageContext messageContext =
>>> MessageContext.getCurrentMessageContext();
>>>         return (Integer) messageContext.getProperty("globalvar");
>>>    }
>>>
>>>    public int setGlobalVar(int pValue) {
>>>        MessageContext messageContext =
>>> MessageContext.getCurrentMessageContext();
>>>         messageContext.setProperty("globalvar", pValue);
>>>    }
>>>   }
>>>
>>>
>>> in the Main class
>>> -----------------
>>> public class Mainclass {
>>>    public Mainclass(){
>>>         //constructor: make sure the property exists to avoid null
>>> pointers
>>>         GlobalHolder.globalholder.setGlobalVar(0);
>>>    }
>>>
>>>    public int myMethod(){
>>>        // go about getting and setting it everywhere in the code.
>>>        GlobalHolder.globalholder.setGlobalVar(700);
>>>        return GlobalHolder.globalholder.getGlobalVar();
>>>    }
>>>
>>> }
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>     
>>
>>
>>   
>

-- 
Thank you!


http://blogs.deepal.org
http://deepal.org

Reply via email to