<?xml version='1.0' encoding='UTF-8'?>
<rp:ObjectSet xmlns:rp="http://www.soasta.com/services/repository">
  <Object created="2008-02-05T16:49:22.000-05:00" id="2777" lastModified="2008-02-05T16:49:22.000-05:00" name="Extract-scriptSessionId" type="transition" schemaVersion="143" path="/">
    <Body>
      <Transition xmlns="http://www.soasta.com/services/repository">
        <Script language="JavaScript" xmlns="http://www.soasta.com/services/repository">// Get the content of the engine.js file returned from the server.
var dwrEngineJsMessage = $context.currentClip.getChild('engine.js');
var dwrEngineJsBody = dwrEngineJsMessage.getResponse(Message.RESPONSE_HTTP_BODY);

// Extract the scriptSessionId variable from the JavaScript file.
// We are looking for a line similar to the following:
// (example)
// dwr.engine._origScriptSessionId = "E1BA0ED81B186820CE1DD82A7ABAB9DD";
var prefix = 'dwr.engine._origScriptSessionId = "';
var startIndex = dwrEngineJsBody.indexOf(prefix) + prefix.length;
var endIndex = dwrEngineJsBody.indexOf('"', startIndex + 1);
scriptSessionId = dwrEngineJsBody.substring(startIndex, endIndex);

// DWR expects browser to generate a random suffix - 
// this is copied directly from engine.js (see _getScriptSessionId()).
scriptSessionId = scriptSessionId + Math.floor(Math.random() * 1000);

// Write the final result to the log for informational purposes.
$context.result.postMessage($context.result.LEVEL_INFO, 
"Extracted scriptSessionId " + scriptSessionId);

// Set the clip property.
$prop.set("MessageClip", "scriptSessionId", scriptSessionId);
</Script>
      </Transition>
    </Body><BinaryData /><Description /><TipText />
  </Object>
</rp:ObjectSet>

