/**
  * Request a ping from a journal.
  *
  * @todo Use the Ping service
  *
  * @param Journal $journal
  *
  * @return bool
  */
 protected function pingJournal(Journal $journal)
 {
     $client = new Client();
     try {
         $response = $client->get($journal->getGatewayUrl());
         if ($response->getStatusCode() !== 200) {
             return false;
         }
         $xml = $response->xml();
         $element = $xml->xpath('//terms')[0];
         if ($element && isset($element['termsAccepted']) && (string) $element['termsAccepted'] === 'yes') {
             return true;
         }
     } catch (RequestException $e) {
         $this->logger->error("Cannot ping {$journal->getUrl()}: {$e->getMessage()}");
         if ($e->hasResponse()) {
             $this->logger->error($e->getResponse()->getStatusCode() . ' ' . $this->logger->error($e->getResponse()->getReasonPhrase()));
         }
     } catch (XmlParseException $e) {
         $this->logger->error("Cannot parse journal ping response {$journal->getUrl()}: {$e->getMessage()}");
     }
     return false;
 }
Esempio n. 2
0
 /**
  * Fetch the service document by HTTP.
  *
  * @param Journal $journal
  *
  * @throws RequestException
  */
 public function serviceDocument(Journal $journal)
 {
     $client = $this->getClient();
     $headers = array('On-Behalf-Of' => $this->serverUuid, 'Journal-Url' => $journal->getUrl());
     try {
         $response = $client->get($this->sdIri, ['headers' => $headers]);
     } catch (RequestException $e) {
         $this->logger->critical($e->getMessage());
         if ($e->hasResponse()) {
             $xml = $e->getResponse()->xml();
             $xml->registerXPathNamespace('atom', 'http://www.w3.org/2005/Atom');
             $this->logger->critical((string) $xml->xpath('//atom:summary')[0]);
         }
         throw $e;
     }
     $xml = new SimpleXMLElement($response->getBody());
     $this->namespaces->registerNamespaces($xml);
     $this->maxUpload = (string) $xml->xpath('sword:maxUploadSize')[0];
     $this->uploadChecksum = (string) $xml->xpath('lom:uploadChecksumType')[0];
     $this->siteName = (string) $xml->xpath('.//atom:title')[0];
     $this->colIri = (string) $xml->xpath('.//app:collection/@href')[0];
 }