Manual Chapter :
Routing Based on XML Content
Applies To:
Show VersionsBIG-IP AAM
- 15.1.8, 15.1.7, 15.1.6, 15.1.5, 15.1.4, 15.1.3, 15.1.2, 15.1.1, 15.1.0, 15.0.1, 15.0.0
BIG-IP APM
- 16.1.3, 16.1.2, 16.1.1, 16.1.0, 16.0.1, 16.0.0, 15.1.8, 15.1.7, 15.1.6, 15.1.5, 15.1.4, 15.1.3, 15.1.2, 15.1.1, 15.1.0, 15.0.1, 15.0.0
BIG-IP Analytics
- 16.1.3, 16.1.2, 16.1.1, 16.1.0, 16.0.1, 16.0.0, 15.1.8, 15.1.7, 15.1.6, 15.1.5, 15.1.4, 15.1.3, 15.1.2, 15.1.1, 15.1.0, 15.0.1, 15.0.0
BIG-IP Link Controller
- 16.1.3, 16.1.2, 16.1.1, 16.1.0, 16.0.1, 16.0.0, 15.1.8, 15.1.7, 15.1.6, 15.1.5, 15.1.4, 15.1.3, 15.1.2, 15.1.1, 15.1.0, 15.0.1, 15.0.0
BIG-IP LTM
- 16.1.3, 16.1.2, 16.1.1, 16.1.0, 16.0.1, 16.0.0, 15.1.8, 15.1.7, 15.1.6, 15.1.5, 15.1.4, 15.1.3, 15.1.2, 15.1.1, 15.1.0, 15.0.1, 15.0.0
BIG-IP PEM
- 16.1.3, 16.1.2, 16.1.1, 16.1.0, 16.0.1, 16.0.0, 15.1.8, 15.1.7, 15.1.6, 15.1.5, 15.1.4, 15.1.3, 15.1.2, 15.1.1, 15.1.0, 15.0.1, 15.0.0
BIG-IP AFM
- 16.1.3, 16.1.2, 16.1.1, 16.1.0, 16.0.1, 16.0.0, 15.1.8, 15.1.7, 15.1.6, 15.1.5, 15.1.4, 15.1.3, 15.1.2, 15.1.1, 15.1.0, 15.0.1, 15.0.0
BIG-IP DNS
- 16.1.3, 16.1.2, 16.1.1, 16.1.0, 16.0.1, 16.0.0, 15.1.8, 15.1.7, 15.1.6, 15.1.5, 15.1.4, 15.1.3, 15.1.2, 15.1.1, 15.1.0, 15.0.1, 15.0.0
BIG-IP ASM
- 16.1.3, 16.1.2, 16.1.1, 16.1.0, 16.0.1, 16.0.0, 15.1.8, 15.1.7, 15.1.6, 15.1.5, 15.1.4, 15.1.3, 15.1.2, 15.1.1, 15.1.0, 15.0.1, 15.0.0
Routing Based on XML Content
Overview: XML content-based routing
You can use the BIG-IP system to perform XML content-based routing
whereby the system routes requests to an appropriate pool, pool member, or virtual server based
on specific content in an XML document. For example, if your company transfers information in XML
format, you could use this feature to examine the XML content with the intent to route the
information to the appropriate department.
You configure content-based routing by creating an XML profile and associating it with a
virtual server. In the XML profile, define the matching content to look for in the XML document.
Next, specify how to route the traffic to a pool by writing simple iRules®.
When the system discovers a match, it triggers an iRule event, and then you can configure the
system to route traffic to a virtual server, a pool, or a node. You can allow multiple query
matches, if needed.
This example shows a simple XML document that the system could use to
perform content-based routing. It includes an element called
FinanceObject
used in this implementation.<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:eai="http://192.168.149.250/eai_enu/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"> <soapenv:Header/> <soapenv:Body> <eai:SiebelEmployeeDelete soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <FinanceObject xsi:type="xsd:string">Route to Financing</FinanceObject> <SiebelMessage xsi:type="ns:ListOfEmployeeInterfaceTopElmt" xmlns:ns="http://www.siebel.com/xml"> <ListOfEmployeeInterface xsi:type="ns:ListOfEmployeeInterface"> <SecretKey>123456789</SecretKey> <Employee>John</Employee> <Title>CEO</Title> </ListOfEmployeeInterface> </SiebelMessage> </eai:SiebelEmployeeDelete> </soapenv:Body> </soapenv:Envelope>
Creating a custom XML profile
To implement content-based routing, you first need to create an XML profile. XML
profiles specify the content to look for in XML documents. In the XML profile, you
define XPath queries to locate items in an XML document.
- On the Main tab, click.The XML screen opens.
- ClickCreate.The New XML screen opens.
- In theNamefield, type a unique name for the XML profile, such ascbr_xml_profile.
- In the Settings area, select theCustomcheck box at right.The settings become available.
- If you want to reference XML elements with namespaces in XPath queries, fromNamespace Mappings, selectSpecify.The screen displays theNamespace Mappings Listsettings.
- Add namespaces to the list to specify how to map XML namespaces (as defined by thexmlnsattribute) for the system to use when routing XML traffic to the correct pool, pool member, or virtual server:
- In thePrefixfield, type the namespace prefix.
- In theNamespacefield, type the URL that the prefix maps to.
- ClickAddto add the namespace to theNamespace Mappings List.
- To define the matching criteria in the XML document, fromXPath Queries, selectSpecify.The screen displays theXPath Queriessettings.
- Add XPath queries to the list to define matching criteria in XML payloads so the system can route the traffic to the correct pool, pool member, or virtual server:
- In theXPathfield, type an XPath expression.For example, to look for an element calledFinanceObject, type//FinanceObject.
- ClickAddto add the XPath expression to the XPath Queries list.You can define up to three XPath queries.The expression is added to the list.
- To allow each query to have multiple matches, selectMultiple Query Matches.
- ClickFinished.The system creates an XML profile.
You can use the XML profile to route XML traffic. Note that XML profiles do not support use of the Expect header field. This
is because the header of a transaction could direct it to one pool, and the payload could invoke an iRule to direct the transaction to a different pool.
Writing XPath queries
You can write up to three XPath queries to define the content that you are
looking for in XML documents. When writing XPath queries, you use a
subset of the XPath syntax described in the XML Path Language (XPath)
standard at
http://www.w3.org/TR/xpath
.These are the rules for writing XPath queries for XML content-based routing.
- Express the queries in abbreviated form.
- Map all prefixes to namespaces.
- Use only ASCII characters in queries.
- Write queries to match elements and attributes.
- Use wildcards as needed for elements and namespaces; for example,//emp:employee/*.
- Do not use predicates in queries.
Syntax for XPath expressions
This table shows the syntax to use for XPath expressions.
Expression |
Description |
---|---|
Nodename |
Selects all child nodes of the named node. |
@Attname |
Selects all attribute nodes of the named node. |
/ |
Indicates XPath step. |
// |
Selects nodes that match the selection no matter where they are in the
document. |
XPath query examples
This table shows examples of XPath queries.
Query |
Description |
---|---|
/a |
Selects the root element a . |
//b |
Selects all b elements wherever they appear in the
document. |
/a/b:* |
Selects any element in a namespace bound to prefix b ,
which is a child of the root element a . |
//a/b:c |
Selects elements in the namespace of element c , which is bound
to prefix b , and is a child of element a . |
Creating a pool to manage HTTP traffic
For implementing content-based routing, you can create one or more pools that contain
the servers where you want the system to send the traffic. You write an iRule to
route the traffic to the pool.
If you want to specify a default pool to which to send traffic when it does not match
the content you are looking for, repeat the procedure to create a second pool. You
specify the default pool in the virtual server. Alternatively, you can create a node
or a virtual server to route traffic to instead of creating a pool.
- On the Main tab, click.The Pool List screen opens.
- ClickCreate.The New Pool screen opens.
- In theNamefield, type a name for the pool, such asfinance_pool.
- For theHealth Monitorssetting, from theAvailablelist, select thehttpmonitor and move the monitor to theActivelist.
- From theLoad Balancing Methodlist, select how the system distributes traffic to members of this pool.The default isRound Robin.
- For thePriority Group Activationsetting, specify how to handle priority groups:
- SelectDisabledto disable priority groups. This is the default option.
- SelectLess than, and in theAvailable Membersfield type the minimum number of members that must remain available in each priority group in order for traffic to remain confined to that group.
- Using theNew Memberssetting, add each resource that you want to include in the pool:
- Type an IP address in theAddressfield.
- Type80in theService Portfield, or selectHTTPfrom the list.
- (Optional) Type a priority number in thePriorityfield.
- ClickAdd.
- ClickFinished.
The new pool appears in the Pools list.
Creating an iRule
You create iRules to automate traffic forwarding for XML
content-based routing. When a match occurs, an iRule event is triggered, and the iRule
directs the individual request to a pool, a node, or virtual server. This implementation
targets a pool.
- On the Main tab, click.
- ClickCreate.
- In theNamefield, type a name, such asXML_CBR_iRule.The full path name of the iRule cannot exceed 255 characters.
- In theDefinitionfield, type the syntax for the iRule using Tool Command Language (Tcl) syntax.For complete and detailed information iRules syntax, see the F5 Networks DevCentral web sitehttp://devcentral.f5.com.
- ClickFinished.
Examples of iRules for XML content-based routing
This example shows an iRule that queries for an element called
FinanceObject
in XML content and if a match is found, an iRule event
is triggered. The system populates the values of the Tcl variables
($XML_count
, $XML_queries
, and
$XML_values
). Then the system routes traffic to a pool called
finance_pool
.when XML_CONTENT_BASED_ROUTING { for {set i 0} { $i < $XML_count } {incr i} { log local0. $XML_queries($i) log local0. $XML_values($i) if {($XML_queries($i) contains "FinanceObject")} { pool finance_pool } } }
This is another example of XML content-based routing. It shows routing by bank name and by price.
when XML_CONTENT_BASED_ROUTING { for {set i 0} { $i < $XML_count } {incr i} { # routing by BANK_NAME if {($XML_queries($i) contains "BANK_NAME")} { if {($XML_values($i) contains "InternationalBank")} { pool pool1 } elseif {($XML_values($i) contains "Hapoalim")} { pool pool2 } else { pool pool3 } } # routing by PRICE if {($XML_queries($i) contains "PRICE")} { if {($XML_values($i) > 50)} { pool pool1 } else { pool pool2 } } # end for } }
The
XML_CONTENT_BASED_ROUTING
event does not trigger when the client's headers contain "Expect: 100-continue"
regardless of whether the
server sends a 100-continue response. In this case, the request is routed to the default pool.
Tcl variables in iRules for XML routing
This table lists and describes the Tcl variables in the sample iRule.
Tcl variable |
Description |
---|---|
$XML_count |
Shows the number of matching queries. |
$XML_queries |
Contains an array of the matching query names. |
$XML_values |
Holds the values of the matching elements. |
Viewing statistics about XML content-based routing
You can view statistics about XML content-based routing to make sure that the
routing is working.
The system first checks for a match, then checks
for malformedness of XML content. So if the system detects a match, it stops
checking, and might not detect any subsequent parts of the document that are
malformed.
- On the Main tab, click.The Local Traffic statistics screen opens.
- From theStatistics Typelist, selectProfiles Summary.
- In the Global Profile Statistics area, for the Profile TypeXML, clickViewin the Details.The system displays information about the number of XML documents that were inspected, the number of documents that had zero to three matches, and the number of XML documents that were found to be malformed.