You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@servicemix.apache.org by Andrew Skiba <an...@bee.tv> on 2008/05/18 15:27:24 UTC

patch for review

Existing JAXPXPathExpression evaluates only to strings. This subclass  
allows to use XStream to evaluate a part of a message into an object  
of any type. For example if a message carries XML like

<message>
    <params>
        <map>
            <entry>
                <key>key1</key>
                <value>value1</value>
            </...>
and xpath=/message/params/map

then this JAXPXPathXStreamExpression evaluates it into java.util.Map

Please tell me what you think.
Andrew.


Re: patch for review

Posted by Andrew Skiba <sk...@gmail.com>.
Please review the revised patch, unit test patch is attached as well: https://issues.apache.org/activemq/browse/SM-1358

On May 19, 2008, at 11:25, Guillaume Nodet wrote:

> Btw, if you have some test case, that would be awesome!
>
> On Mon, May 19, 2008 at 10:25 AM, Guillaume Nodet <gn...@gmail.com>  
> wrote:
>> Looks like a good use case, thx a lot for sharing this.
>> Could you raise a JIRA and attach your patch ?
>>
>> On Mon, May 19, 2008 at 10:22 AM, Andrew Skiba <sk...@gmail.com>  
>> wrote:
>>> Hello Guillaume,
>>>
>>> First of all, I really meant maps, not only for an example.
>>> ConstantExpression is already handling maps correctly, I tried. I  
>>> guess
>>> PropertyExpression will handle any complex type, too. So only XPath
>>> expressions are unable to deal with maps.
>>>
>>> It's needed to use maps instead of primitives if you implement a  
>>> Command
>>> Pattern in the endpoint. For example, database named query has a  
>>> name and a
>>> list of named parameters with their values. It may be implemented  
>>> with a
>>> method like query(String queryName, Map<String, Object> params).  
>>> Instead of
>>> hard coding XPath of params in the NormalizedMessage, it would be  
>>> useful if
>>> you could configure where to find it, like this:
>>>
>>>                       <jpa:jpa-query service="test:jpa"
>>> endpoint="updateQuery">
>>>                               <queryName>
>>>                                   <bean
>>> class="org.apache.servicemix.expression.  
>>> JAXPXPathXStreamExpression">
>>>                                       <constructor-arg
>>> value="/query/name"/>
>>>                                   </bean>
>>>                               </queryName>
>>>                               <params>
>>>                                   <bean
>>> class="org.apache.servicemix.expression.JAXPXPathXStreamExpression">
>>>                                       <constructor-arg
>>> value="/query/params/map"/>
>>>                                   </bean>
>>>                               </params>
>>>                           </jpa:jpa-query>
>>>
>>> Then it can handle messages with content like
>>>
>>>       <query>
>>>               <name>updateVideoTitle</name>
>>>               <params>
>>>                       <map>
>>>                               <entry>
>>>                                       <key>id</key>
>>>                                       <value>10</value>
>>>                               </entry><entry>
>>>                                       <key>title</key>
>>>                                       <value>Office space</value>
>>>                               </entry>
>>>                       </map>
>>>               </params>
>>>       </query>
>>>
>>> What do you think?
>>> Andrew.
>>>
>>> On May 19, 2008, at 10:15, Guillaume Nodet wrote:
>>>
>>>> How would one use such an expression ? Usually, predicates use  
>>>> simple
>>>> types
>>>> such as boolean or string, not complex objects as maps.  I know  
>>>> map is
>>>> just
>>>> an example, but other simple types are already handled by  
>>>> subtypes of the
>>>> JAXPXpathExpression.  Just wondering...
>>>>
>>>> On Sun, May 18, 2008 at 3:27 PM, Andrew Skiba <an...@bee.tv>  
>>>> wrote:
>>>>>
>>>>> Existing JAXPXPathExpression evaluates only to strings. This  
>>>>> subclass
>>>>> allows
>>>>> to use XStream to evaluate a part of a message into an object of  
>>>>> any
>>>>> type.
>>>>> For example if a message carries XML like <message> <params> <map>
>>>>> <entry>
>>>>> <key>key1</key> <value>value1</value> </...> and
>>>>> xpath=/message/params/map
>>>>> then this JAXPXPathXStreamExpression evaluates it into  
>>>>> java.util.Map
>>>>> Please tell me what you think.
>>>>> Andrew.
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Cheers,
>>>> Guillaume Nodet
>>>> ------------------------
>>>> Blog: http://gnodet.blogspot.com/
>>>
>>>
>>
>>
>>
>> --
>> Cheers,
>> Guillaume Nodet
>> ------------------------
>> Blog: http://gnodet.blogspot.com/
>>
>
>
>
> -- 
> Cheers,
> Guillaume Nodet
> ------------------------
> Blog: http://gnodet.blogspot.com/


Re: patch for review

Posted by Guillaume Nodet <gn...@gmail.com>.
Looks like a good use case, thx a lot for sharing this.
Could you raise a JIRA and attach your patch ?

On Mon, May 19, 2008 at 10:22 AM, Andrew Skiba <sk...@gmail.com> wrote:
> Hello Guillaume,
>
> First of all, I really meant maps, not only for an example.
> ConstantExpression is already handling maps correctly, I tried. I guess
> PropertyExpression will handle any complex type, too. So only XPath
> expressions are unable to deal with maps.
>
> It's needed to use maps instead of primitives if you implement a Command
> Pattern in the endpoint. For example, database named query has a name and a
> list of named parameters with their values. It may be implemented with a
> method like query(String queryName, Map<String, Object> params). Instead of
> hard coding XPath of params in the NormalizedMessage, it would be useful if
> you could configure where to find it, like this:
>
>                        <jpa:jpa-query service="test:jpa"
> endpoint="updateQuery">
>                                <queryName>
>                                    <bean
> class="org.apache.servicemix.expression. JAXPXPathXStreamExpression">
>                                        <constructor-arg
> value="/query/name"/>
>                                    </bean>
>                                </queryName>
>                                <params>
>                                    <bean
> class="org.apache.servicemix.expression.JAXPXPathXStreamExpression">
>                                        <constructor-arg
> value="/query/params/map"/>
>                                    </bean>
>                                </params>
>                            </jpa:jpa-query>
>
> Then it can handle messages with content like
>
>        <query>
>                <name>updateVideoTitle</name>
>                <params>
>                        <map>
>                                <entry>
>                                        <key>id</key>
>                                        <value>10</value>
>                                </entry><entry>
>                                        <key>title</key>
>                                        <value>Office space</value>
>                                </entry>
>                        </map>
>                </params>
>        </query>
>
> What do you think?
> Andrew.
>
> On May 19, 2008, at 10:15, Guillaume Nodet wrote:
>
>> How would one use such an expression ? Usually, predicates use simple
>> types
>> such as boolean or string, not complex objects as maps.  I know map is
>> just
>> an example, but other simple types are already handled by subtypes of the
>> JAXPXpathExpression.  Just wondering...
>>
>> On Sun, May 18, 2008 at 3:27 PM, Andrew Skiba <an...@bee.tv> wrote:
>>>
>>> Existing JAXPXPathExpression evaluates only to strings. This subclass
>>> allows
>>> to use XStream to evaluate a part of a message into an object of any
>>> type.
>>> For example if a message carries XML like <message> <params> <map>
>>> <entry>
>>> <key>key1</key> <value>value1</value> </...> and
>>> xpath=/message/params/map
>>> then this JAXPXPathXStreamExpression evaluates it into java.util.Map
>>> Please tell me what you think.
>>> Andrew.
>>>
>>>
>>>
>>
>>
>>
>> --
>> Cheers,
>> Guillaume Nodet
>> ------------------------
>> Blog: http://gnodet.blogspot.com/
>
>



-- 
Cheers,
Guillaume Nodet
------------------------
Blog: http://gnodet.blogspot.com/

Re: patch for review

Posted by Andrew Skiba <sk...@gmail.com>.
Hello Guillaume,

First of all, I really meant maps, not only for an example.  
ConstantExpression is already handling maps correctly, I tried. I  
guess PropertyExpression will handle any complex type, too. So only  
XPath expressions are unable to deal with maps.

It's needed to use maps instead of primitives if you implement a  
Command Pattern in the endpoint. For example, database named query has  
a name and a list of named parameters with their values. It may be  
implemented with a method like query(String queryName, Map<String,  
Object> params). Instead of hard coding XPath of params in the  
NormalizedMessage, it would be useful if you could configure where to  
find it, like this:

			<jpa:jpa-query service="test:jpa" endpoint="updateQuery">
                                 <queryName>
                                     <bean  
class="org.apache.servicemix.expression. JAXPXPathXStreamExpression">
                                         <constructor-arg value="/ 
query/name"/>
                                     </bean>
                                 </queryName>
                                 <params>
                                     <bean  
class="org.apache.servicemix.expression.JAXPXPathXStreamExpression">
                                         <constructor-arg value="/ 
query/params/map"/>
                                     </bean>
                                 </params>
                             </jpa:jpa-query>

Then it can handle messages with content like

	<query>
		<name>updateVideoTitle</name>
		<params>
			<map>
				<entry>
					<key>id</key>
					<value>10</value>
				</entry><entry>
					<key>title</key>
					<value>Office space</value>
				</entry>
			</map>
		</params>
	</query>
	
What do you think?
Andrew.

On May 19, 2008, at 10:15, Guillaume Nodet wrote:

> How would one use such an expression ? Usually, predicates use  
> simple types
> such as boolean or string, not complex objects as maps.  I know map  
> is just
> an example, but other simple types are already handled by subtypes  
> of the
> JAXPXpathExpression.  Just wondering...
>
> On Sun, May 18, 2008 at 3:27 PM, Andrew Skiba <an...@bee.tv> wrote:
>> Existing JAXPXPathExpression evaluates only to strings. This  
>> subclass allows
>> to use XStream to evaluate a part of a message into an object of  
>> any type.
>> For example if a message carries XML like <message> <params> <map>  
>> <entry>
>> <key>key1</key> <value>value1</value> </...> and xpath=/message/ 
>> params/map
>> then this JAXPXPathXStreamExpression evaluates it into java.util.Map
>> Please tell me what you think.
>> Andrew.
>>
>>
>>
>
>
>
> -- 
> Cheers,
> Guillaume Nodet
> ------------------------
> Blog: http://gnodet.blogspot.com/


Re: patch for review

Posted by Guillaume Nodet <gn...@gmail.com>.
How would one use such an expression ? Usually, predicates use simple types
such as boolean or string, not complex objects as maps.  I know map is just
an example, but other simple types are already handled by subtypes of the
JAXPXpathExpression.  Just wondering...

On Sun, May 18, 2008 at 3:27 PM, Andrew Skiba <an...@bee.tv> wrote:
> Existing JAXPXPathExpression evaluates only to strings. This subclass allows
> to use XStream to evaluate a part of a message into an object of any type.
> For example if a message carries XML like <message> <params> <map> <entry>
> <key>key1</key> <value>value1</value> </...> and xpath=/message/params/map
> then this JAXPXPathXStreamExpression evaluates it into java.util.Map
> Please tell me what you think.
> Andrew.
>
>
>



-- 
Cheers,
Guillaume Nodet
------------------------
Blog: http://gnodet.blogspot.com/