예제 #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 = $this->httpService->createClient($this->config['Catalog']['url']);
         $client->setRawBody($xml);
         $client->setEncType('application/xml; "charset=utf-8"');
         $client->setMethod('POST');
         if (isset($this->timeout)) {
             $client->setOptions(array('timeout' => $this->timeout));
         }
         if (isset($this->config['Catalog']['username']) && isset($this->config['Catalog']['password'])) {
             $user = $this->config['Catalog']['username'];
             $password = $this->config['Catalog']['password'];
             $client->setAuth($user, $password);
         }
         if ($this->hasUntrustedSSL) {
             // Do not verify SSL certificate
             $client->setOptions(array('adapter' => 'Zend\\Http\\Client\\Adapter\\Curl', 'curloptions' => array(CURLOPT_FOLLOWLOCATION => true, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_SSL_VERIFYPEER => false)));
         } elseif (isset($this->cacert)) {
             $client->setOptions(array('adapter' => 'Zend\\Http\\Client\\Adapter\\Curl', 'curloptions' => array(CURLOPT_FOLLOWLOCATION => true, CURLOPT_CAINFO => $this->cacert)));
         }
         $result = $client->send();
     } catch (\Exception $e) {
         $message = $e->getMessage();
         $this->addEnviromentalException($message);
         throw new ILSException($message);
     }
     if (!$result->isSuccess()) {
         $message = 'HTTP error: ' . $result->getContent();
         $this->addEnviromentalException($message);
         throw new ILSException($message);
     }
     // Process the NCIP response:
     $body = $result->getBody();
     $response = @simplexml_load_string($body);
     if (!is_a($response, 'SimpleXMLElement')) {
         $message = "Problem parsing XML";
         $this->addEnviromentalException($message);
         throw new ILSException($message);
     }
     $response->registerXPathNamespace('ns1', 'http://www.niso.org/2008/ncip');
     if ($problem = $this->getProblem($response)) {
         // TODO chcek problem type
         $message = 'Problem recieved in XCNCIP2 Driver .. Content:' . str_replace('\\n', '<br/>', $problem);
         $this->addEnviromentalException($message);
         throw new ILSException($message);
     }
     return $response;
 }
예제 #2
0
 /**
  * Make Ilsdi Request Array
  *
  * Makes a request to the Koha ILSDI API
  *
  * @param string $service     Called function (GetAvailability,
  *                                             GetRecords,
  *                                             GetAuthorityRecords,
  *                                             LookupPatron,
  *                                             AuthenticatePatron,
  *                                             GetPatronInfo,
  *                                             GetPatronStatus,
  *                                             GetServices,
  *                                             RenewLoan,
  *                                             HoldTitle,
  *                                             HoldItem,
  *                                             CancelHold)
  * @param array  $params      Key is parameter name, value is parameter value
  * @param string $http_method HTTP method (default = GET)
  *
  * @throws ILSException
  * @return obj
  */
 protected function makeIlsdiRequest($service, $params, $http_method = "GET")
 {
     $start = microtime(true);
     $url = $this->ilsBaseUrl . "?service=" . $service;
     foreach ($params as $paramname => $paramvalue) {
         $url .= "&{$paramname}=" . urlencode($paramvalue);
     }
     $this->debug("URL: '{$url}'");
     $http_headers = ["Accept: text/xml", "Accept-encoding: plain"];
     try {
         $client = $this->httpService->createClient($url);
         $client->setMethod($http_method);
         $client->setHeaders($http_headers);
         $result = $client->send();
     } catch (\Exception $e) {
         $this->debug("Result is invalid.");
         throw new ILSException($e->getMessage());
     }
     if (!$result->isSuccess()) {
         $this->debug("Result is invalid.");
         throw new ILSException('HTTP error');
     }
     $end = microtime(true);
     $time1 = $end - $start;
     $start = microtime(true);
     $result = simplexml_load_string($result->getBody());
     if (!$result) {
         $this->debug("XML is not valid, URL: {$url}");
         throw new ILSException("XML is not valid, URL: {$url}");
     }
     $end = microtime(true);
     $time2 = $end - $start;
     echo "\t{$time1} - {$time2}";
     return $result;
 }
예제 #3
0
 /**
  * Perform an HTTP request.
  *
  * @param string $url    URL of request
  * @param array  $param  query parameters to add to URL
  * @param string $method HTTP method
  * @param string $body   HTTP body (null for none)
  *
  * @return SimpleXMLElement
  */
 public function doHTTPRequest($url, $params = null, $method = 'GET', $body = null, $headers = array())
 {
     if ($this->debug_enabled) {
         $fullUrl = $this->appendQueryString($url, $params);
         $this->debug("URL: '{$fullUrl}'");
     }
     if ($params == null) {
         $params = array();
     }
     $result = null;
     try {
         if ($method == 'GET') {
             $result = $this->httpService->get($url, $params, $this->timeout, $headers);
         } else {
             if ($method == 'POST') {
                 $url = $this->appendQueryString($url, $params);
                 $result = $this->httpService->post($url, $body, 'application/octet-stream', $this->timeout);
             } else {
                 $url = $this->appendQueryString($url, $params);
                 $client = $this->httpService->createClient($url, $method, $this->timeout);
                 if ($body != null) {
                     $client->setRawBody($body);
                 }
                 $result = $client->send();
             }
         }
     } catch (\Exception $e) {
         throw new ILSException($e->getMessage());
     }
     if (!$result->isSuccess()) {
         throw new ILSException('HTTP error');
     }
     $answer = $result->getBody();
     if ($this->debug_enabled) {
         $this->debug("url: {$url} response: {$answer}");
     }
     $answer = str_replace('xmlns=', 'ns=', $answer);
     $result = simplexml_load_string($answer);
     if (!$result) {
         if ($this->debug_enabled) {
             $this->debug("XML is not valid, URL: {$url}");
         }
         throw new ILSException("XML is not valid, URL: {$url} method: {$method} answer: {$answer}.");
     }
     return $result;
 }