You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by mtod09 <mt...@thetods.net> on 2014/12/16 23:59:29 UTC

Camel Spring XML working with variables from xml message

I'm developing a route that will read the incoming xml message and create a
new message to pass to an outbound route.

I need to extract some data via xpath then concat the data  elements to send
to a new route.

Example

<msg1>
   <data1>My</data1>
   <data2>home</data2>
<msg1>

var1 = data1
var2 = data2

var3 = var1 + " " + var2

var3 = "My home"

I'm not sure how to do this with Spring XML does any one have an example or
pointer?

My Route so far:

    <camel:camelContext id="myCamel"
xmlns="http://camel.apache.org/schema/spring">

        <camel:dataFormats>
            <camel:syslog id="mySyslog"/>
        </camel:dataFormats>

        <camel:route>
            <camel:from uri="activemq:queue:syslogMessages"/>
            
            <setHeader headerName="DateValue">
                <xpath
resultType="String">/km:FMIMessage/km:Header/km:Payload/se:SystemEvent/se:EventTime/text()</xpath>
            </setHeader>
            <setHeader headerName="PRI">
                <xpath
resultType="String">/km:FMIMessage/km:Header/km:Payload/se:SystemEvent/se:LevelID/text()</xpath>
            </setHeader>
            <setHeader headerName="Hostname">
                <xpath
resultType="String">/km:FMIMessage/km:Header/km:Payload/se:SystemEvent/se:ServerName/text()</xpath>
            </setHeader>
            <setHeader headerName="Message">
                <xpath
resultType="String">/km:FMIMessage/km:Header/km:Payload/se:SystemEvent/se:MessageText/text()</xpath>
            </setHeader>
            <setHeader headerName="SyslogMsg">
                <constant>"<2> DateValue Hostname Message"</constant>
            </setHeader>
            
            

            <camel:marshal ref="mySyslog"/>
            <camel:to uri="mina:udp://localhost:514?sync=false"/>
            

        </camel:route>

    </camel:camelContext>

Thanks 

Mike




--
View this message in context: http://camel.465427.n5.nabble.com/Camel-Spring-XML-working-with-variables-from-xml-message-tp5760788.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel Spring XML working with variables from xml message

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

If you have all the data in headers, then you can use the simple
language to build a message body
http://camel.apache.org/simple

I guess this is what you attempted with <constant>. But constant is
what is says a constant.

 <constant>"<2> DateValue Hostname Message"</constant>

So try with

 <simple>"<2> ${header. DateValue} ${header. Hostname} ${header.
Message}"</simple>

On Tue, Dec 16, 2014 at 11:59 PM, mtod09 <mt...@thetods.net> wrote:
> I'm developing a route that will read the incoming xml message and create a
> new message to pass to an outbound route.
>
> I need to extract some data via xpath then concat the data  elements to send
> to a new route.
>
> Example
>
> <msg1>
>    <data1>My</data1>
>    <data2>home</data2>
> <msg1>
>
> var1 = data1
> var2 = data2
>
> var3 = var1 + " " + var2
>
> var3 = "My home"
>
> I'm not sure how to do this with Spring XML does any one have an example or
> pointer?
>
> My Route so far:
>
>     <camel:camelContext id="myCamel"
> xmlns="http://camel.apache.org/schema/spring">
>
>         <camel:dataFormats>
>             <camel:syslog id="mySyslog"/>
>         </camel:dataFormats>
>
>         <camel:route>
>             <camel:from uri="activemq:queue:syslogMessages"/>
>
>             <setHeader headerName="DateValue">
>                 <xpath
> resultType="String">/km:FMIMessage/km:Header/km:Payload/se:SystemEvent/se:EventTime/text()</xpath>
>             </setHeader>
>             <setHeader headerName="PRI">
>                 <xpath
> resultType="String">/km:FMIMessage/km:Header/km:Payload/se:SystemEvent/se:LevelID/text()</xpath>
>             </setHeader>
>             <setHeader headerName="Hostname">
>                 <xpath
> resultType="String">/km:FMIMessage/km:Header/km:Payload/se:SystemEvent/se:ServerName/text()</xpath>
>             </setHeader>
>             <setHeader headerName="Message">
>                 <xpath
> resultType="String">/km:FMIMessage/km:Header/km:Payload/se:SystemEvent/se:MessageText/text()</xpath>
>             </setHeader>
>             <setHeader headerName="SyslogMsg">
>                 <constant>"<2> DateValue Hostname Message"</constant>
>             </setHeader>
>
>
>
>             <camel:marshal ref="mySyslog"/>
>             <camel:to uri="mina:udp://localhost:514?sync=false"/>
>
>
>         </camel:route>
>
>     </camel:camelContext>
>
> Thanks
>
> Mike
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Camel-Spring-XML-working-with-variables-from-xml-message-tp5760788.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/