示例#1
0
 /**
  * Send an NCIP request.
  *
  * @param string $xml XML request document
  *
  * @return object     SimpleXMLElement parsed from response
  */
 protected function sendRequest($xml)
 {
     // Make the NCIP request:
     try {
         $client = new HttpClient();
         $client->setUri($this->config['Catalog']['url']);
         $client->setRawBody($xml);
         $client->setEncType('application/xml; "charset=utf-8"');
         $result = $client->setMethod('POST')->send();
     } catch (\Exception $e) {
         throw new ILSException($e->getMessage());
     }
     if (!$result->isSuccess()) {
         throw new ILSException('HTTP error');
     }
     // Process the NCIP response:
     $response = $result->getBody();
     $result = @simplexml_load_string($response);
     if (is_a($result, 'SimpleXMLElement')) {
         $result->registerXPathNamespace('ns1', 'http://www.niso.org/2008/ncip');
         return $result;
     } else {
         throw new ILSException("Problem parsing XML");
     }
 }
示例#2
0
 /**
  * Support method -- perform an HTTP request.  This will be a GET request unless
  * either $postParams or $rawPost is set to a non-null value.
  *
  * @param string $url        Target URL for request
  * @param array  $postParams Associative array of POST parameters (null for
  * none).
  * @param string $rawPost    String representing raw POST parameters (null for
  * none).
  *
  * @throws ILSException
  * @return string Response body
  */
 protected function httpRequest($url, $postParams = null, $rawPost = null)
 {
     $method = is_null($postParams) && is_null($rawPost) ? 'GET' : 'POST';
     try {
         $client = new HttpClient();
         $client->setUri($url);
         if (is_array($postParams)) {
             $client->setParameterPost($postParams);
         }
         if (!is_null($rawPost)) {
             $client->setRawBody($rawPost);
             $client->setEncType('application/x-www-form-urlencoded');
         }
         $result = $client->setMethod($method)->send();
     } catch (\Exception $e) {
         throw new ILSException($e->getMessage());
     }
     if (!$result->isSuccess()) {
         throw new ILSException('HTTP error');
     }
     return $result->getBody();
 }
示例#3
0
 /**
  * Send a request to the SIRSI side API script and returns the response.
  *
  * @param array $params Associative array of query parameters to send.
  *
  * @return string
  */
 protected function querySirsi($params)
 {
     // make sure null parameters are sent as empty strings instead or else the
     // driver.pl may choke on null parameter values
     foreach ($params as $key => $value) {
         if ($value == null) {
             $params[$key] = '';
         }
     }
     $url = $this->url;
     if (empty($url)) {
         $url = $this->host;
         if ($this->port) {
             $url = "http://" . $url . ":" . $this->port . "/" . $this->search_prog;
         } else {
             $url = "http://" . $url . "/" . $this->search_prog;
         }
     }
     $httpClient = new HttpClient();
     $httpClient->setMethod('POST');
     $httpClient->setUri($url);
     $httpClient->setRawBody(http_build_query($params));
     $httpClient->setEncType('application/x-www-form-urlencoded');
     // use HTTP POST so parameters like user id and PIN are NOT logged by web
     // servers
     $result = $httpClient->send();
     // Even if we get a response, make sure it's a 'good' one.
     if (!$result->isSuccess()) {
         throw new ILSException("Error response code received from {$url}");
     }
     // get the response data
     $response = $result->getBody();
     return rtrim($response);
 }
示例#4
0
 /**
  * Make Request
  *
  * Makes a request to the Voyager Restful API
  *
  * @param array  $hierarchy Array of key-value pairs to embed in the URL path of
  * the request (set value to false to inject a non-paired value).
  * @param array  $params    A keyed array of query data
  * @param string $mode      The http request method to use (Default of GET)
  * @param string $xml       An optional XML string to send to the API
  *
  * @throws ILSException
  * @return obj  A Simple XML Object loaded with the xml data returned by the API
  */
 protected function makeRequest($hierarchy, $params = false, $mode = "GET", $xml = false)
 {
     // Build Url Base
     $urlParams = "http://{$this->ws_host}:{$this->ws_port}/{$this->ws_app}";
     // Add Hierarchy
     foreach ($hierarchy as $key => $value) {
         $hierarchyString[] = $value !== false ? urlencode($key) . "/" . urlencode($value) : urlencode($key);
     }
     // Add Params
     foreach ($params as $key => $param) {
         $queryString[] = urlencode($key) . "=" . urlencode($param);
     }
     // Build Hierarchy
     $urlParams .= "/" . implode("/", $hierarchyString);
     // Build Params
     $urlParams .= "?" . implode("&", $queryString);
     // Create Proxy Request
     $client = new HttpClient();
     $client->setUri($urlParams);
     // Attach XML if necessary
     if ($xml !== false) {
         $client->setRawBody($xml);
     }
     // Send Request and Retrieve Response
     $result = $client->setMethod($mode)->send();
     if (!$result->isSuccess()) {
         throw new ILSException('Problem with RESTful API.');
     }
     $xmlResponse = $result->getBody();
     $oldLibXML = libxml_use_internal_errors();
     libxml_use_internal_errors(true);
     $simpleXML = simplexml_load_string($xmlResponse);
     libxml_use_internal_errors($oldLibXML);
     if ($simpleXML === false) {
         return false;
     }
     return $simpleXML;
 }