You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Dragisa Krsmanovic <dk...@plos.org> on 2009/10/12 22:39:40 UTC

Calling setHeader() after to()

I am trying to do something like:

 from("activemq:plos.pmc")
    .to("rnc:pmc-message.rnc")
    .setHeader(DOI).xpath("/ambraMessage/doi/text()", String.class)
    .setHeader(Exchange.FILE_NAME).xpath("/ambraMessage/archive/text()",String.class)
  ...

But it doesn't allow me to add any setHeader methods
after .to("rnc:...") I want to validate a message before I try to
extract Xpath and I have an onException handler to catch
ValidationException.

What am I doing wrong ? 


-- 
Dragisa Krsmanovic
Java Developer
Public Library of Science 
http://www.plos.org


Re: Calling setHeader() after to()

Posted by Dragisa Krsmanovic <dk...@plos.org>.
On Thu, 2009-10-15 at 08:37 +0200, Claus Ibsen wrote:
> On Wed, Oct 14, 2009 at 11:07 PM, Dragisa Krsmanovic
> <dk...@plos.org> wrote:
> > On Wed, 2009-10-14 at 05:58 +0200, Claus Ibsen wrote:
> >> Ah the reason is that the javac and generics is limited in terms of DSL wise.
> >>
> >> What you need to do is to pass in the xpath as a 2nd parameter to setHeader.
> >>
> >> This
> >>    .setHeader(DOI).xpath("/ambraMessage/doi/text()", String.class)
> >>
> >> Should be
> >>    .setHeader(DOI, xpath("/ambraMessage/doi/text()", String.class))
> >>
> >
> > I don't seem to have luck with this. This doesn't compile:
> >
> > from("activemq:plos.pmc")
> >  .setHeader(DOI, xpath("/ambraMessage/doi/text()", String.class))
> >  .to("mock:end");
> >
> > xpath() is not defined in RouteBuilder.
> 
> Dont your IDE have good help? IDEA pop up with a list of suggestions :)
> 
> You need to static import from XPathBuilder:
> 
> import static org.apache.camel.builder.xml.XPathBuilder.xpath;

Yes, Idea pops up suggestion now that I've included it. ;)

Ahem... It's a little bit hard to navigate documentation. Where would
one find details about this ?

-- 
Dragisa Krsmanovic
Java Developer
Public Library of Science 
http://www.plos.org


Re: Calling setHeader() after to()

Posted by Claus Ibsen <cl...@gmail.com>.
On Wed, Oct 14, 2009 at 11:07 PM, Dragisa Krsmanovic
<dk...@plos.org> wrote:
> On Wed, 2009-10-14 at 05:58 +0200, Claus Ibsen wrote:
>> Ah the reason is that the javac and generics is limited in terms of DSL wise.
>>
>> What you need to do is to pass in the xpath as a 2nd parameter to setHeader.
>>
>> This
>>    .setHeader(DOI).xpath("/ambraMessage/doi/text()", String.class)
>>
>> Should be
>>    .setHeader(DOI, xpath("/ambraMessage/doi/text()", String.class))
>>
>
> I don't seem to have luck with this. This doesn't compile:
>
> from("activemq:plos.pmc")
>  .setHeader(DOI, xpath("/ambraMessage/doi/text()", String.class))
>  .to("mock:end");
>
> xpath() is not defined in RouteBuilder.

Dont your IDE have good help? IDEA pop up with a list of suggestions :)

You need to static import from XPathBuilder:

import static org.apache.camel.builder.xml.XPathBuilder.xpath;

>
> --
> Dragisa Krsmanovic
> Java Developer
> Public Library of Science
> http://www.plos.org
>
>



-- 
Claus Ibsen
Apache Camel Committer

Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Re: Calling setHeader() after to()

Posted by Dragisa Krsmanovic <dk...@plos.org>.
On Wed, 2009-10-14 at 05:58 +0200, Claus Ibsen wrote:
> Ah the reason is that the javac and generics is limited in terms of DSL wise.
> 
> What you need to do is to pass in the xpath as a 2nd parameter to setHeader.
> 
> This
>    .setHeader(DOI).xpath("/ambraMessage/doi/text()", String.class)
> 
> Should be
>    .setHeader(DOI, xpath("/ambraMessage/doi/text()", String.class))
> 

I don't seem to have luck with this. This doesn't compile:

from("activemq:plos.pmc")
 .setHeader(DOI, xpath("/ambraMessage/doi/text()", String.class))
 .to("mock:end");

xpath() is not defined in RouteBuilder.

-- 
Dragisa Krsmanovic
Java Developer
Public Library of Science 
http://www.plos.org


Re: Calling setHeader() after to()

Posted by Claus Ibsen <cl...@gmail.com>.
On Tue, Oct 13, 2009 at 6:54 PM, Dragisa Krsmanovic
<dk...@plos.org> wrote:
> On Tue, 2009-10-13 at 06:13 +0200, Claus Ibsen wrote:
>> On Mon, Oct 12, 2009 at 10:39 PM, Dragisa Krsmanovic
>> <dk...@plos.org> wrote:
>> > I am trying to do something like:
>> >
>> >  from("activemq:plos.pmc")
>> >    .to("rnc:pmc-message.rnc")
>> >    .setHeader(DOI).xpath("/ambraMessage/doi/text()", String.class)
>> >    .setHeader(Exchange.FILE_NAME).xpath("/ambraMessage/archive/text()",String.class)
>> >  ...
>> >
>> > But it doesn't allow me to add any setHeader methods
>> > after .to("rnc:...") I want to validate a message before I try to
>> > extract Xpath and I have an onException handler to catch
>> > ValidationException.
>> >
>> > What am I doing wrong ?
>> >
>>
>> What do you mean by doesnt allow me to?
>>
>> You should be able to do that. Are you sure an exception is not occurring?
>> You can use the tracer to see how the message is routed
>> http://camel.apache.org/tracer
>
> Sorry, I meant to say it doesn't compile.
>
> This route will not compile on Camel 2.0.0 or latest 2.1-SNAPSHOT:

Ah the reason is that the javac and generics is limited in terms of DSL wise.

What you need to do is to pass in the xpath as a 2nd parameter to setHeader.

This
   .setHeader(DOI).xpath("/ambraMessage/doi/text()", String.class)

Should be
   .setHeader(DOI, xpath("/ambraMessage/doi/text()", String.class))



>
> from("activemq:plos.pmc")
>   .to("rnc:pmc-message.rnc")
>   .setHeader(DOI).xpath("/ambraMessage/doi/text()", String.class)
>   .setHeader(Exchange.FILE_NAME).xpath("/ambraMessage/archive/text()",String.class)
>   .setHeader("to").xpath("/ambraMessage/pmc/mailto/text()",String.class)
>   .setHeader("CC").xpath("/ambraMessage/pmc/mailtoCC/text()",String.class)
>   .setHeader("from").xpath("/ambraMessage/pmc/mailtoSender/text()",String.class)
>   .to("mock:end");
>
>
> --
> Dragisa Krsmanovic
> Java Developer
> Public Library of Science
> http://www.plos.org
>
>




-- 
Claus Ibsen
Apache Camel Committer

Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Re: Calling setHeader() after to()

Posted by Dragisa Krsmanovic <dk...@plos.org>.
On Tue, 2009-10-13 at 06:13 +0200, Claus Ibsen wrote:
> On Mon, Oct 12, 2009 at 10:39 PM, Dragisa Krsmanovic
> <dk...@plos.org> wrote:
> > I am trying to do something like:
> >
> >  from("activemq:plos.pmc")
> >    .to("rnc:pmc-message.rnc")
> >    .setHeader(DOI).xpath("/ambraMessage/doi/text()", String.class)
> >    .setHeader(Exchange.FILE_NAME).xpath("/ambraMessage/archive/text()",String.class)
> >  ...
> >
> > But it doesn't allow me to add any setHeader methods
> > after .to("rnc:...") I want to validate a message before I try to
> > extract Xpath and I have an onException handler to catch
> > ValidationException.
> >
> > What am I doing wrong ?
> >
> 
> What do you mean by doesnt allow me to?
> 
> You should be able to do that. Are you sure an exception is not occurring?
> You can use the tracer to see how the message is routed
> http://camel.apache.org/tracer

Sorry, I meant to say it doesn't compile.

This route will not compile on Camel 2.0.0 or latest 2.1-SNAPSHOT:

from("activemq:plos.pmc")
   .to("rnc:pmc-message.rnc")
   .setHeader(DOI).xpath("/ambraMessage/doi/text()", String.class)
   .setHeader(Exchange.FILE_NAME).xpath("/ambraMessage/archive/text()",String.class)
   .setHeader("to").xpath("/ambraMessage/pmc/mailto/text()",String.class)
   .setHeader("CC").xpath("/ambraMessage/pmc/mailtoCC/text()",String.class)
   .setHeader("from").xpath("/ambraMessage/pmc/mailtoSender/text()",String.class)
   .to("mock:end");


-- 
Dragisa Krsmanovic
Java Developer
Public Library of Science 
http://www.plos.org


Re: Calling setHeader() after to()

Posted by Claus Ibsen <cl...@gmail.com>.
On Mon, Oct 12, 2009 at 10:39 PM, Dragisa Krsmanovic
<dk...@plos.org> wrote:
> I am trying to do something like:
>
>  from("activemq:plos.pmc")
>    .to("rnc:pmc-message.rnc")
>    .setHeader(DOI).xpath("/ambraMessage/doi/text()", String.class)
>    .setHeader(Exchange.FILE_NAME).xpath("/ambraMessage/archive/text()",String.class)
>  ...
>
> But it doesn't allow me to add any setHeader methods
> after .to("rnc:...") I want to validate a message before I try to
> extract Xpath and I have an onException handler to catch
> ValidationException.
>
> What am I doing wrong ?
>

What do you mean by doesnt allow me to?

You should be able to do that. Are you sure an exception is not occurring?
You can use the tracer to see how the message is routed
http://camel.apache.org/tracer

>
> --
> Dragisa Krsmanovic
> Java Developer
> Public Library of Science
> http://www.plos.org
>
>



-- 
Claus Ibsen
Apache Camel Committer

Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus