Using headers and velocity

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Using headers and velocity

Castyn
This post was updated on .
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.  What am I doing wrong, or is there a better way to do this?  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>
Reply | Threaded
Open this post in threaded view
|

Re: Using headers and velocity

Christian Mueller
Administrator
Hello Eric!

Is there a question? ;-)

Best,
Christian

On Mon, Nov 28, 2011 at 10:51 PM, Castyn <[hidden email]> 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.
>
Reply | Threaded
Open this post in threaded view
|

Re: Using headers and velocity

Castyn
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.
Reply | Threaded
Open this post in threaded view
|

Re: Using headers and velocity

Claus Ibsen-2
In reply to this post by Castyn
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 <[hidden email]> 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: [hidden email]
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/
Reply | Threaded
Open this post in threaded view
|

Re: Using headers and velocity

Castyn
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.

Reply | Threaded
Open this post in threaded view
|

Re: Using headers and velocity

Castyn
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.