You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by paulc8712 <pa...@gmail.com> on 2013/08/28 05:44:00 UTC

freemarker with pojo and/or xpath

Hi All.

I'm fairly new to Camel - and very new to Freemarker.

There doesn't seem to be much out there in the way of camel-freemarker
examples other than the fairly simplistic email example in
http://camel.apache.org/freemarker.html

What I would like to be able to do is use freemarker with either a POJO
header or body, or XML using xpath.  Is this possible?

If it is - I would appreciate it greatly if people could share some sample
freemarker templates that use POJO as the data source.

Thanks, Paulc



--
View this message in context: http://camel.465427.n5.nabble.com/freemarker-with-pojo-and-or-xpath-tp5738098.html
Sent from the Camel - Users mailing list archive at Nabble.com.

AW: freemarker with pojo and/or xpath

Posted by "Jan Matèrne (jhm)" <ap...@materne.de>.
For Freemarker itself the manual is on http://freemarker.org/docs/

Jan

> -----Ursprüngliche Nachricht-----
> Von: Christian Posta [mailto:christian.posta@gmail.com]
> Gesendet: Mittwoch, 28. August 2013 06:01
> An: users@camel.apache.org
> Betreff: Re: freemarker with pojo and/or xpath
> 
> Yep, totally possible.
> So freemarker binds a "context" to the template, and populates the
> template body with whatever is found in the "context"
> So in the case of Camel integration, Camel will put some parts of the
> exchange (and the whole exchange actually) which is then available in
> the freemarker template.
> The body and headers are all treated as POJOs when they are bound to
> the freemarker context, so if you have your own pojo, MyPerson, and you
> wish you access its members 'givenName' or 'familyName' within the
> freemarker template, you can do so like ${body.givenName} or
> ${body.familyName}. Same thing goes for headers.
> 
> Have a peek at this unit test to make it more clear:
> 
> https://github.com/apache/camel/blob/master/components/camel-
> freemarker/src/test/java/org/apache/camel/component/freemarker/Freemark
> erBodyAsDomainObjectTest.java#L32
> 
> 
> On Tue, Aug 27, 2013 at 8:44 PM, paulc8712 <pa...@gmail.com> wrote:
> 
> > Hi All.
> >
> > I'm fairly new to Camel - and very new to Freemarker.
> >
> > There doesn't seem to be much out there in the way of camel-
> freemarker
> > examples other than the fairly simplistic email example in
> > http://camel.apache.org/freemarker.html
> >
> > What I would like to be able to do is use freemarker with either a
> > POJO header or body, or XML using xpath.  Is this possible?
> >
> > If it is - I would appreciate it greatly if people could share some
> > sample freemarker templates that use POJO as the data source.
> >
> > Thanks, Paulc
> >
> >
> >
> > --
> > View this message in context:
> > http://camel.465427.n5.nabble.com/freemarker-with-pojo-and-or-xpath-
> tp
> > 5738098.html Sent from the Camel - Users mailing list archive at
> > Nabble.com.
> >
> 
> 
> 
> --
> *Christian Posta*
> http://www.christianposta.com/blog
> twitter: @christianposta


Re: freemarker with pojo and/or xpath

Posted by Christian Posta <ch...@gmail.com>.
Yep, totally possible.
So freemarker binds a "context" to the template, and populates the template
body with whatever is found in the "context"
So in the case of Camel integration, Camel will put some parts of the
exchange (and the whole exchange actually) which is then available in the
freemarker template.
The body and headers are all treated as POJOs when they are bound to the
freemarker context, so if you have your own pojo, MyPerson, and you wish
you access its members 'givenName' or 'familyName' within the freemarker
template, you can do so like ${body.givenName} or ${body.familyName}. Same
thing goes for headers.

Have a peek at this unit test to make it more clear:

https://github.com/apache/camel/blob/master/components/camel-freemarker/src/test/java/org/apache/camel/component/freemarker/FreemarkerBodyAsDomainObjectTest.java#L32


On Tue, Aug 27, 2013 at 8:44 PM, paulc8712 <pa...@gmail.com> wrote:

> Hi All.
>
> I'm fairly new to Camel - and very new to Freemarker.
>
> There doesn't seem to be much out there in the way of camel-freemarker
> examples other than the fairly simplistic email example in
> http://camel.apache.org/freemarker.html
>
> What I would like to be able to do is use freemarker with either a POJO
> header or body, or XML using xpath.  Is this possible?
>
> If it is - I would appreciate it greatly if people could share some sample
> freemarker templates that use POJO as the data source.
>
> Thanks, Paulc
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/freemarker-with-pojo-and-or-xpath-tp5738098.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
*Christian Posta*
http://www.christianposta.com/blog
twitter: @christianposta