DataPower

DataPower

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only

A Simple and Generic XSL Error Handler

By Leandro Takeda posted Tue May 29, 2018 03:01 PM

  

A Simple and Generic XSL Error Handler

By Leandro Takeda (May 2018)

 

You may already have a solution for this in your DataPower Gateway layer, if not, there you go!

That´s a simple error handler so you can include in your error rule, in your MPGW, Web Service Proxy, or whatever.

First of all, a tip, we start with a comment (or summary), it's a good practice. It works basically to let who will may read this, or edit this file, in future, knows about the file refers to. It will explain what the purpose of this file is, etc.

<dp:summary xmlns="">

<operation>xform</operation>

<description>EDP Error Handling for SOAP</description>

</dp:summary>

Now we will get the DataPower error code, if it´s not a DataPower exception, the code will be 0x00000000, if there is no sub-code, we will get the error-code, both codes can be used later to get the exact error. There are lot of scenarios where we have error-code and not sub-code and vice-versa. I will definitely not explain this here. :)

<xsl:variable name="errorCodeDataPower">

<xsl:choose>

<xsl:when test="dp:variable('var://service/error-subcode') != '0x00000000'">

<xsl:value-of select="dp:variable('var://service/error-subcode')"/>

</xsl:when>

<xsl:otherwise>

<xsl:value-of select="dp:variable('var://service/error-code')"/>

</xsl:otherwise>

</xsl:choose>

</xsl:variable>

Also, you can customize based on what you want, if you want to get the code from the HTTP, just do:

<xsl:variable name="statusCode" select="dp:http-response-header('x-dp-response-code')"/>

<xsl:when test="dp:responding() and regexp:match($statusCode,'401(.*)','') ">Authorization Error: User Unauthorized to access this resource</xsl:when>

As I said, this is just an example, see that we are not using the error-code here, but if you want, you can:

<xsl:when test="$errorCodeDataPower = '0x01130006'">

<xsl:value-of select="concat('Internal Error: Service Temporarily Out of Service - Please contact system administrator - Request reference: ', $externalTransactionID )"/>

</xsl:when>

This is a simple example of: “Failed to establish a backside connection error”.

You can find a complete list of errors here:

https://www.ibm.com/support/knowledgecenter/en/SS9H2Y_7.2.0/com.ibm.dp.doc/results.html

You can also send it to the system log:

<xsl:message dp:priority="error">

<xsl:value-of select="concat('Soap Fault Sent: ', $faultstring)" />

* This is message we got before, from HTTP or from DataPower

</xsl:message>

And not less important, create the response message:

<env:Envelope>

<env:Body>

<env:Fault>

<faultcode>

<xsl:choose>

<xsl:when test="dp:responding()">env:Server</xsl:when>

<xsl:otherwise>env:Client</xsl:otherwise>

</xsl:choose>

                    </faultcode>

                    <faultstring>

<xsl:value-of select="$faultstring"/>

* This is message we got before, from HTTP or from DataPower

</faultstring>

                    <detail>

                         <timestamp>

<xsl:value-of select="date:format-date(date:date-time(), 'yyyyMMddHHmmss')"/>

</timestamp>

                    </detail>

               </env:Fault>

         </env:Body>

</env:Envelope>

Please, don´t miss to provide as much as detail as possible, so you can help the developers on the other side as the application to handle the errors better.

And again, this tutorial contains just examples, ignore the order of the code and the errors used, that may not fit your environment.

Questions? letakeda@gmail.com

Enjoy! Cheers!

0 comments
48 views

Permalink