You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Amiya Sankar Pradhan <am...@gmail.com> on 2017/05/31 09:07:05 UTC

Extract xml attribute value and set to request header

Hi All, I am new to apache camel. I need some help on the below issue.

We have a requirement to set a header values(value has to be extracted from
the body before setting) in soap request based on the soap body element
received and then reroute it after that.

Presently we are marsalling the soap body to java object in the router class
and getting the required value and setting it to the header. As the request
is very large we are facing memory leak issue.

therefore we want to read the xml and retrieve the attribute and set it in
the header without converting it to java object.

please let us know how can we achieve that. Also let me know if this
approach is correct.

Thanks 



--
View this message in context: http://camel.465427.n5.nabble.com/Extract-xml-attribute-value-and-set-to-request-header-tp5801420.html
Sent from the Camel - Users mailing list archive at Nabble.com.

AW: Extract xml attribute value and set to request header

Posted by Burkard Stephan <St...@visana.ch>.
Hi 

In Java DSL you can do it like this: 

.setHeader("myHeader").xpath("/xpath/to/needed/element", String.class)

XPath in Camel: http://camel.apache.org/xpath.html
Set Message-Header example: http://camel.apache.org/constant.html

Regards
Stephan


-----Ursprüngliche Nachricht-----
Von: Amiya Sankar Pradhan [mailto:amiya.cart@gmail.com] 
Gesendet: Mittwoch, 31. Mai 2017 11:07
An: users@camel.apache.org
Betreff: Extract xml attribute value and set to request header

Hi All, I am new to apache camel. I need some help on the below issue.

We have a requirement to set a header values(value has to be extracted from the body before setting) in soap request based on the soap body element received and then reroute it after that.

Presently we are marsalling the soap body to java object in the router class and getting the required value and setting it to the header. As the request is very large we are facing memory leak issue.

therefore we want to read the xml and retrieve the attribute and set it in the header without converting it to java object.

please let us know how can we achieve that. Also let me know if this approach is correct.

Thanks 



--
View this message in context: http://camel.465427.n5.nabble.com/Extract-xml-attribute-value-and-set-to-request-header-tp5801420.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Extract xml attribute value and set to request header

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

If the SOAP body is XML payload you can extract the values using xpath
or xquery languages.

But mind that XPath likely reads in the content into memory - not sure
if it has any kind of streaming support.
And I think XPath from the JDK reads content into memory.

An alternative is to use StAX which can parse in a streaming mode, and
then parse until you have the value and then stop.

Camel has a StAX component
http://camel.apache.org/stax





On Wed, May 31, 2017 at 11:07 AM, Amiya Sankar Pradhan
<am...@gmail.com> wrote:
> Hi All, I am new to apache camel. I need some help on the below issue.
>
> We have a requirement to set a header values(value has to be extracted from
> the body before setting) in soap request based on the soap body element
> received and then reroute it after that.
>
> Presently we are marsalling the soap body to java object in the router class
> and getting the required value and setting it to the header. As the request
> is very large we are facing memory leak issue.
>
> therefore we want to read the xml and retrieve the attribute and set it in
> the header without converting it to java object.
>
> please let us know how can we achieve that. Also let me know if this
> approach is correct.
>
> Thanks
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Extract-xml-attribute-value-and-set-to-request-header-tp5801420.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2