vADC Docs

HowTo: Inspect XML and route requests

by on ‎02-24-2013 07:47 AM - edited on ‎06-10-2015 10:10 AM by PaulWallace (1,692 Views)

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: https://splash.riverbed.com/docs/DOC-1542#sthash.l9nEpuLc.dpuf

 

POST / HTTP/1.1  
Host: portal.customer.com  
Content-Type: text/xml; charset=UTF-8  
SOAPAction: "urnSmiley TongueartnerAPICallbackOnSynchronizeNotesAction"  
Content-length: 1296  
  
<E:Envelope xmlns:E="http://schemas.xmlsoap.org/soap/envelope/"   
  xmlns:A="http://schemas.xmlsoap.org/soap/encoding/"   
  xmlns:s="http://www.w3.org/2001/XMLSchema-instance"   
  xmlns:y="http://www.w3.org/2001/XMLSchema"   
  E:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">  
  <E:Body>  
  <mSmiley SurprisednSynchronizeNotes xmlns:m="urnSmiley TongueartnerAPI">  
  <HostSessionID s:type="y:string">123</HostSessionID>  
  <Source s:type="y:string">  
   /dvrti1RTIDocRoot/portal2/60097.48806.65101.44299/8.pdf  
  </Source>  
  <Notes s:type="mSmiley SurprisedperatedNotesList" A:arrayType="mSmiley SurprisedperatedNote[1]">  
  <item>  
  <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>  
  </Author>  
  <Anchor s:type="m:WPoint">  
  <Xcoord s:type="y:float">2378.3252</Xcoord>  
  <Ycoord s:type="y:float">2948.76855</Ycoord>  
  </Anchor>  
  <PageSize s:type="m:WSize">  
  <Xsize s:type="y:float">20400</Xsize>  
  <Ysize s:type="y:float">13200</Ysize>  
  </PageSize>  
  <Text s:type="y:string">test callback</Text>  
  </item>  
  </Notes>  
  </mSmiley SurprisednSynchronizeNotes>  
  </E:Body>  
</E:Envelope>

 

Contributors