diff --git a/local/config/vufind/DAIA.ini b/local/config/vufind/DAIA.ini index 3a150edfdc5983cec615ee47f4612194b09d9f5a..de3128e33a18ec962a31ac7087ef1aeaba4044b4 100644 --- a/local/config/vufind/DAIA.ini +++ b/local/config/vufind/DAIA.ini @@ -19,6 +19,11 @@ ;baseUrl = http://139.18.19.238:9080/daialibero/daia/ ;baseUrl = http://139.18.19.238:9080/daiatheca/daia/ +; Set a DAIA specific timeout in seconds to be used for DAIA http requests (defaults +; to Zend defaults or as defined in +; vendor/vufind-org/vufindhttp/src/VuFindHttp/HttpService.php) +;timeout = 30 + ; The prefix prepended to the VuFind record Id resulting in the document URI ; used for the DAIA request (default = ppn:) (the prefix usually defines the ; field which the DAIA server uses for the loookup - e.g. ppn: or isbn:). diff --git a/local/config/vufind/FincILS.ini b/local/config/vufind/FincILS.ini index 6d1c95cf9c4f2464f1106c2c279bba3da55bd4d8..d6a9eb5cf111e24fdc2368c7817989dc22f4c816 100644 --- a/local/config/vufind/FincILS.ini +++ b/local/config/vufind/FincILS.ini @@ -72,6 +72,11 @@ queryIls[] = 'getAccessFacet:Local Holdings' ; baseUrl = http://139.18.19.238:9080/paiatheca/paia/ISIL/ ; baseUrl = http://139.18.19.238:9080/paiawachtl/paia/{ISIL/LiberoDBId}/ +; Set a PAIA specific timeout in seconds to be used for PAIA http requests (defaults +; to Zend defaults or as defined in +; vendor/vufind-org/vufindhttp/src/VuFindHttp/HttpService.php) +;timeout = 30 + ; Enable caching for PAIA items (default is false). ;paiaCache = false diff --git a/module/finc/src/finc/ILS/Driver/DAIA.php b/module/finc/src/finc/ILS/Driver/DAIA.php index 034697f0d63d6e83e22c1891546f02de8807ee64..05327be762fc2c2c1996507e66117bb1ae10dfe8 100644 --- a/module/finc/src/finc/ILS/Driver/DAIA.php +++ b/module/finc/src/finc/ILS/Driver/DAIA.php @@ -46,6 +46,13 @@ use VuFind\Exception\ILS as ILSException; */ class DAIA extends \VuFind\ILS\Driver\DAIA { + /** + * Timeout in seconds to be used for DAIA http requests + * + * @var string + */ + protected $daiaTimeout = null; + /** * Flag to switch on/off caching for DAIA items * @@ -65,6 +72,10 @@ class DAIA extends \VuFind\ILS\Driver\DAIA public function init() { parent::init(); + // use DAIA specific timeout setting for http requests if configured + if ((isset($this->config['DAIA']['timeout']))) { + $this->daiaTimeout = $this->config['DAIA']['timeout']; + } if (isset($this->config['DAIA']['daiaCache'])) { $this->daiaCacheEnabled = $this->config['DAIA']['daiaCache']; } else { @@ -197,6 +208,79 @@ class DAIA extends \VuFind\ILS\Driver\DAIA return $status; } + /** + * Perform an HTTP request. + * + * @param string $id id for query in daia + * + * @return xml or json object + * @throws ILSException + */ + protected function doHTTPRequest($id) + { + $http_headers = [ + 'Content-type: ' . $this->contentTypesRequest[$this->daiaResponseFormat], + 'Accept: ' . $this->contentTypesRequest[$this->daiaResponseFormat], + ]; + + $params = [ + 'id' => $id, + 'format' => $this->daiaResponseFormat, + ]; + + try { + $result = $this->httpService->get( + $this->baseUrl, + $params, $this->daiaTimeout, $http_headers + ); + } catch (\Exception $e) { + throw new ILSException( + 'HTTP request exited with Exception ' . $e->getMessage() . + ' for record: ' . $id + ); + } + + if (!$result->isSuccess()) { + throw new ILSException( + 'HTTP status ' . $result->getStatusCode() . + ' received, retrieving availability information for record: ' . $id + ); + + } + + // check if result matches daiaResponseFormat + if ($this->contentTypesResponse != null) { + if ($this->contentTypesResponse[$this->daiaResponseFormat]) { + $contentTypesResponse = array_map( + 'trim', + explode( + ',', + $this->contentTypesResponse[$this->daiaResponseFormat] + ) + ); + list($responseMediaType) = array_pad( + explode( + ';', + $result->getHeaders()->get('ContentType')->getFieldValue(), + 2 + ), + 2, + null + ); // workaround to avoid notices if encoding is not set in header + if (!in_array(trim($responseMediaType), $contentTypesResponse)) { + throw new ILSException( + 'DAIA-ResponseFormat not supported. Received: ' . + $responseMediaType . ' - ' . + 'Expected: ' . + $this->contentTypesResponse[$this->daiaResponseFormat] + ); + } + } + } + + return ($result->getBody()); + } + /** * Parse an array with DAIA status information. * diff --git a/module/finc/src/finc/ILS/Driver/PAIA.php b/module/finc/src/finc/ILS/Driver/PAIA.php index d5bc66a34226b774e0ccccb7f361327b7829918c..978b8eafccce7d52121fc6475356bc0ec33bfc5b 100644 --- a/module/finc/src/finc/ILS/Driver/PAIA.php +++ b/module/finc/src/finc/ILS/Driver/PAIA.php @@ -57,6 +57,13 @@ class PAIA extends DAIA */ protected $paiaURL; + /** + * Timeout in seconds to be used for PAIA http requests + * + * @var + */ + protected $paiaTimeout = null; + /** * Flag to switch on/off caching for PAIA items * @@ -135,6 +142,11 @@ class PAIA extends DAIA } $this->paiaURL = $this->config['PAIA']['baseUrl']; + // use PAIA specific timeout setting for http requests if configured + if ((isset($this->config['PAIA']['timeout']))) { + $this->paiaTimeout = $this->config['PAIA']['timeout']; + } + // do we have caching enabled for PAIA if (isset($this->config['PAIA']['paiaCache'])) { $this->paiaCacheEnabled = $this->config['PAIA']['paiaCache']; @@ -1331,7 +1343,7 @@ class PAIA extends DAIA $this->paiaURL . $file, $postData, 'application/json; charset=UTF-8', - null, + $this->paiaTimeout, $http_headers ); } catch (\Exception $e) { @@ -1368,7 +1380,7 @@ class PAIA extends DAIA try { $result = $this->httpService->get( $this->paiaURL . $file, - [], null, $http_headers + [], $this->paiaTimeout, $http_headers ); } catch (\Exception $e) { throw new ILSException($e->getMessage());