You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by l_tsall <le...@yahoo.com> on 2011/04/27 21:38:04 UTC
xpath 2.0 function bean binding camel xpath annotation
Can I combine Xpath 2 functions with camel xpath annotations?
For example
public void updateStatus(@XPath("/order/@customerId") Integer customerId,
@XPath("order/status/text()") String
status
@XPath("upper-case(order/status/text())") String uppercaseStatus
)
Gives a
org.apache.camel.builder.xml.InvalidXPathExpression: Invalid xpath:
upper-case(order/status/text()). Reason:
javax.xml.xpath.XPathExpressionException
Caused by: net.sf.saxon.trans.XPathException: Extension function required
class org.w3c.dom.NodeList; supplied value of class
net.sf.saxon.value.StringValue could not be converted
The following example works as expected
XPathBuilder upperCaseBuilder =
XPathBuilder.xpath("upper-case(/order/status/text())");
String result = upperCaseBuilder.evaluate(context, "<order
customerId=\"123\"><status>in progress</status></order>");
assertEquals("IN PROGRESS", result);
--
View this message in context: http://camel.465427.n5.nabble.com/xpath-2-0-function-bean-binding-camel-xpath-annotation-tp4344611p4344611.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: xpath 2.0 function bean binding camel xpath annotation
Posted by boday <be...@initekconsulting.com>.
l_tsall, haven't had a chance to look at this yet, but I'll see what I can do
(in the next week hopefully)...
l_tsall wrote:
>
> Hi again,
>
> Thanks for resolving this issue.
>
> But which is the proper resultType for the very useful xpath function
> distinct-values which returns a sequence of atomic values?
>
> template.sendBody("<order
> customerId=\"123\"><credit><value>10</value><value>10</value><value>12</value></credit></order>");
>
> I can bind this with
> @XQuery("distinct-values(/order/credit/value)") String distinctValues
> and get distinctValues: 1012
>
> but @XPath(distinct-values(/order/credit/value") NodeList nodes
> generates as expected
> Extension function required class org.w3c.dom.NodeList; supplied value of
> class net.sf.saxon.value.UntypedAtomicValue could not be converted
>
> Would it be possible bind the result in a List<String>
> something like
> @XPath(value="distinct-values(/order/credit/value)",resultType=List.class
> ) List<String> distinctValues ?
>
-----
Ben O'Day
IT Consultant -http://benoday.blogspot.com
--
View this message in context: http://camel.465427.n5.nabble.com/xpath-2-0-function-bean-binding-camel-xpath-annotation-tp4344611p4407263.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: xpath 2.0 function bean binding camel xpath annotation
Posted by l_tsall <le...@yahoo.com>.
Hi again,
Thanks for resolving this issue.
But which is the proper resultType for the very useful xpath function
distinct-values which returns a sequence of atomic values?
template.sendBody("<order
customerId=\"123\"><credit><value>10</value><value>10</value><value>12</value></credit></order>");
I can bind this with
@XQuery("distinct-values(/order/credit/value)") String values
and get distinctValues: 1012
but @XPath(distinct-values(/order/credit/value") NodeList nodes
generates as expected
Extension function required class org.w3c.dom.NodeList; supplied value of
class net.sf.saxon.value.UntypedAtomicValue could not be converted
Would it be possible bind the result in a List<String>
something like
@XPath(value="distinct-values(/order/credit/value)",resultType=List.class )
List<String> distinctValues ?
--
View this message in context: http://camel.465427.n5.nabble.com/xpath-2-0-function-bean-binding-camel-xpath-annotation-tp4344611p4393304.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: xpath 2.0 function bean binding camel xpath annotation
Posted by "ben.oday" <be...@initekconsulting.com>.
added https://issues.apache.org/jira/browse/CAMEL-3911 to explore this
further
Claus Ibsen-2 wrote:
>
> Ah we should maybe try in the @XPath situation to check the parameter
> type, and if possible configure the XPathBuilder to use that same
> type. Then it knows when evaluating the xpath expression the result is
> to a String.
>
> In case its not possible to do so then we rely on the camel type
> converter to convert the result afterwards.
> But the XPathBuilder has X number of types it support out of the box such
> as
> - numbers
> - string
> - boolean
> - dom
> - etc.
>
-----
Ben O'Day
IT Consultant -http://benoday.blogspot.com
--
View this message in context: http://camel.465427.n5.nabble.com/xpath-2-0-function-bean-binding-camel-xpath-annotation-tp4344611p4346846.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: xpath 2.0 function bean binding camel xpath annotation
Posted by Claus Ibsen <cl...@gmail.com>.
On Thu, Apr 28, 2011 at 9:36 AM, l_tsall <le...@yahoo.com> wrote:
> That's exactly what I needed. Thanks :)
>
> ben.oday wrote:
>>
>> The issue is that @XPath defaults the resultType to NodeList.class. But I
>> think you need to use String.class instead...
>>
>> So, try setting the resultType explicitly, like this...
>>
>> public void updateStatus(@XPath(value ="/order/@customerId", resultType =
>> String.class) Integer customerId,
>> @XPath(value ="order/status/text()",
>> resultType = String.class) String status
>> @XPath(value=
>> "upper-case(order/status/text())", resultType = String.class) String
>> uppercaseStatus
>> )
>>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/xpath-2-0-function-bean-binding-camel-xpath-annotation-tp4344611p4345927.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
Ah we should maybe try in the @XPath situation to check the parameter
type, and if possible configure the XPathBuilder to use that same
type. Then it knows when evaluating the xpath expression the result is
to a String.
In case its not possible to do so then we rely on the camel type
converter to convert the result afterwards.
But the XPathBuilder has X number of types it support out of the box such as
- numbers
- string
- boolean
- dom
- etc.
--
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
CamelOne 2011: http://fusesource.com/camelone2011/
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/
Re: xpath 2.0 function bean binding camel xpath annotation
Posted by l_tsall <le...@yahoo.com>.
That's exactly what I needed. Thanks :)
ben.oday wrote:
>
> The issue is that @XPath defaults the resultType to NodeList.class. But I
> think you need to use String.class instead...
>
> So, try setting the resultType explicitly, like this...
>
> public void updateStatus(@XPath(value ="/order/@customerId", resultType =
> String.class) Integer customerId,
> @XPath(value ="order/status/text()",
> resultType = String.class) String status
> @XPath(value=
> "upper-case(order/status/text())", resultType = String.class) String
> uppercaseStatus
> )
>
--
View this message in context: http://camel.465427.n5.nabble.com/xpath-2-0-function-bean-binding-camel-xpath-annotation-tp4344611p4345927.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: xpath 2.0 function bean binding camel xpath annotation
Posted by "ben.oday" <be...@initekconsulting.com>.
The issue is that @XPath defaults the resultType to NodeList.class. But I
think you need to use String.class instead...
So, try setting the resultType explicitly, like this...
public void updateStatus(@XPath("/order/@customerId") Integer customerId,
@XPath("order/status/text()") String
status
@XPath(value =
"upper-case(order/status/text())", resultType = String.class) String
uppercaseStatus
)
l_tsall wrote:
>
> Can I combine Xpath 2 functions with camel xpath annotations?
>
> For example
>
> public void updateStatus(@XPath("/order/@customerId") Integer customerId,
> @XPath("order/status/text()") String
> status
>
> @XPath("upper-case(order/status/text())") String uppercaseStatus
> )
> Gives a
> org.apache.camel.builder.xml.InvalidXPathExpression: Invalid xpath:
> upper-case(order/status/text()). Reason:
> javax.xml.xpath.XPathExpressionException
>
> Caused by: net.sf.saxon.trans.XPathException: Extension function required
> class org.w3c.dom.NodeList; supplied value of class
> net.sf.saxon.value.StringValue could not be converted
>
> The following example works as expected
>
> XPathBuilder upperCaseBuilder =
> XPathBuilder.xpath("upper-case(/order/status/text())");
> String result = upperCaseBuilder.evaluate(context, "<order
> customerId=\"123\"><status>in progress</status></order>");
> assertEquals("IN PROGRESS", result);
>
-----
Ben O'Day
IT Consultant -http://benoday.blogspot.com
--
View this message in context: http://camel.465427.n5.nabble.com/xpath-2-0-function-bean-binding-camel-xpath-annotation-tp4344611p4345146.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: xpath 2.0 function bean binding camel xpath annotation
Posted by "ben.oday" <be...@initekconsulting.com>.
I get the same error when running the API directly (from
2.8-SNAPSHOT)...either way, I'll look into it a bit...
XPathBuilder upperCaseBuilder =
XPathBuilder.xpath("upper-case(/order/status/text())");
String result = upperCaseBuilder.evaluate(context, "<order
customerId=\"123\"><status>in progress</status></order>");
org.apache.camel.builder.xml.InvalidXPathExpression: Invalid xpath:
upper-case(/order/status/text()). Reason:
javax.xml.xpath.XPathExpressionException
at
org.apache.camel.builder.xml.XPathBuilder.evaluateAs(XPathBuilder.java:631)
...
l_tsall wrote:
>
> Can I combine Xpath 2 functions with camel xpath annotations?
>
> For example
>
> public void updateStatus(@XPath("/order/@customerId") Integer customerId,
> @XPath("order/status/text()") String
> status
>
> @XPath("upper-case(order/status/text())") String uppercaseStatus
> )
> Gives a
> org.apache.camel.builder.xml.InvalidXPathExpression: Invalid xpath:
> upper-case(order/status/text()). Reason:
> javax.xml.xpath.XPathExpressionException
>
> Caused by: net.sf.saxon.trans.XPathException: Extension function required
> class org.w3c.dom.NodeList; supplied value of class
> net.sf.saxon.value.StringValue could not be converted
>
> The following example works as expected
>
> XPathBuilder upperCaseBuilder =
> XPathBuilder.xpath("upper-case(/order/status/text())");
> String result = upperCaseBuilder.evaluate(context, "<order
> customerId=\"123\"><status>in progress</status></order>");
> assertEquals("IN PROGRESS", result);
>
-----
Ben O'Day
IT Consultant -http://benoday.blogspot.com
--
View this message in context: http://camel.465427.n5.nabble.com/xpath-2-0-function-bean-binding-camel-xpath-annotation-tp4344611p4344745.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: xpath 2.0 function bean binding camel xpath annotation
Posted by Claus Ibsen <cl...@gmail.com>.
On Wed, Apr 27, 2011 at 10:53 PM, l_tsall <le...@yahoo.com> wrote:
> I am using saxon by Setting a custom XPathFactory using System Property as
> described in http://camel.apache.org/xpath.html
>
> System.setProperty(XPathFactory.DEFAULT_PROPERTY_NAME + ":" +
> "http://saxon.sf.net/jaxp/xpath/om", "net.sf.saxon.xpath.XPathFactoryImpl");
>
> this only works with XPathBuilder.xpath("upper-case(/order/status/text())");
>
> Is there something else needed to configure saxon as the xpath engine for a
> xpath parameter binding annotation?
>
They ought to become the same as @XPath will use XPathBuilder as well.
Can you create an unit test and a JIRA ticket? Then we can take a look at it.
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/xpath-2-0-function-bean-binding-camel-xpath-annotation-tp4344611p4344815.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
--
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
CamelOne 2011: http://fusesource.com/camelone2011/
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/
Re: xpath 2.0 function bean binding camel xpath annotation
Posted by l_tsall <le...@yahoo.com>.
I am using saxon by Setting a custom XPathFactory using System Property as
described in http://camel.apache.org/xpath.html
System.setProperty(XPathFactory.DEFAULT_PROPERTY_NAME + ":" +
"http://saxon.sf.net/jaxp/xpath/om", "net.sf.saxon.xpath.XPathFactoryImpl");
this only works with XPathBuilder.xpath("upper-case(/order/status/text())");
Is there something else needed to configure saxon as the xpath engine for a
xpath parameter binding annotation?
--
View this message in context: http://camel.465427.n5.nabble.com/xpath-2-0-function-bean-binding-camel-xpath-annotation-tp4344611p4344815.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: xpath 2.0 function bean binding camel xpath annotation
Posted by Claus Ibsen <cl...@gmail.com>.
I think you need to use Saxon as XPath engine as AFAIK the XPath
engine from the JDK only supports XPath 1.x functions.
On Wed, Apr 27, 2011 at 9:38 PM, l_tsall <le...@yahoo.com> wrote:
> Can I combine Xpath 2 functions with camel xpath annotations?
>
> For example
>
> public void updateStatus(@XPath("/order/@customerId") Integer customerId,
> @XPath("order/status/text()") String
> status
>
> @XPath("upper-case(order/status/text())") String uppercaseStatus
> )
> Gives a
> org.apache.camel.builder.xml.InvalidXPathExpression: Invalid xpath:
> upper-case(order/status/text()). Reason:
> javax.xml.xpath.XPathExpressionException
>
> Caused by: net.sf.saxon.trans.XPathException: Extension function required
> class org.w3c.dom.NodeList; supplied value of class
> net.sf.saxon.value.StringValue could not be converted
>
> The following example works as expected
>
> XPathBuilder upperCaseBuilder =
> XPathBuilder.xpath("upper-case(/order/status/text())");
> String result = upperCaseBuilder.evaluate(context, "<order
> customerId=\"123\"><status>in progress</status></order>");
> assertEquals("IN PROGRESS", result);
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/xpath-2-0-function-bean-binding-camel-xpath-annotation-tp4344611p4344611.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
--
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
CamelOne 2011: http://fusesource.com/camelone2011/
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/