/**
  * @param Response $response
  *
  * @return string
  */
 protected static function createMessage(Response $response)
 {
     if ($response->getStatusCode() != 400) {
         return '[' . $response->getStatusCode() . '] A HTTP error has occurred: ' . $response->getBody(true);
     }
     $message = 'Some errors occurred:';
     foreach ($response->xml()->error as $error) {
         $message .= PHP_EOL . '[' . (string) $error->code . '] ' . (string) $error->message;
     }
     return $message;
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function xml()
 {
     try {
         $result = $this->response->xml();
     } catch (\Exception $exception) {
         throw GuzzleRestException::createFromException($exception);
     }
     return $result;
 }
Example #3
0
 private function getContent(Response $response)
 {
     if ($response->isContentType('xml')) {
         return $response->xml();
     } elseif ($response->isContentType('audio')) {
         return $response->getBody()->getStream();
     } else {
         return $response->getBody();
     }
 }
Example #4
0
 public function decodeResponse(Response $response)
 {
     $rootElement = dom_import_simplexml($response->xml());
     $doc = $rootElement->ownerDocument;
     $xpath = new DOMXPath($doc);
     $faultElement = $xpath->query("/methodResponse/fault");
     if ($faultElement->length > 0) {
         $errorCodeList = $xpath->query("/methodResponse/fault[1]/value[1]/struct[1]/member[name='faultCode']/value/int");
         $errorMessageList = $xpath->query("/methodResponse/fault[1]/value[1]/struct[1]/member[name='faultString']/value/string");
         $errorCode = $errorCodeList->length > 0 ? (int) $errorCodeList->item(0)->nodeValue : null;
         $errorMessage = $errorMessageList->length > 0 ? (string) $errorMessageList->item(0)->nodeValue : "";
         throw new RpcErrorException($errorMessage, $errorCode);
     }
     if (($params = $xpath->evaluate("/methodResponse/params/param")) instanceof DomNodeList && $params->length > 0) {
         $results = array();
         foreach ($params as $paramElement) {
             $results[] = $this->parameterDeserializer->getValueFromDomElement($paramElement);
         }
         return $results;
     }
     throw new RpcNoResultException();
 }
Example #5
0
 /**
  * @covers Guzzle\Http\Message\Response::xml
  * @expectedException \Guzzle\Common\Exception\RuntimeException
  * @expectedExceptionMessage Unable to parse response body into XML: String could not be parsed as XML
  */
 public function testThrowsExceptionWhenFailsToParseXmlResponse()
 {
     $response = new Response(200, array(), '<abc');
     $response->xml();
 }
Example #6
0
 public function testPreventsComplexExternalEntities()
 {
     $xml = '<?xml version="1.0"?><!DOCTYPE scan[<!ENTITY test SYSTEM "php://filter/read=convert.base64-encode/resource=ResponseTest.php">]><scan>&test;</scan>';
     $response = new Response(200, array(), $xml);
     $oldCwd = getcwd();
     chdir(__DIR__);
     try {
         $xml = $response->xml();
         chdir($oldCwd);
         $this->markTestIncomplete('Did not throw the expected exception! XML resolved as: ' . $xml->asXML());
     } catch (\Exception $e) {
         chdir($oldCwd);
     }
 }
 /**
  * @param Response $response
  * @return \SimpleXMLElement
  */
 public static function getContent(Response $response)
 {
     return $response->xml();
 }
 public function __construct(RequestInterface $request, HttpResponse $response)
 {
     parent::__construct($request, $response->xml());
     $this->isSuccessful = $response->isSuccessful();
 }
Example #9
0
 /**
  * @expectedException \Guzzle\Common\Exception\RuntimeException
  */
 public function testPreventsComplexExternalEntities()
 {
     $xml = '<?xml version="1.0"?><!DOCTYPE scan[<!ENTITY test SYSTEM "php://filter/read=convert.base64-encode/resource=ResponseTest.php">]><scan>&test;</scan>';
     $response = new Response(200, array(), $xml);
     $oldCwd = getcwd();
     chdir(__DIR__);
     try {
         $response->xml();
         chdir($oldCwd);
     } catch (\Exception $e) {
         chdir($oldCwd);
         throw $e;
     }
 }