You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Alexey <re...@gmail.com> on 2012/08/29 14:10:31 UTC

Re: xpath for header

Sorry, I moved the discussion to another topic. 
You don't quite understand me. My xpath expression is correct. I tested this
xpath expr. with my xml using online xpath selector, it's work normal. The
problem is that xpath must select from my header, but not in the body.

For example that expression work incorrect:
<xpath>in:header('history')/history/p[@id = 'RESTSYBRIGE' and @state !=
'NN']</xpath> 

message not move to queue RESTRUCT.DECLINE

How to make so that the XPath searching in the header?



--
View this message in context: http://camel.465427.n5.nabble.com/xpath-for-header-tp5718190p5718251.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: xpath for header

Posted by Alexey <re...@gmail.com>.
Claus Ibsen-2, cool! Thanks!



--
View this message in context: http://camel.465427.n5.nabble.com/xpath-for-header-tp5718190p5718393.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: xpath for header

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Well Camel usually have a easier way than wring 20 lines of code.

There is a static evaluate/matches method on XPathBuilder you can pass
in your xpath + data, eg

boolean matches = XPathBuilder.xpath("/foo/bar/@xyz").matches(context,
"<foo><bar xyz='cheese'/></foo>")




On Thu, Aug 30, 2012 at 12:04 PM, Alexey <re...@gmail.com> wrote:
> Claus Ibsen-2, thank you very much!
>
> For the time begin, I did that follows:
>
> ---route---
> ...
> <filter>
>     <method ref="histActAggregator" method="xpathExecute(${headers.history},
> '/history/p[@id = &quot;RESTSYBRIGE&quot; and @state != &quot;NN&quot;]')"
> />
>     <to uri="activemq:queue:RESTRUCT.DECLINE"/>
> </filter>
> ...
>
> ---bean 'histActAggregator' ---
> ...
>     public boolean xpathExecute(String xml, String xpathStr) {
>         try {
>             XPathFactory factory = XPathFactory.newInstance();
>             XPath xpath = factory.newXPath();
>             XPathExpression expr = xpath.compile(xpathStr);
>             InputSource inputSource = new InputSource(new
> StringReader(xml));
>             Boolean result = (Boolean) expr.evaluate(inputSource,
> XPathConstants.BOOLEAN);
>
>             return result;
>         } catch (XPathExpressionException ex) {
>             logger.log(Level.SEVERE, "XPathExpressionException; In xml: " +
> xml + "; xpath expression: ", ex);
>             throw new RuntimeException(ex);
>         }
>     }
> ...
>
> May be the solution isn't very elegantly, but it works :)
>
> thanks
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/xpath-for-header-tp5718190p5718365.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: xpath for header

Posted by Alexey <re...@gmail.com>.
Claus Ibsen-2, thank you very much!

For the time begin, I did that follows:

---route---
...
<filter>
    <method ref="histActAggregator" method="xpathExecute(${headers.history},
'/history/p[@id = &quot;RESTSYBRIGE&quot; and @state != &quot;NN&quot;]')"
/>
    <to uri="activemq:queue:RESTRUCT.DECLINE"/>
</filter>
...

---bean 'histActAggregator' ---
...
    public boolean xpathExecute(String xml, String xpathStr) {
        try {
            XPathFactory factory = XPathFactory.newInstance();
            XPath xpath = factory.newXPath();
            XPathExpression expr = xpath.compile(xpathStr);
            InputSource inputSource = new InputSource(new
StringReader(xml));
            Boolean result = (Boolean) expr.evaluate(inputSource,
XPathConstants.BOOLEAN);

            return result;
        } catch (XPathExpressionException ex) {
            logger.log(Level.SEVERE, "XPathExpressionException; In xml: " +
xml + "; xpath expression: ", ex);
            throw new RuntimeException(ex);
        }
    }
...

May be the solution isn't very elegantly, but it works :)

thanks



--
View this message in context: http://camel.465427.n5.nabble.com/xpath-for-header-tp5718190p5718365.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: xpath for header

Posted by Claus Ibsen <cl...@gmail.com>.
On Wed, Aug 29, 2012 at 6:17 PM, Claus Ibsen <cl...@gmail.com> wrote:
> On Wed, Aug 29, 2012 at 2:10 PM, Alexey <re...@gmail.com> wrote:
>> Sorry, I moved the discussion to another topic.
>> You don't quite understand me. My xpath expression is correct. I tested this
>> xpath expr. with my xml using online xpath selector, it's work normal. The
>> problem is that xpath must select from my header, but not in the body.
>>
>> For example that expression work incorrect:
>> <xpath>in:header('history')/history/p[@id = 'RESTSYBRIGE' and @state !=
>> 'NN']</xpath>
>>
>> message not move to queue RESTRUCT.DECLINE
>>
>> How to make so that the XPath searching in the header?
>>
>
> xpath works on message body only.
>

I logged a JIRA to improve this in the future
https://issues.apache.org/jira/browse/CAMEL-5550


>
>>
>>
>> --
>> View this message in context: http://camel.465427.n5.nabble.com/xpath-for-header-tp5718190p5718251.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>
>
> --
> Claus Ibsen
> -----------------
> FuseSource
> Email: cibsen@fusesource.com
> Web: http://fusesource.com
> Twitter: davsclaus, fusenews
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: xpath for header

Posted by Claus Ibsen <cl...@gmail.com>.
On Wed, Aug 29, 2012 at 2:10 PM, Alexey <re...@gmail.com> wrote:
> Sorry, I moved the discussion to another topic.
> You don't quite understand me. My xpath expression is correct. I tested this
> xpath expr. with my xml using online xpath selector, it's work normal. The
> problem is that xpath must select from my header, but not in the body.
>
> For example that expression work incorrect:
> <xpath>in:header('history')/history/p[@id = 'RESTSYBRIGE' and @state !=
> 'NN']</xpath>
>
> message not move to queue RESTRUCT.DECLINE
>
> How to make so that the XPath searching in the header?
>

xpath works on message body only.


>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/xpath-for-header-tp5718190p5718251.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen