<?xml version='1.0' encoding='UTF-8'?>
<rp:ObjectSet xmlns:rp="http://www.soasta.com/services/repository">
  <Object created="2009-04-09T13:11:58.000-07:00" id="678586" lastModified="2009-04-09T13:11:58.000-07:00" type="transition" schemaVersion="222" name="HTTP_Redirection" path="/">
    <Body>
      <Transition xmlns="http://www.soasta.com/services/repository">
        <Script language="JavaScript" xmlns="http://www.soasta.com/services/repository">// This script looks to see if the response code was 302
// if so, it resets the target of the next message
// to use the host name and service path specified by the Location header

// Get the Message that immediately precedes this Script.
var msg = $context.currentItem.previousItem;
var origText = msg.getResponse(msg.RESPONSE_TEXT);

//from the response, determine if this a 302 response
var pos = origText.indexOf("HTTP/1.1 302 Found");
if (pos == -1)
{
   $context.result.postMessage($context.result.LEVEL_INFO, "did not find 302");
}
else
{   
   //now get the value of the location header and then the protocol following
   var firstPos = origText.indexOf("Location: ");
   firstPos = origText.indexOf("http", firstPos + 1);
   
   var lastPos = origText.indexOf("\n", firstPos + 1);
      
   var location =  origText.substring(firstPos, lastPos);
   
   //now we need to separate this into host name and service path
   var doubleSlashPos = location.indexOf("//"); 
   firstSlashPos = location.indexOf("/", doubleSlashPos + 2);
   
   //extract out the host name and the service path from the location
   var hostName    = location.substring(doubleSlashPos + 2, firstSlashPos);
   var servicePath = location.substring(firstSlashPos);
    
   //set the host name and service path for the target of the next message
   $context.currentItem.nextItem.target.systemPropertyList.setPropertyValue("HostName", hostName);
   $context.currentItem.nextItem.target.systemPropertyList.setPropertyValue("ServicePath", servicePath);
}
</Script>
      </Transition>
    </Body><BinaryData /><Description /><TipText />
  </Object>
</rp:ObjectSet>