SaveRequest(); // turn this on if debugging needed $DEBUG_AGENT = 0; // amount of time in seconds to sleep/debug $SLEEP_SECS = 20; // Useful for debugging if ($DEBUG_AGENT) sleep($SLEEP_SECS); // Initialize web tier with the site configuration file. InitializeWebTier(); // Create a request object $hreq = new MgHttpRequest(); // Get access to the header collection $hdr = $hreq->GetHeader(); // Get access to request parameter collection $reqParam = $hreq->GetRequestParam(); // Get access to request metadata collection $reqMd = $hreq->GetRequestMetadata(); // Fill all header variables setHeader($hdr); // Fill request parameters setRequestParameters($reqParam); // Fill request metadata setRequestMetadata($reqMd); // Custom action before executing the request beforeExecute($hreq); // Execute the request and return response $hresp = $hreq->Execute(); // Custom action after execute if(!afterExecute($hreq, $hresp)) { // no custom actions, send stream to client $statusCode = $hresp->GetStatusCode(); if($statusCode != 200) { $shortError = $hresp->GetHttpErrorMessage(); $longError = $hresp->GetErrorMessage(); header("HTTP/1.1 {$statusCode} {$shortError}"); header("Status: {$statusCode} {$shortError}"); echo "\n\n"; echo "

{$shortError}

\n{$longError}"; echo "\n\n"; } else { // Dump all headers before sending data $header = $hresp->GetHeader(); if ($header != null) { $headerLines = $header->GetHeaderNames(); // TODO: PHP collection semantics do not work on our collections. // We should try to address this so that the following will work // foreach ($headerLines as $headerLine) $hdrCount = $headerLines->GetCount(); for ($hdrNum = 0; $hdrNum < $hdrCount; $hdrCount++) { $headerLine = $headerLines->GetItem($hdrNum); $headerValue = $header->GetHeaderValue($headerLine); header("{$headerLine}: {$headerValue}"); } } // adds the content type specific to this response $contentType = $hresult->GetResultContentType(); if (strlen($contentType)>0) { header("Content-type: " . $contentType); } $result = $hresp->GetResult(); $resultObj = $result->GetResultObject(); $byteReader = null; if ($resultObj instanceof MgByteReader) { $byteReader = $resultObj; } else if ($resultObj instanceof MgFeatureReader) { $byteReader = $resultObj->ToXml(); } else if ($resultObj instanceof MgStringCollection) { $byteReader = $resultObj->ToXml(); } else if ($resultObj instanceof MgSqlDataReader) { $byteReader = $resultObj->ToXml(); } else if ($resultObj instanceof MgDataReader) { $byteReader = $resultObj->ToXml(); } else if ($resultObj instanceof MgSpatialContextReader) { $byteReader = $resultObj->ToXml(); } else if ($resultObj instanceof MgLongTransactionReader) { $byteReader = $resultObj->ToXml(); } else if ($resultObj instanceof MgHttpPrimitiveValue) { $str = $resultObj->ToString(); echo $str; } if ($byteReader != null) { // Set content length header header("Content-Length:".$byteReader->GetLength()); $len = 0; $val = ""; $len = $byteReader->Read($val, 4096); while ($len > 0) { echo $val; ob_flush(); flush();s $len = $byteReader->Read($val, 4096); } } } } // Flush output buffer ob_end_flush(); ?>