Scenario 1: Modifying the URI, headers, and cookies (HTTPRequest)

This scenario illustrates how to modify the RequestLine/URI element, as well as the header and cookie elements in the original HTTP request.

The following changes are made to the HTTP request in this example:

  1. Append /test to the existing URI value.
  2. Add a new header called NAME_A with the value VALUE_A if it does not exist.
  3. Update the NAME_B header value to be UPDATED_B.
  4. Remove the header called NAME_C.
  5. Add a cookie called MY_COOKIE.
  6. Update the EXISTING_COOKIE cookie content to be NEW_COOKIE_VALUE.

Input documents

The following sample input documents are used for this scenario:

HTTP Request

<?xml version="1.0" encoding="UTF-8"?>
<HTTPRequest>
       <Scheme>https</Scheme>
	<RequestLine>
		<Method>GET</Method>
		<URI>/en/us/</URI>
  
		<Version>HTTP/1.1</Version>
	</RequestLine>
	<Headers>
		<Header name="Host">www.ibm.com</Header>
		<Header name="NAME_B">original_b</Header>
		<Header name="NAME_C">original_c</Header>
	</Headers>
	<Cookies>
		<Cookie name="EXISTING_COOKIE">2_orQUNJCbjdxqIEdDPMXj31UHMXuU3hRCU...</Cookie>
	</Cookies> 
</HTTPRequest>

XSLT Rules

Note: These rules must be stored in an XSL document that is defined as a request resource with an associated POP or a request line pattern match. 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
  HTTPRequestChange elements and then process templates.
 -->
 <xsl:template match="/">
  <HTTPRequestChange>
   <xsl:apply-templates />

   <!-- Update the value of object name based on the URI -->
   <ObjectName>
    /combined-instances<xsl:value-of select="//HTTPRequest/RequestLine/URI"/>
   </ObjectName>

  </HTTPRequestChange>
 </xsl:template>

 <!--
  Do nothing to the Method.
 -->
 <xsl:template match="//HTTPRequest/RequestLine/Method" />

 <!--
  Match on the URI. Append "test/" to the URI.
 -->
 <xsl:template match="//HTTPRequest/RequestLine/URI">
  <URI>
   <xsl:value-of select="node()" />
    test/
  </URI>
 </xsl:template>

 <!--
  Do nothing to the Version
 -->
 <xsl:template match="//HTTPRequest/RequestLine/Version" />

 <!--
  Match on the Headers. Add a new header called NAME_A if
  it does not exist.
 -->
 <xsl:template match="//HTTPRequest/Headers">
  <xsl:choose>
   <xsl:when test="Header/@name='NAME_A'" />
   <xsl:otherwise>
    <Header action="add" name="NAME_A">
     VALUE_A
    </Header>
   </xsl:otherwise>
  </xsl:choose>
  <xsl:apply-templates select="//HTTPRequest/Headers/Header" />
 </xsl:template>

 <!-- Process the header elements -->
 <xsl:template match="//HTTPRequest/Headers/Header">
  <xsl:choose>
   <!-- Update the value of the NAME_B header -->
   <xsl:when test="@name = 'NAME_B'">
    <Header action="update" name="NAME_B">
     UPDATED_B
    </Header>
   </xsl:when>
   <!-- Delete the NAME_C header -->
   <xsl:when test="contains(@name, 'NAME_C')">
    <Header action="remove" name="NAME_C">
     <xsl:value-of select="node()" />
    </Header>
   </xsl:when>
  </xsl:choose>
 </xsl:template>

 <!--
  Match on the Cookies. Add a new cookie called MY_COOKIE if
  it does not exist.
 -->
 <xsl:template match="//HTTPRequest/Cookies">
  <xsl:choose>
   <xsl:when test="Cookie/@name='MY_COOKIE'" />
   <xsl:otherwise>
    <Cookie action="add" name="MY_COOKIE">
     MY_COOKIE_VALUE
    </Cookie>
   </xsl:otherwise>
  </xsl:choose>
  <xsl:apply-templates select="//HTTPRequest/Cookies/Cookie" />
 </xsl:template>

 <!-- Process the cookie elements -->
 <xsl:template match="//HTTPRequest/Cookies/Cookie">
  <xsl:choose>
   <!-- Update the value of the EXISTING_COOKIE cookie -->
   <xsl:when test="@name = 'EXISTING_COOKIE'">
    <Cookie action="update" name="EXISTING_COOKIE">
     NEW_COOKIE_VALUE
    </Cookie>
   </xsl:when>
  </xsl:choose>
 </xsl:template>
 <xsl:template match="//HTTPRequest/Credential" />
</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 request.


<?xml version="1.0" encoding="UTF-8"?>
<HTTPRequestChange>
 <URI>/en/us/test/</URI>
 <Header action="add" name="NAME_A">VALUE_A</Header>
 <Header action="update" name="NAME_B">UPDATED_B</Header>
 <Header action="remove" name="NAME_C">ORIGINAL_C</Header>
 <Cookie action="add" name="MY_COOKIE">MY_COOKIE_VALUE</Cookie>
 <Cookie action="update" name="EXISTING_COOKIE">NEW_COOKIE_VALUE</Cookie>
 <ObjectName>/combined-instances/jct/resourceB</ObjectName>
</HTTPRequestChange>