public function doPost() { error_log("GadgetDataServlet received POST request."); $requestParam = isset($_POST['request']) ? $_POST['request'] : ''; $token = isset($_POST['st']) ? $_POST['st'] : ''; // detect if magic quotes are on, and if so strip them from the request if (get_magic_quotes_gpc()) { $requestParam = stripslashes($requestParam); } $request = json_decode($requestParam, true); error_log("Request was:\n" . implode(",", $request)); if ($request == $requestParam) { // oddly enough if the json_decode function can't parse the code, // it just returns the original string (instead of something usefull like 'null' or false :)) error_log("Invalid request JSON"); throw new Exception("Invalid request JSON"); } try { $response = new DataResponse($this->createResponse($requestParam, $token)); } catch (Exception $e) { error_log("ERROR " . $e); $response = new DataResponse(false, BAD_REQUEST); } // // Build assoc arrays for JSON encoding // foreach ($response->getResponses() as $arryResponses ){ // foreach ($arryResponses as $aRespItem ){ // $assocJsonResponses[]=$aRespItem; // } // } error_log("There were " . sizeof($response->getResponses())) . " fields in the response."; $arryResponses['responses'] = $response->getResponses(); $reponse1 = json_encode($arryResponses); error_log("Response was:\n " . $reponse1); echo $reponse1; }
public function HandleData() { $dataRep = new DataResponse(); if ($this->uriCount === 1) { $data = $dataRep->getUserName($this->uris[0]); return $data; } elseif ($this->uriCount === 2) { $data = $dataRep->getUserProfile($this->uris[0], $this->uris[1]); return $data; } }
public function parseResponse(DataResponse $response) { // this parser doesn't depend on any internal state, so never re-parse if ($this->features) { return $this->features; } $this->dbfParser = new DBase3FileParser(); $this->mapProjector = new MapProjector(); if ($response->getContext('zipped')) { $content = $response->getResponse(); foreach ($content as $filename => $fileData) { $this->setContents($fileData['shp']); $this->dbfParser->setContents($fileData['dbf']); $this->dbfParser->setup(); $this->projection = isset($fileData['projection']) ? $fileData['projection'] : null; $this->mapProjector->setSrcProj($this->projection); $this->doParse(); } } else { $this->projection = $response->getContext('projection'); $this->mapProjector->setSrcProj($this->projection); $this->setFilename($response->getContext('shp')); $this->dbfParser->setFilename($response->getContext('dbf')); $this->dbfParser->setup(); $this->doParse(); } return $this->features; }
/** * 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; } }
/** * 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; }
public function parseResponse(DataResponse $response) { if ($authority = $response->getContext('authority')) { $this->authority = $authority; } return parent::parseResponse($response); }
public function parseResponse(DataResponse $response) { $data = $response->getResponse(); return $this->parseData($data); }
protected function initResponse() { $response = DataResponse::factory($this->DEFAULT_RESPONSE_CLASS, $this->initArgs); foreach ($this->context as $var => $value) { $response->setContext($var, $value); } return $response; }
public function parseResponse(DataResponse $response) { $data = $response->getResponse(); if (!is_resource($data) || get_resource_type($data) != 'ldap result') { return false; } $ds = $response->getContext('ldap'); $fieldMap = $response->getContext('fieldMap'); $parsedData = $this->parseSearch($data, $ds, $fieldMap); if ($this->getOption('action') == 'user') { $parsedData = isset($parsedData[0]) ? $parsedData[0] : false; $this->setTotalItems($parsedData ? 1 : 0); } else { $this->setTotalItems(count($parsedData)); } return $parsedData; }