Showing results for 
Search instead for 
Did you mean: 

HowTo: Inspect XML and route requests

This snippet of TrafficScript illustrates how to use a Request rule to route requests based on the contents of a field in an XML document.


This is the solution to a request from a version 3.1 evaluator.


# Only do this for HTTP POSTs...  
if( http.getMethod() != "POST" ) break;  
$body = http.getBody();  
$source = xml.xpath.matchNodeSet( $body, "", "//Source/text()" );  
# This sets $source to be  
# "/dvrti1RTIDocRoot/portal2/60097.48806.65101.44299/8.pdf"  
if( string.contains( $source, "/portal2/" ) ) {  
   pool.use( "portal2 pool" );  
} else if( string.contains( $source, "/qa3x/" ) ) {  
   pool.use( "qa3x pool" );  


For reference, the original XML request looked something like: - See more at:


POST / HTTP/1.1  
Content-Type: text/xml; charset=UTF-8  
SOAPAction: "urnSmiley TongueartnerAPICallbackOnSynchronizeNotesAction"  
Content-length: 1296  
<E:Envelope xmlns:E=""   
  <mSmiley SurprisednSynchronizeNotes xmlns:m="urnSmiley TongueartnerAPI">  
  <HostSessionID s:type="y:string">123</HostSessionID>  
  <Source s:type="y:string">  
  <Notes s:type="mSmiley SurprisedperatedNotesList" A:arrayType="mSmiley SurprisedperatedNote[1]">  
  <Ver s:type="y:int">1</Ver>  
  <Operation s:type="mSmiley SurprisedperationCode">added</Operation>  
  <Id s:type="y:int">1</Id>  
  <Page s:type="y:int">1</Page>  
  <Type s:type="m:NoteType">Text</Type>  
  <Time s:type="y:dateTime">2005-04-06T21:49:03Z</Time>  
  <CTime s:type="y:dateTime">2005-04-06T21:49:03Z</CTime>  
  <Author s:type="m:NoteAuthor">  
  <F s:type="y:string">John</F>  
  <L s:type="y:string">Reviewer1</L>  
  <Aid s:type="y:string">User01</Aid>  
  <Anchor s:type="m:WPoint">  
  <Xcoord s:type="y:float">2378.3252</Xcoord>  
  <Ycoord s:type="y:float">2948.76855</Ycoord>  
  <PageSize s:type="m:WSize">  
  <Xsize s:type="y:float">20400</Xsize>  
  <Ysize s:type="y:float">13200</Ysize>  
  <Text s:type="y:string">test callback</Text>  
  </mSmiley SurprisednSynchronizeNotes>  


Version history
Revision #:
1 of 1
Last update:
‎02-24-2013 07:47:AM
Updated by:
Labels (1)