Scenario 3: Modifying the ResponseLine/StatusCode only (HTTPResponse)

This scenario illustrates how to modify the StatusCode and Reason elements in an HTTP Response. The XSLT in this example makes the following updates:

  • 503 status codes are changed to be 501.
  • When a status code update occurs, the reason is also updated to reflect the change. The reason for the 501 status is “Not Implemented".

Input documents

The following sample input documents are used for this scenario:

HTTP Response

<?xml version="1.0" encoding="UTF-8"?>
<HTTPResponse>
	<ResponseLine>
		<Version>HTTP/1.1</Version>
		<StatusCode>503</StatusCode>
		<Reason>Service Unavailable</Reason>
	</ResponseLine>
	<Headers>
		<Header name="Date">Thu%2C%2016%20Sep%202010%2010
			%3A57%3A52%20GMT</Header>
		<Header name="Server">IBM_HTTP_Server</Header>
		<Header name="Content-Type">text%2Fhtml%3Bcharset%3DUTF-8</Header>
		<Header name="Content-Language">en-US</Header>
	</Headers>
	<Cookies>
		<Cookie name="PD-S-SESSION-ID">
			<Content>2_orQUNJCbjdxqIEdDPMXj31UiHMXuU3hRCUtpN7xe6J1xZhxt0</Content>
			<Path>/</Path>
			<Domain>domainA.com</Domain>
			<Expires>Wed, 09 Jun 2021 10:18:14 GMT</Expires>
			<Secure>1</Secure>
			<HTTPOnly>0</HTTPOnly>
		</Cookie>
	</Cookies>
</HTTPResponse>

XSLT Rules

Note: These rules must be stored in an XSL document that is defined as a response resource with an associated POP. See Configuration.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	version="1.0">

	<!--Firstly, strip any space elements -->
	<xsl:strip-space elements="*" />
	
	<!-- 
		Perform a match on the root of the document. Output the required
		HTTPResponseChange elements and then process templates.	
	-->
		<xsl:template match="/">
			<HTTPResponseChange>
				<xsl:apply-templates />
			</HTTPResponseChange>
		</xsl:template>
	
	<!-- 
		Do nothing to the Version
	-->	
	<xsl:template match="//HTTPResponse/ResponseLine/Version" />

	<!-- 
		If the original StatusCode is 503 then update the 
		StatusCode to 501.
	-->	
	<xsl:template match="//HTTPResponse/ResponseLine">
        <xsl:choose>
            <xsl:when test="StatusCode='503'">
                <StatusCode>501</StatusCode>
                <Reason>Not Implemented</Reason>
            </xsl:when>
        </xsl:choose>
    </xsl:template>

    <xsl:template match="//HTTPResponse/Credential" />

	<!-- 
		Do nothing to the Headers. 
	-->
	<xsl:template match="//HTTPResponse/Headers" />

       <!-- 
		Do nothing to the Cookies. 
	-->
	<xsl:template match="//HTTPResponse/Cookies" />

</xsl:stylesheet>

Output XML document

In this scenario, the following XML document is output from the XSL transformation. This document outlines changes for WebSEAL to perform on the original HTTP response.

<?xml version="1.0" encoding="UTF-8"?>
<HTTPResponseChange>
	<StatusCode>501</StatusCode>
	<Reason>Not Implemented</Reason>
</HTTPResponseChange>