You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by heinrichheine <ma...@vitaphone.de> on 2011/08/23 11:43:35 UTC

setHeader using xpath returns Object?

Hi,

i'm building my first route using the java DSL and i'm running in a small
trouble setting a header field.

I had a spring route looking and working like this:

<camel:setHeader headerName="incomingDate">
         <camel:xpath
resultType="java.lang.String">//incoming:Value[1]/@date</camel:xpath>
</camel:setHeader>

I want to build exactly the same in the java dsl:

 .setHeader("incomingDate")
 .xpath("//incoming:Value[1]/@date", String.class, ns)

The problem is, that xpath returns an Object, so i cannot continue
configuring my route from this point.
I want to put a choice as next step in the route, but thats not working
because xpath returns an Object.
And also i get a compiler warning due to type safety.
Does anyone have an idea for this?

Thanks in advance

 martin



--
View this message in context: http://camel.465427.n5.nabble.com/setHeader-using-xpath-returns-Object-tp4726154p4726154.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: setHeader using xpath returns Object?

Posted by Willem Jiang <wi...@gmail.com>.
Hi,

You may consider to use the XPathBuilder to setup the expression for the 
setHeader().


On 8/23/11 6:06 PM, heinrichheine wrote:
> Your totally right,
>
> but if i do it, i get:
> "The method xpath(String) in the type BuilderSupport is not applicable for
> the arguments (String, Class<String>, Namespaces)"
>
> compile error.
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/setHeader-using-xpath-returns-Object-tp4726154p4726222.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>


-- 
Willem
----------------------------------
FuseSource
Web: http://www.fusesource.com
Blog:    http://willemjiang.blogspot.com (English)
          http://jnn.javaeye.com (Chinese)
Twitter: willemjiang
Weibo: willemjiang

Re: setHeader using xpath returns Object?

Posted by Claus Ibsen <cl...@gmail.com>.
On Wed, Aug 24, 2011 at 11:10 AM, heinrichheine
<ma...@vitaphone.de> wrote:
> Well, the XPathBuilder finally did it.
> XPathBuilder.xpath("//expr", String.class).namespaces(ns)
> is working.
>
> I wonder what is different to your setup that my xpath method does not have
> parameters for namespaces.
>
> My route builder extends org.apache.camel.builder.RouteBuilder.
> The xpath method availlable in the setHeader scope is coming from
> org.apache.camel.builder.BuilderSupport
> and there is just an xpath(String value) method.
>

That works fine as well as you can set the options afterwards such as

                from("direct:start")
                        .choice()
                        .when(xpath("/order/@type =
'book'").resultType(String.class).namespace("foo",
"http://www.foo.com")).to("direct:book")
                        .otherwise().to("direct:other")
                        .end();



> --
> View this message in context: http://camel.465427.n5.nabble.com/setHeader-using-xpath-returns-Object-tp4726154p4729783.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.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: setHeader using xpath returns Object?

Posted by heinrichheine <ma...@vitaphone.de>.
Well, the XPathBuilder finally did it.
XPathBuilder.xpath("//expr", String.class).namespaces(ns)
is working.

I wonder what is different to your setup that my xpath method does not have
parameters for namespaces.

My route builder extends org.apache.camel.builder.RouteBuilder.
The xpath method availlable in the setHeader scope is coming from
org.apache.camel.builder.BuilderSupport
and there is just an xpath(String value) method. 

--
View this message in context: http://camel.465427.n5.nabble.com/setHeader-using-xpath-returns-Object-tp4726154p4729783.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: setHeader using xpath returns Object?

Posted by Claus Ibsen <cl...@gmail.com>.
On Tue, Aug 23, 2011 at 12:06 PM, heinrichheine
<ma...@vitaphone.de> wrote:
> Your totally right,
>
> but if i do it, i get:
> "The method xpath(String) in the type BuilderSupport is not applicable for
> the arguments (String, Class<String>, Namespaces)"
>

The xpath should have methods to set the namespace, result type etc.

So something along the lines of:
.setHeader("xxx", xpath("xxx").resultType(String.class).namespace(ns))



> compile error.
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/setHeader-using-xpath-returns-Object-tp4726154p4726222.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.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: setHeader using xpath returns Object?

Posted by heinrichheine <ma...@vitaphone.de>.
Your totally right,

but if i do it, i get:
"The method xpath(String) in the type BuilderSupport is not applicable for
the arguments (String, Class<String>, Namespaces)"

compile error.

--
View this message in context: http://camel.465427.n5.nabble.com/setHeader-using-xpath-returns-Object-tp4726154p4726222.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: setHeader using xpath returns Object?

Posted by Freeman Fang <fr...@gmail.com>.
Hi,

It should be

setHeader("incomingDate", xpath("//incoming:Value[1]/@date",  
String.class, ns))

but not
setHeader("incomingDate")
.xpath("//incoming:Value[1]/@date", String.class, ns)


Freeman
On 2011-8-23, at 下午5:43, heinrichheine wrote:

> Hi,
>
> i'm building my first route using the java DSL and i'm running in a  
> small
> trouble setting a header field.
>
> I had a spring route looking and working like this:
>
> <camel:setHeader headerName="incomingDate">
>         <camel:xpath
> resultType="java.lang.String">//incoming:Value[1]/@date</camel:xpath>
> </camel:setHeader>
>
> I want to build exactly the same in the java dsl:
>
> .setHeader("incomingDate")
> .xpath("//incoming:Value[1]/@date", String.class, ns)
>
> The problem is, that xpath returns an Object, so i cannot continue
> configuring my route from this point.
> I want to put a choice as next step in the route, but thats not  
> working
> because xpath returns an Object.
> And also i get a compiler warning due to type safety.
> Does anyone have an idea for this?
>
> Thanks in advance
>
> martin
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/setHeader-using-xpath-returns-Object-tp4726154p4726154.html
> Sent from the Camel - Users mailing list archive at Nabble.com.

---------------------------------------------
Freeman Fang

FuseSource
Email:ffang@fusesource.com
Web: fusesource.com
Twitter: freemanfang
Blog: http://freemanfang.blogspot.com










Re: setHeader using xpath returns Object?

Posted by heinrichheine <ma...@vitaphone.de>.
Addition: Camel 2.5.0

--
View this message in context: http://camel.465427.n5.nabble.com/setHeader-using-xpath-returns-Object-tp4726154p4726178.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: setHeader using xpath returns Object?

Posted by Claus Ibsen <cl...@gmail.com>.
On Tue, Aug 23, 2011 at 11:43 AM, heinrichheine
<ma...@vitaphone.de> wrote:
> Hi,
>
> i'm building my first route using the java DSL and i'm running in a small
> trouble setting a header field.
>
> I had a spring route looking and working like this:
>
> <camel:setHeader headerName="incomingDate">
>         <camel:xpath
> resultType="java.lang.String">//incoming:Value[1]/@date</camel:xpath>
> </camel:setHeader>
>
> I want to build exactly the same in the java dsl:
>
>  .setHeader("incomingDate")
>  .xpath("//incoming:Value[1]/@date", String.class, ns)
>
> The problem is, that xpath returns an Object, so i cannot continue
> configuring my route from this point.

But the xpath inside as a parameter to .setHeader

  .setHeader("incomingDate", xpath("//incoming:Value[1]/@date",
String.class, ns))



> I want to put a choice as next step in the route, but thats not working
> because xpath returns an Object.
> And also i get a compiler warning due to type safety.
> Does anyone have an idea for this?
>
> Thanks in advance
>
>  martin
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/setHeader-using-xpath-returns-Object-tp4726154p4726154.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.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/