You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Castyn <er...@gmail.com> on 2011/11/28 22:51:22 UTC
Using headers and velocity
I am trying to get a piece of information that is obtained via a cxfEndpoint
into a velocity template that will be sent on down the route to other
endpoints. Thus far I am trying something very basic and seems like it
should work, just storing the sessionId retrieved via xpath as a header and
then referencing it in the velocity template. Here are the basic components
currently:
*Camel Route: (beginning is just a timer and request)*
....
<to uri="cxf:bean:salesforceLogin"/>
<convertBodyTo type="org.w3c.dom.Document" />
<setHeader headerName="sforceSessionId" id="sforceSessionId">
<xpath resultType="java.lang.String">//sessionId</xpath>
</setHeader>
<to uri="velocity://velocity/sforceLogout.vm" />
*Message from cxf:bean:salesforceLogin:*
<?xml version="1.0" encoding="UTF-8" ?>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns="urn:enterprise.soap.sforce.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<loginResponse>
<result>
<sessionId>*ABCDE*</sessionId>
</result>
</loginResponse>
</soapenv:Body>
</soapenv:Envelope>
*Velocity Template:*
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:urn="urn:enterprise.soap.sforce.com">
<soapenv:Header>
<urn:SessionHeader>
<urn:sessionId>${headers.sforceSessionId}</urn:sessionId>
</urn:SessionHeader>
</soapenv:Header>
<soapenv:Body>
<urn:logout/>
</soapenv:Body>
</soapenv:Envelope>
--
View this message in context: http://camel.465427.n5.nabble.com/Using-headers-and-velocity-tp5030214p5030214.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Using headers and velocity
Posted by Castyn <er...@gmail.com>.
Well the last part of the route has nothing in the sessionId of the velocity
template which is my issue, so I am wondering what is wrong with what I am
doing really.
--
View this message in context: http://camel.465427.n5.nabble.com/Using-headers-and-velocity-tp5030214p5030870.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Using headers and velocity
Posted by Christian Müller <ch...@gmail.com>.
Hello Eric!
Is there a question? ;-)
Best,
Christian
On Mon, Nov 28, 2011 at 10:51 PM, Castyn <er...@gmail.com> wrote:
> I am trying to get a piece of information that is obtained via a
> cxfEndpoint
> into a velocity template that will be sent on down the route to other
> endpoints. Thus far I am trying something very basic and seems like it
> should work, just storing the sessionId retrieved via xpath as a header and
> then referencing it in the velocity template. Here are the basic
> components
> currently:
>
> *Camel Route: (beginning is just a timer and request)*
> ....
> <to uri="cxf:bean:salesforceLogin"/>
> <convertBodyTo type="org.w3c.dom.Document" />
> <setHeader headerName="sforceSessionId"
> id="sforceSessionId">
> <xpath resultType="java.lang.String">//sessionId</xpath>
> </setHeader>
> <to uri="velocity://velocity/sforceLogout.vm" />
>
> *Message from cxf:bean:salesforceLogin:*
> <?xml version="1.0" encoding="UTF-8" ?>
> <soapenv:Envelope
> xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
> xmlns="urn:enterprise.soap.sforce.com"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
> <soapenv:Body>
> <loginResponse>
> <result>
> <sessionId>*ABCDE*</sessionId>
> </result>
> </loginResponse>
> </soapenv:Body>
> </soapenv:Envelope>
>
> *Velocity Template:*
> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/
> "
> xmlns:urn="urn:enterprise.soap.sforce.com">
> <soapenv:Header>
> <urn:SessionHeader>
> <urn:sessionId>${headers.sforceSessionId}</urn:sessionId>
> </urn:SessionHeader>
> </soapenv:Header>
> <soapenv:Body>
> <urn:logout/>
> </soapenv:Body>
> </soapenv:Envelope>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Using-headers-and-velocity-tp5030214p5030214.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
Re: Using headers and velocity
Posted by Castyn <er...@gmail.com>.
Apparently what I said about using a mock namespace does actually work, so I
just set a xmlnx:s to the standard namespace in the xml message and then the
xpath worked great.
--
View this message in context: http://camel.465427.n5.nabble.com/Using-headers-and-velocity-tp5030214p5032900.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Using headers and velocity
Posted by Castyn <er...@gmail.com>.
I have checked the headers and it does seem that the xpath is not returning
anything.
Given that this is the Spring DSL, and the sessionID element would only fall
under the standard namespace I am not sure how to actually declare it in the
spring DSL properly. Can I use a mock namespace and append that to the
front of the expression? Seems like saying //ns0:sessionID wouldn't work
though even if I set the ns0 in the context to the base xmnls of the doc.
Would a simple expression be easier to pull out this sessionID value? I
tried that as well and am still not getting a value from it.
--
View this message in context: http://camel.465427.n5.nabble.com/Using-headers-and-velocity-tp5030214p5032839.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Using headers and velocity
Posted by Claus Ibsen <cl...@gmail.com>.
Make sure the xpath expression works. When using XPath on a XML that
has namespaces, then you must declare the namespace in the XPath
expression as well. That can be a bit tricky.
See the Camel XPath page for an example.
Also you can send the message to a log endpoint, and have
?showHeaders=true, to see all the headers. Then you would possible
notice that the header is missing / or has null value.
On Mon, Nov 28, 2011 at 10:51 PM, Castyn <er...@gmail.com> wrote:
> I am trying to get a piece of information that is obtained via a cxfEndpoint
> into a velocity template that will be sent on down the route to other
> endpoints. Thus far I am trying something very basic and seems like it
> should work, just storing the sessionId retrieved via xpath as a header and
> then referencing it in the velocity template. Here are the basic components
> currently:
>
> *Camel Route: (beginning is just a timer and request)*
> ....
> <to uri="cxf:bean:salesforceLogin"/>
> <convertBodyTo type="org.w3c.dom.Document" />
> <setHeader headerName="sforceSessionId" id="sforceSessionId">
> <xpath resultType="java.lang.String">//sessionId</xpath>
> </setHeader>
> <to uri="velocity://velocity/sforceLogout.vm" />
>
> *Message from cxf:bean:salesforceLogin:*
> <?xml version="1.0" encoding="UTF-8" ?>
> <soapenv:Envelope
> xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
> xmlns="urn:enterprise.soap.sforce.com"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
> <soapenv:Body>
> <loginResponse>
> <result>
> <sessionId>*ABCDE*</sessionId>
> </result>
> </loginResponse>
> </soapenv:Body>
> </soapenv:Envelope>
>
> *Velocity Template:*
> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
> xmlns:urn="urn:enterprise.soap.sforce.com">
> <soapenv:Header>
> <urn:SessionHeader>
> <urn:sessionId>${headers.sforceSessionId}</urn:sessionId>
> </urn:SessionHeader>
> </soapenv:Header>
> <soapenv:Body>
> <urn:logout/>
> </soapenv:Body>
> </soapenv:Envelope>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Using-headers-and-velocity-tp5030214p5030214.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
--
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/