Hi Michael,

Just some quick thoughts to try and help out ;)

You can look at the local-name() XPath 2.0 function to obtain just the
element name without the namespace.

If you have an XSD representing your messages, you could consider using
JAXB or JiBX to turn them into objects before calling the Velocity
template. That would give you full access to the payload without having to
set headers one by one. You can then use the Velocity VTL [1] to access
your object's properties.

AFAIK, in Velocity, using $body.Element will translate into calling the
getElement() getter on the $body variable (to which Camel injects the IN
message Body), so you'll want it to be a POJO at this point if you intend
to use this construct. With $headers, you access the headers of the IN
message instead of the body, and this is a Map.

Concerning the issue with the null value on ${headers.SItemID}, there could
be several possibilities. To ensure that we hit the bull's eye, could you
please paste down your entire XML document, including
the /evt:Event/evt:Header subtree? It seems that part is missing in the
thread.

Thanks,
Raúl.

[1] http://velocity.apache.org/engine/devel/vtl-reference-guide.html.

On 6 December 2011 17:49, MichaelAtSAG <mebevilac...@gmail.com> wrote:

> Thanks Claus.
>
> I am able to parse and use the first element named ${headers.SevtType} in
> velocity, excellent!
>
> Yet the second element named ${headers.SItemID} is not populated. Here are
> the current file:
>
> Camel context:
> -------------------
> <camelContext xmlns="http://camel.apache.org/schema/spring";
> xmlns:evt="http://namespaces.softwareag.com/EDA/Event";
>
> xmlns:pay="
> http://namespaces.softwareag.com/EDA/WebM/Sample/InventoryMgmt/1.0";>
> <route id="Route_Emit_InvShortage">
>        <setHeader headerName="evtType">
>                 <xpath>/evt:Event/evt:Header/evt:Type</xpath>
>        </setHeader>
>        <choice>
>                <when>
>                         <xpath>$evtType =
> '{
> http://namespaces.softwareag.com/EDA/WebM/Sample/InventoryMgmt/1.0}PartInventoryShortage
> '
>                                        </xpath>
>
>                        <setHeader headerName="SevtType">
>                                <xpath
> resultType="java.lang.String">/evt:Event/evt:Header/evt:Type</xpath>
>                        </setHeader>
>                        <setHeader headerName="SItemID">
>                                <xpath
>
> resultType="java.lang.String">/evt:Event/evt:Body/pay:PartInventoryLow/pay:Part/pay:ItemID</xpath>
>                        </setHeader>
>                         <to
> uri="velocity:file:src/main/resources/email.vm" />
>
> Velocity:
> -------------------
> Dear Purchaser,
>
> We have an urgent situation. We need ${body.DesiredInventoryLevel} piece(s)
> for item number ${headers.SItemID}, yet suppliers only have
> ${body.SupplierInventoryLevel} piece(s).
>
> Please review this situation.
>
> This is an automated email, triggered by event '${headers.SevtType}'.
> Please
> do not reply.
>
>
> Questions:
> -------------------
> <1> Why is the setHeader for ItemID not working?
> <2> What would the xpath command be to retrieve the local element, not the
> entire URI?
> Current:
> '{
> http://namespaces.softwareag.com/EDA/WebM/Sample/InventoryMgmt/1.0}PartInventoryShortage
> '
> Desired: 'PartInventoryShortage'
> <3> If I have the XSD, can I parse the entire document and reference all
> elements in velocity and not require the <setHeader> commands for each
> element?
> <4> In velocity, when do I use body.<element> versus header.<element> ?
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Velocity-without-java-tp5042885p5052886.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Reply via email to