You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by Carsten Ziegeler <cz...@apache.org> on 2006/07/10 11:33:23 UTC

[Axis2] Problems with MessageContext

While playing around with implementing my own handler, I found out,
that the getProperties() method of the MessageContext is not implemented
correctly: MessageContext overrides the property handling of the parent
class by setting/getting properties from the Options object. But
getProperties() is passed on to the parent class which then always
returns an empty map. (Using getOptions().getProperties() of course works).
If you need an implementation for getProperties() which uses the Options
object I can provide it.

In addition it seems that the outgoing MessageContext objects do not
contain the servlet context. Is this by mistake or by design? If it's
the latter, how can I access the servlet context?

Thanks
Carsten
-- 
Carsten Ziegeler - Open Source Group, S&N AG
http://www.s-und-n.de
http://www.osoco.org/weblogs/rael/


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


Re: [Axis2] Problems with MessageContext

Posted by Deepal Jayasinghe <de...@opensource.lk>.

Carsten Ziegeler wrote:

>Deepal Jayasinghe wrote:
>  
>
>>If you are happy with unmodifiable map then I have no objection , any
>>way if some one want to modify property (or properties) he can easily do
>>that no need to call the getProperties and then modify the map.
>>
>>So lets keep what we have now  :)
>>
>>    
>>
>You mean with my patch :) (Because the current impl always returns an
>empty map).
>I updated the patch to create an unmodifiable map and added some javadocs.
>  
>
The one return unmodifiable map

>Carsten
>
>
>  
>
>------------------------------------------------------------------------
>
>Index: D:/dev/workspace/axis2/modules/core/src/org/apache/axis2/context/MessageContext.java
>===================================================================
>--- D:/dev/workspace/axis2/modules/core/src/org/apache/axis2/context/MessageContext.java	(revision 421208)
>+++ D:/dev/workspace/axis2/modules/core/src/org/apache/axis2/context/MessageContext.java	(working copy)
>@@ -30,6 +30,9 @@
> 
> import javax.xml.namespace.QName;
> import java.util.ArrayList;
>+import java.util.Collections;
>+import java.util.HashMap;
>+import java.util.Map;
> 
> /**
>  * MessageContext holds service specific state information.
>@@ -471,6 +474,42 @@
>     }
> 
>     /**
>+     * Retrieves all property values. The order of search is as follows: search in
>+     * my own options and then look in my context hierarchy. Since its possible
>+     * that the entire hierarchy is not present, it will start at whatever level
>+     * has been set and start there.
>+     * The returned map is unmodifiable, so any changes to the properties have
>+     * to be done by calling {@link #setProperty(String, Object)}. In addition,
>+     * any changes to the properties are not reflected on this map.
>+     *
>+     * @return An unmodifiable map containing the combination of all available
>+     *         properties or an empty map.
>+     */
>+    public Map getProperties() {
>+        final Map resultMap = new HashMap();
>+
>+        // My own context hierarchy may not all be present. So look for whatever
>+        // nearest level is present and add the properties
>+        // We have to access the contexts in reverse order, in order to allow
>+        // a nearer context to overwrite values from a more distant context
>+        if (configurationContext != null) {
>+            resultMap.putAll(configurationContext.getProperties());
>+        }
>+        if (serviceGroupContext != null) {
>+            resultMap.putAll(serviceGroupContext.getProperties());
>+        }
>+        if (serviceContext != null) {
>+            resultMap.putAll(serviceContext.getProperties());
>+        }
>+        if (operationContext != null) {
>+            resultMap.putAll(operationContext.getProperties());
>+        }
>+        // and now add options
>+        resultMap.putAll(options.getProperties());
>+        return Collections.unmodifiableMap(resultMap);
>+    }
>+
>+    /**
>      * @return Returns RelatesTo array.
>      */
>     public RelatesTo[] getRelationships() {
>
>  
>
>------------------------------------------------------------------------
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: axis-dev-unsubscribe@ws.apache.org
>For additional commands, e-mail: axis-dev-help@ws.apache.org
>

-- 
Thanks,
Deepal
................................................................
~Future is Open~ 



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


Re: [Axis2] Problems with MessageContext

Posted by Carsten Ziegeler <cz...@apache.org>.
Deepal Jayasinghe wrote:
> If you are happy with unmodifiable map then I have no objection , any
> way if some one want to modify property (or properties) he can easily do
> that no need to call the getProperties and then modify the map.
> 
> So lets keep what we have now  :)
> 
You mean with my patch :) (Because the current impl always returns an
empty map).
I updated the patch to create an unmodifiable map and added some javadocs.

Carsten


-- 
Carsten Ziegeler - Open Source Group, S&N AG
http://www.s-und-n.de
http://www.osoco.org/weblogs/rael/

Re: [Axis2] Problems with MessageContext

Posted by Deepal Jayasinghe <de...@opensource.lk>.
If you are happy with unmodifiable map then I have no objection , any
way if some one want to modify property (or properties) he can easily do
that no need to call the getProperties and then modify the map.

So lets keep what we have now  :)

Carsten Ziegeler wrote:

>Carsten Ziegeler schrieb:
>  
>
>>Deepal Jayasinghe wrote:
>>    
>>
>>>Hi Carsten;
>>>
>>>I went through your patch and realized that , you are giving read only
>>>access to the properties . So if someone want to change the value of
>>>property (properties) then he wont be able to do that. I think we need
>>>to provide way to change them as well .
>>>
>>>      
>>>
>>Hmm, but in this case has the MessageContext no control about what has
>>been changed, because it happens outside of its context.
>>
>>But I will come up with another patch which will handle put and remove
>>as well.
>>
>>    
>>
>Ok, I look at a possible solution - but I think it's not worth the effort :)
>In order to be able to change the map, it's requrired to provide a map
>implementation which acts as a wrapepr around all the other maps. Simple
>operations like put,get,remove etc. are simple to implement - but
>complex ones, like values(), entrySet() etc. require a lot of code.
>We could use commons-collections and their CompositeMap for that - at
>least partically.
>
>Before I implement this, I would like to know if adding a dependency to
>commons collections just for this simple feature is fine. Personally I
>think the getProperties() method should return an unmodifiable map.
>
>Carsten
>
>
>  
>

-- 
Thanks,
Deepal
................................................................
~Future is Open~ 




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


Re: [Axis2] Problems with MessageContext

Posted by Carsten Ziegeler <cz...@apache.org>.
Carsten Ziegeler schrieb:
> Deepal Jayasinghe wrote:
>> Hi Carsten;
>>
>> I went through your patch and realized that , you are giving read only
>> access to the properties . So if someone want to change the value of
>> property (properties) then he wont be able to do that. I think we need
>> to provide way to change them as well .
>>
> Hmm, but in this case has the MessageContext no control about what has
> been changed, because it happens outside of its context.
> 
> But I will come up with another patch which will handle put and remove
> as well.
> 
Ok, I look at a possible solution - but I think it's not worth the effort :)
In order to be able to change the map, it's requrired to provide a map
implementation which acts as a wrapepr around all the other maps. Simple
operations like put,get,remove etc. are simple to implement - but
complex ones, like values(), entrySet() etc. require a lot of code.
We could use commons-collections and their CompositeMap for that - at
least partically.

Before I implement this, I would like to know if adding a dependency to
commons collections just for this simple feature is fine. Personally I
think the getProperties() method should return an unmodifiable map.

Carsten


-- 
Carsten Ziegeler - Open Source Group, S&N AG
http://www.s-und-n.de
http://www.osoco.org/weblogs/rael/

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


Re: [Axis2] Problems with MessageContext

Posted by Carsten Ziegeler <cz...@apache.org>.
Deepal Jayasinghe wrote:
> Hi Carsten;
> 
> I went through your patch and realized that , you are giving read only
> access to the properties . So if someone want to change the value of
> property (properties) then he wont be able to do that. I think we need
> to provide way to change them as well .
> 
Hmm, but in this case has the MessageContext no control about what has
been changed, because it happens outside of its context.

But I will come up with another patch which will handle put and remove
as well.

Carsten

-- 
Carsten Ziegeler - Open Source Group, S&N AG
http://www.s-und-n.de
http://www.osoco.org/weblogs/rael/

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


Re: [Axis2] Problems with MessageContext

Posted by Deepal Jayasinghe <de...@opensource.lk>.
Hi Carsten;

I went through your patch and realized that , you are giving read only
access to the properties . So if someone want to change the value of
property (properties) then he wont be able to do that. I think we need
to provide way to change them as well .



Carsten Ziegeler wrote:

>Sanjiva Weerawarana wrote:
>  
>
>>On Tue, 2006-07-11 at 08:19 +0200, Carsten Ziegeler wrote:
>>    
>>
>>>>So in effect the properties hashtable inherited from the superclass is
>>>>not used by the MessageContext class.
>>>>
>>>>        
>>>>
>>>Yes, except in the getProperties() method. If you do a setProperty("A",
>>>"B") on the message context and then do a getProperties().get("A"), you
>>>end up with getting null and not "B". So I think it should be fixed.
>>>      
>>>
>>Oops, you're right of course! Send a patch? :)
>>    
>>
>
>Sure, here we go :)
>
>The implementation is adding the properties from the various contexts
>into a map (reversing the search order) and returns the combined map.
>
>Carsten
>  
>
>------------------------------------------------------------------------
>
>Index: D:/dev/workspace/axis2/modules/core/src/org/apache/axis2/context/MessageContext.java
>===================================================================
>--- D:/dev/workspace/axis2/modules/core/src/org/apache/axis2/context/MessageContext.java	(revision 420740)
>+++ D:/dev/workspace/axis2/modules/core/src/org/apache/axis2/context/MessageContext.java	(working copy)
>@@ -30,6 +30,8 @@
> 
> import javax.xml.namespace.QName;
> import java.util.ArrayList;
>+import java.util.HashMap;
>+import java.util.Map;
> 
> /**
>  * MessageContext holds service specific state information.
>@@ -471,6 +473,42 @@
>     }
> 
>     /**
>+     * Retrieves all property values. The order of search is as follows: search in
>+     * my own options and then look in my context hierarchy. Since its possible
>+     * that the entire hierarchy is not present, I will start at whatever level
>+     * has been set and start there.
>+     *
>+     * @return the combination of all available properties or an empty map
>+     */
>+    public Map getProperties() {
>+        final Map resultMap = new HashMap();
>+
>+        // My own context hierarchy may not all be present. So look for whatever
>+        // nearest level is present and add the properties
>+        // We have to access the contexts in reverse order, in order to allow
>+        // a nearer context to overwrite values from a more distant context
>+        if (configurationContext != null) {
>+            resultMap.putAll(configurationContext.getProperties());
>+        }
>+        if (serviceGroupContext != null) {
>+            resultMap.putAll(serviceGroupContext.getProperties());
>+        }
>+        if (serviceContext != null) {
>+            resultMap.putAll(serviceContext.getProperties());
>+        }
>+        if (operationContext != null) {
>+            resultMap.putAll(operationContext.getProperties());
>+        }
>+
>+        // and now add options, or if the map is empty so far just return them
>+        if ( resultMap.isEmpty() ) {
>+            return options.getProperties();
>+        }
>+        resultMap.putAll(options.getProperties());
>+        return resultMap;
>+    }
>+
>+    /**
>      * @return Returns RelatesTo array.
>      */
>     public RelatesTo[] getRelationships() {
>
>  
>
>------------------------------------------------------------------------
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: axis-dev-unsubscribe@ws.apache.org
>For additional commands, e-mail: axis-dev-help@ws.apache.org
>

-- 
Thanks,
Deepal
................................................................
~Future is Open~ 




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


Re: [Axis2] Problems with MessageContext

Posted by Carsten Ziegeler <cz...@apache.org>.
Sanjiva Weerawarana wrote:
> On Tue, 2006-07-11 at 08:19 +0200, Carsten Ziegeler wrote:
>>> So in effect the properties hashtable inherited from the superclass is
>>> not used by the MessageContext class.
>>>
>> Yes, except in the getProperties() method. If you do a setProperty("A",
>> "B") on the message context and then do a getProperties().get("A"), you
>> end up with getting null and not "B". So I think it should be fixed.
> 
> Oops, you're right of course! Send a patch? :)

Sure, here we go :)

The implementation is adding the properties from the various contexts
into a map (reversing the search order) and returns the combined map.

Carsten
-- 
Carsten Ziegeler - Open Source Group, S&N AG
http://www.s-und-n.de
http://www.osoco.org/weblogs/rael/

Re: [Axis2] Problems with MessageContext

Posted by Sanjiva Weerawarana <sa...@opensource.lk>.
On Tue, 2006-07-11 at 08:19 +0200, Carsten Ziegeler wrote:
> > So in effect the properties hashtable inherited from the superclass is
> > not used by the MessageContext class.
> > 
> Yes, except in the getProperties() method. If you do a setProperty("A",
> "B") on the message context and then do a getProperties().get("A"), you
> end up with getting null and not "B". So I think it should be fixed.

Oops, you're right of course! Send a patch? :)

Sanjiva.



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


Re: [Axis2] Problems with MessageContext

Posted by Carsten Ziegeler <cz...@apache.org>.
Sanjiva Weerawarana wrote:
> On Mon, 2006-07-10 at 11:33 +0200, Carsten Ziegeler wrote:
>> While playing around with implementing my own handler, I found out,
>> that the getProperties() method of the MessageContext is not implemented
>> correctly: MessageContext overrides the property handling of the parent
>> class by setting/getting properties from the Options object. But
>> getProperties() is passed on to the parent class which then always
>> returns an empty map. (Using getOptions().getProperties() of course works).
>> If you need an implementation for getProperties() which uses the Options
>> object I can provide it.
> 
> IIRC, the behavior desired was for just the message context to use
> options' properties instead of using the local hashtable. This has
> something to do with allowing users to set stuff from outside via
> options and having them take effect at the various contexts.
> 
Ah, thanks for the info.

> So if the property is not found via options.getProperty() then we cross
> over to whatever level of other context is around (operation or service
> or .. etc.) and ask there. 
> 
> Note that setProperty() too has been overridden to match this behavior.
> 
> So in effect the properties hashtable inherited from the superclass is
> not used by the MessageContext class.
> 
Yes, except in the getProperties() method. If you do a setProperty("A",
"B") on the message context and then do a getProperties().get("A"), you
end up with getting null and not "B". So I think it should be fixed.

>> In addition it seems that the outgoing MessageContext objects do not
>> contain the servlet context. Is this by mistake or by design? If it's
>> the latter, how can I access the servlet context?
> 
> Its by design- you have to get the operation context from the outgoing
> MC and then get the incoming MC from that and look there for the servlet
> context and any other "incoming" info.
> 
Ok, thanks!

Carsten
-- 
Carsten Ziegeler - Open Source Group, S&N AG
http://www.s-und-n.de
http://www.osoco.org/weblogs/rael/

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


Re: [Axis2] Problems with MessageContext

Posted by Sanjiva Weerawarana <sa...@opensource.lk>.
On Mon, 2006-07-10 at 11:33 +0200, Carsten Ziegeler wrote:
> While playing around with implementing my own handler, I found out,
> that the getProperties() method of the MessageContext is not implemented
> correctly: MessageContext overrides the property handling of the parent
> class by setting/getting properties from the Options object. But
> getProperties() is passed on to the parent class which then always
> returns an empty map. (Using getOptions().getProperties() of course works).
> If you need an implementation for getProperties() which uses the Options
> object I can provide it.

IIRC, the behavior desired was for just the message context to use
options' properties instead of using the local hashtable. This has
something to do with allowing users to set stuff from outside via
options and having them take effect at the various contexts.

So if the property is not found via options.getProperty() then we cross
over to whatever level of other context is around (operation or service
or .. etc.) and ask there. 

Note that setProperty() too has been overridden to match this behavior.

So in effect the properties hashtable inherited from the superclass is
not used by the MessageContext class.

> In addition it seems that the outgoing MessageContext objects do not
> contain the servlet context. Is this by mistake or by design? If it's
> the latter, how can I access the servlet context?

Its by design- you have to get the operation context from the outgoing
MC and then get the incoming MC from that and look there for the servlet
context and any other "incoming" info.

Sanjiva.


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