On Mon, Dec 14, 2009 at 2:03 PM, Martin Gilday <[email protected]> wrote:
> Hi,
>
> Yes that is how we thought it should be. However we have come across
> the following issue. The first route works as desired. The second and
> third do not compile.
>
> // Works
> from("direct:test").setHeader("foo")
> .xpath("/bar")
> .to("cheese");
>
> //The method to(String) is undefined for the type Object
> from("direct:test")
> .to("log:org.example.Incoming?level=INFO")
> .setHeader("foo")
> .xpath("/bar")
> .to("cheese");
>
> //The method to(String) is undefined for the type Object
> from("direct:test")
> .beanRef("myBean", "myMethod")
> .setHeader("foo")
> .xpath("/bar")
> .to("cheese");
>
> Is this a bug or are we doing something wrong here?
>
The Java language is maxed out with the builder pattern and generics.
What you actually do is to kinda call a sub method (the xpath) and
then want to go back to the scope used before (eg from setHeader) but
that is not always possible with regular Java.
That is why I prefer to pass in the xpath as a parameter to the setHeader method
.setHeader("foo", xpath("/bar"))
You then need to use static import
import static org.apache.camel.builder.xml.XPathBuilder.xpath;
> Could you elaborate on what you meant by "You can just set the file name
> based on xpath and with some xpath concat magic you can assemble it in
> one expression."
>
No :)
That person wanted to set the filename based on parts of xpath.
So if you want to extract from xpath and add .xml as file extension,
and/or maybe have a fixed prefix for the file name, you can do
that with some xpath concat magic. I am no xpath lover and cant
remember the syntax for using those xpath functions.
> Martin
>
> ----- Original message -----
> From: "Claus Ibsen" <[email protected]>
> To: [email protected]
> Date: Mon, 14 Dec 2009 13:03:16 +0100
> Subject: Re: Filename based on XPath result
>
> On Mon, Dec 14, 2009 at 11:55 AM, Martin Gilday <[email protected]>
> wrote:
>> Hi,
>>
>> I have a StringMessage which contains and XML body. I would like to use
>> a unique part of the body as the filename in conjunction with the file
>> component. Is it possible to consume from JMS and send to file with the
>> filename the result of an XPath match?
>>
>
> Yeah this question came up last week
> http://old.nabble.com/File-Component%3A-File-name-from-body-data-ts26708582.html
>
>
>> Thanks,
>> Martin.
>>
>
>
>
> --
> Claus Ibsen
> Apache Camel Committer
>
> Author of Camel in Action: http://www.manning.com/ibsen/
> Open Source Integration: http://fusesource.com
> Blog: http://davsclaus.blogspot.com/
> Twitter: http://twitter.com/davsclaus
>
--
Claus Ibsen
Apache Camel Committer
Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus