/**
  * Retrieves the data using the given url. The default implementation uses the file_get_content()
  * function to retrieve the request. Subclasses would need to implement this if a simple GET request
  * is not sufficient (i.e. you need POST or custom headers). 
  * @param string the url to retrieve
  * @return string the response from the server
  * @TODO support POST requests and custom headers and perhaps proxy requests
  */
 protected function retrieveData($url)
 {
     if ($this->debugMode) {
         error_log(sprintf(__CLASS__ . " Retrieving %s", $url));
     }
     try {
         if ($this->method == 'GET') {
             $http = phpCAS::getProxiedService(PHPCAS_PROXIED_SERVICE_HTTP_GET);
         } else {
             if ($this->method = 'POST') {
                 $http = phpCAS::getProxiedService(PHPCAS_PROXIED_SERVICE_HTTP_POST);
             } else {
                 throw new Exception('Unsupported HTTP method ' . $this->method);
             }
         }
         $http->setUrl($url);
         // Not yet supported in phpCAS-1.2.2, will be added in a future version.
         //      foreach ($this->getHeaders() as $header) {
         //          $http->addRequestHeader($header);
         //      }
         $http->send();
         $this->response = DataResponse::factory('HTTPDataResponse', array());
         $this->response->setRequest($this->method, $url, $this->filters, $this->requestHeaders);
         $this->response->setResponse($http->getResponseBody(), $http->getResponseHeaders());
         if ($this->debugMode) {
             error_log(sprintf(__CLASS__ . " Returned status %d and %d bytes", $this->getResponseCode(), strlen($data)));
         }
         return $http->getResponseBody();
     } catch (CAS_ProxyTicketException $e) {
         if ($this->debugMode) {
             error_log(__CLASS__ . " The user's proxy ticket expired, prompt for login.");
         }
         // For now we will just re-throw the exception and let the WebModule that
         // is calling us handle prompting for re-authentication.
         throw $e;
     }
 }
Beispiel #2
0
 /**
  * Retrieves the data using the given url. The default implementation uses the file_get_content()
  * function to retrieve the request. Subclasses would need to implement this if a simple GET request
  * is not sufficient (i.e. you need POST or custom headers). 
  * @param string the url to retrieve
  * @return string the response from the server
  * @TODO support POST requests and custom headers and perhaps proxy requests
  */
 protected function retrieveData($url)
 {
     Kurogo::log(LOG_INFO, "Retrieving {$url}", 'data');
     $data = file_get_contents($url, false, $this->streamContext);
     $http_response_header = isset($http_response_header) ? $http_response_header : array();
     $this->response = DataResponse::factory('HTTPDataResponse', array());
     $this->response->setRequest($this->method, $url, $this->filters, $this->requestHeaders);
     $this->response->setResponse($data);
     $this->response->setResponseHeaders($http_response_header);
     Kurogo::log(LOG_DEBUG, sprintf("Returned status %d and %d bytes", $this->getResponseCode(), strlen($data)), 'data');
     return $data;
 }
Beispiel #3
0
 protected function initResponse()
 {
     $response = DataResponse::factory($this->DEFAULT_RESPONSE_CLASS, $this->initArgs);
     foreach ($this->context as $var => $value) {
         $response->setContext($var, $value);
     }
     return $response;
 }