N.B. this tutorial assumes the reader has some knowledge of DataPower.
IBM WebSphere DataPower SOA Appliances provides, apart from the XSLT1.0 extension functions, a wide range of DataPower specific XSLT extensions functions. Anyone who has got their hands dirty trying to do DataPower programming using XSLT knows that there are many ways to solve a problem.
In this post i will explain how to add a custom header to a request/response. More specifically i will add a custom response header to an HTTP request. If you have gone through the DataPower Extension Elements and Functions Catalog knows that there are 2 options available -
- set-http-request-header and set-http-response-header
- set-request-header and set-response-header
The later being for both HTTP and MQ.
I will be using the set-response-header in this example. This is particularly useful when dealing with web-services.
We will consider the following scenario –
- User makes a simple HTTP POST to a DataPower HTTP FSPH
- The backend of the DataPower config echoes the POST message
- On the response rule we add a custom header
This way we can verify the header getting added without having to enable the debug logs or probe on the appliance.
The policy looks like the one below.
Under the Server to Client rule, which is our response rule, I have added a Transform action. The style sheet with in the Transform action just adds a custom header to the response rule. This is the XSLT that I used
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dp="http://www.datapower.com/extensions" extension-element-prefixes="dp" exclude-result-prefixes="dp"> <xsl:template match="/"> <xsl:variable name="s" select="dp:variable('var://service/routing-url')" /> <dp:set-http-response-header name="'SomeRandomlyAddedHeader'" value="$s"/> </xsl:template> </xsl:stylesheet>
We are adding an additional header “’SomeRandomlyAddedHeader”. When we place the POST request to the DataPower service we get the headers as shown below –