Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
Showing results for 
Search instead for 
Did you mean: 
Intro: Once you are working on more complex logic to be implemented in CPI, using header and property value is very common practice. Accessing these values in groovy script is known to every one. This blog will go through different ways to access Header and properties values in following areas:


  • Xpath

  • Message Mapping

  • XSLT mapping

This will simpify the logic to be implemented.


  1. XPath:


Accessing header and property value in Xpath is pretty simple. Just use ${{headerName}} or ${{propertyName}} with the Xpath.


Consider below example:



Heaver Value

In order to collect all selling code having code type greater than 50, we can write the following XPATH:



Same way property can be accessed in Xpath, if in case both header and property have same variable name then header will take preference.


  1. Message Mapping


To access header and property value in Message Mapping flow, you need to create two different script with extension *.gsh and place it in script folder of project.






def String getProperty(String property_name, MappingContext context) {

    def propValue= context.getPropery(property_name);

    return propValue;







def String getheader(String header_name, MappingContext context) {

    def headervalue= context.getHeader(header_name);

    return headervalue;



Add these scripts as custom function in Message Mapping.


Once these script are added as custom function, they can be used within mapping as shown below. Add the variable name of header or property you want to retrieve in the constant function.




  1. XSLT mapping


All parameters defined in the XLST mapping are automatically bound to Camel headers. In case a property or header with that name already exists, its value gets auto assigned to the parameter.



First the namespace where the extension functions (setheader, setProperty) is registered needs to be defined.


<xsl:stylesheet version="2.0"


The exchange must be included in the XSLT as a parameter.


<xsl:param name="exchange"/>


Setting a header or property:

When this is done, the extension functions can be called from within the XSLT sheet. The provided functions have three parameters (the first parameter must be the exchange, the other two are header name and header value or exchange property name and value (all strings)).


Here is an example:

<xsl:template match="/">

<xsl:value-of select="hci:setHeader($exchange, 'myname', 'myvalue')"/>

<xsl:value-of select="hci:setProperty($exchange, 'myname', 'myvalue')"/>



Getting the value of a header or property:

In order to get the value of a header/property that already exists, simply define a parameter with the same name.


Example: assume that a header/property with the name a1 already exists and has a value 123, simple define a parameter with the same name:


<xsl:param name= “a1”>


Now 123 is automatically assigned as a value to a1.
Labels in this area