Routing Based on XML Traffic

TrafficScript includes support for parsing XML documents using XPath, an industry-standard language used to query XML documents.

XML documents are used by SOAP-based protocols such as Web Services, and enable complex data to be exchanged and understood automatically without user intervention.

An XML document is organized into a tree structure of nodes1. Each node might contain a piece of data, or other nodes. XPath can navigate through these nodes to extract specific data from the XML document. This data can then be used to make routing decisions on the traffic.

The XPath 1.0 specification is available at http://www.w3.org/TR/xpath.

Example: Google Search Request

The Google™ search engine has a Web Services interface that accepts SOAP requests for search queries. A request for a search for Ivanti consists of an HTTP POST containing the following XML body data:

<?xml version="1.0" encoding="UTF-8"?>

<SOAP-ENV:Envelope

xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"

SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"

xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"

xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"

xmlns:xsd="http://www.w3.org/1999/XMLSchema">

<SOAP-ENV:Body>

<namesp1:doGoogleSearch xmlns:namesp1="urn:GoogleSearch">

<key xsi:type="xsd:string">googleUniqueID</key>

<q xsi:type="xsd:string">Ivanti</q>

<start xsi:type="xsd:int">0</start>

<maxResults xsi:type="xsd:int">10</maxResults>

<filter xsi:type="xsd:boolean">false</filter>

<restrict xsi:type="xsd:string"/>

<safeSearch xsi:type="xsd:boolean">false</safeSearch>

<lr xsi:type="xsd:string"/>

<ie xsi:type="xsd:string">latin1</ie>

<oe xsi:type="xsd:string">latin1</oe>

</namesp1:doGoogleSearch>

</SOAP-ENV:Body>

</SOAP-ENV:Envelope>

Note that the SOAP body contains a “doGoogleSearch” node. This contains the parameters of the search request.

An Internet service might implement or proxy doGoogleSearch requests and the Traffic Manager might be used to manage the traffic to this service.

For example, it might be necessary to split doGoogleSearch requests according to the specified maximum number of results. If “maxResults” is greater than 100, the request is to be sent to pool “googleLarge”, otherwise it should be sent to pool “google”.

A TrafficScript rule can use the functions xml.XPath.MatchNodeSet() and xml.XPath.MatchNodeCount() to query the SOAP request body and test XML nodes:

# Read the entire body of the SOAP/HTTP request

$body = http.getBody( 0 );

 

# XML parameters lie in the "urn:GoogleSearch" XML

# namespace:

$googlens = "xmlns:googlens=\"urn:GoogleSearch\"";

 

# Test for the presence of a "doGoogleSearch" node.

# If present, get the value of the "maxResults"

# parameter and choose the pool

 

if( xml.XPath.MatchNodeCount( $body, $googlens,

"//googlens:doGoogleSearch" ) ) {

 

$maxResults = xml.XPath.MatchNodeSet( $body, $googlens,

"//googlens:doGoogleSearch/maxResults/text()" );

 

if( $maxResults >= 100 ) {

pool.use( "googleLarge" );

} else {

pool.use( "google" );

}

}