FAQ
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?

Thanks,
Martin.

Search Discussions

  • Claus Ibsen at Dec 14, 2009 at 12:04 pm

    On Mon, Dec 14, 2009 at 11:55 AM, Martin Gilday 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
  • Martin Gilday at Dec 14, 2009 at 1:04 pm
    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?

    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."

    Martin

    ----- Original message -----
    From: "Claus Ibsen" <claus.ibsen@gmail.com>
    To: users@camel.apache.org
    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 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 at Dec 14, 2009 at 3:12 pm

    On Mon, Dec 14, 2009 at 2:03 PM, Martin Gilday 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" <claus.ibsen@gmail.com>
    To: users@camel.apache.org
    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 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
  • Martin Gilday at Dec 15, 2009 at 9:47 am
    Thanks Claus, that works well.


    ----- Original message -----
    From: "Claus Ibsen" <claus.ibsen@gmail.com>
    To: users@camel.apache.org
    Date: Mon, 14 Dec 2009 16:11:25 +0100
    Subject: Re: Filename based on XPath result
    On Mon, Dec 14, 2009 at 2:03 PM, Martin Gilday 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" <claus.ibsen@gmail.com>
    To: users@camel.apache.org
    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 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
  • Ankelee at Mar 22, 2010 at 3:15 pm
    Hi

    I'm trying to do this:

    from("direct:controlMessageToCbr")
    .setHeader("envelopeId", xpath("/something/@Id")).to.....

    But the header just get set to the XPathBuilder object.

    Wouldn't something like the .evaluate() method needed to be used for this
    (when using the XPathBuilder in Java)?

    String address =
    XPathBuilder.xpath("/somthing/@Id").evaluate(exchange.getContext(),
    exchange.getIn().getBody(), String.class);

    Maybe there's a better soulution to retrieve the id from the xml? I just
    want to get hold of it somehow.
    --
    View this message in context: http://old.nabble.com/Filename-based-on-XPath-result-tp26775964p27987793.html
    Sent from the Camel - Users mailing list archive at Nabble.com.
  • Ankelee at Mar 22, 2010 at 4:02 pm
    Nevermind this. I was trying to read the header in a processor and forgot
    that Camel has a type converter ;)



    ankelee wrote:
    Hi

    I'm trying to do this:

    from("direct:controlMessageToCbr")
    .setHeader("envelopeId", xpath("/something/@Id")).to.....

    But the header get set to a net.sf.saxon.dom.DOMNodeList object.

    Wouldn't something like the .evaluate() method needed to be used for this
    (when using the XPathBuilder in Java)?

    String address =
    XPathBuilder.xpath("/somthing/@Id").evaluate(exchange.getContext(),
    exchange.getIn().getBody(), String.class);

    How can I refer to the context inside the route?

    Maybe there's a better soulution to retrieve the id from the xml? I just
    want to get hold of it somehow.
    --
    View this message in context: http://old.nabble.com/Filename-based-on-XPath-result-tp26775964p27988470.html
    Sent from the Camel - Users mailing list archive at Nabble.com.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupusers @
categoriescamel
postedDec 14, '09 at 10:55a
activeMar 22, '10 at 4:02p
posts7
users3
websitecamel.apache.org

People

Translate

site design / logo © 2022 Grokbase