Wednesday, June 13, 2012

Retrieving the original Content-Type in WebSphere DataPower response Processing Rule

I ran into a situation with DataPower today where the Content-Type of the responses from DataPower is altered from the original Content-Type of the backend service into text/plain. I have a Multi-Protocol Gateway with an HTTP front-side handler and configured to have a Non-XML request and response type. I have multiple processing policies for accepting and sending requests to a number of backend services but only one processing policy for all the incoming responses from the bakend services. This processing rule has an xformbin transform as the first action so that the response payload is treated as a consumable string for the Log action that follows it. The last action in the processing rule is an xform action that sets the original HTTP status phrase from the backend.

The responses DataPower gets from the backend should be the same response the invoker receives. What happened is, since I have an xformbin action which transformed the response payload to text, the Content-Type was transformed into text/plain automatically. To solve this, I added a few lines in the last xform action in my proceasing rule which retrieves the original content type via var://context/INPUT/content-type.

My original intent was to set this variable in the first xformbin action so that I will retrieve it later in tha last xform action. But, when I tested it, I was surprised to see that I have successfully reassigned the original Content-Type already.

Here's a segment of the last xform:
<xsl:variable name="content_type" select="dp:variable('var://context/INPUT/content-type')" />
<dp:set-http-response-header name="'Content-Type'" value="$content_type" />
DISCLAIMER: I'm no expert in DataPower. In fact, it's just a recently acquired skill that is a few months old so please bare with me if my solutions seem stupid.

No comments: