PageRenderTime 54ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/branches/v2.0.0/library/Microsoft/WindowsAzure/Storage/Queue.php

#
PHP | 568 lines | 306 code | 57 blank | 205 comment | 85 complexity | 1d9e1859be3bb109092c7f593d85bb7f MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /**
  3. * Copyright (c) 2009 - 2010, RealDolmen
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are met:
  8. * * Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * * Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * * Neither the name of RealDolmen nor the
  14. * names of its contributors may be used to endorse or promote products
  15. * derived from this software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY RealDolmen ''AS IS'' AND ANY
  18. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  19. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  20. * DISCLAIMED. IN NO EVENT SHALL RealDolmen BE LIABLE FOR ANY
  21. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  22. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  23. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  24. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  26. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. *
  28. * @category Microsoft
  29. * @package Microsoft_WindowsAzure
  30. * @subpackage Storage
  31. * @copyright Copyright (c) 2009 - 2010, RealDolmen (http://www.realdolmen.com)
  32. * @license http://todo name_todo
  33. * @version $Id: Blob.php 24241 2009-07-22 09:43:13Z unknown $
  34. */
  35. /**
  36. * @see Microsoft_WindowsAzure_Credentials_SharedKey
  37. */
  38. require_once 'Microsoft/WindowsAzure/Credentials/SharedKey.php';
  39. /**
  40. * @see Microsoft_WindowsAzure_RetryPolicy_RetryPolicyAbstract
  41. */
  42. require_once 'Microsoft/WindowsAzure/RetryPolicy/RetryPolicyAbstract.php';
  43. /**
  44. * @see Microsoft_Http_Client
  45. */
  46. require_once 'Microsoft/Http/Client.php';
  47. /**
  48. * @see Microsoft_Http_Response
  49. */
  50. require_once 'Microsoft/Http/Response.php';
  51. /**
  52. * @see Microsoft_WindowsAzure_Storage
  53. */
  54. require_once 'Microsoft/WindowsAzure/Storage.php';
  55. /**
  56. * Microsoft_WindowsAzure_Storage_QueueInstance
  57. */
  58. require_once 'Microsoft/WindowsAzure/Storage/QueueInstance.php';
  59. /**
  60. * Microsoft_WindowsAzure_Storage_QueueMessage
  61. */
  62. require_once 'Microsoft/WindowsAzure/Storage/QueueMessage.php';
  63. /**
  64. * @see Microsoft_WindowsAzure_Exception
  65. */
  66. require_once 'Microsoft/WindowsAzure/Exception.php';
  67. /**
  68. * @category Microsoft
  69. * @package Microsoft_WindowsAzure
  70. * @subpackage Storage
  71. * @copyright Copyright (c) 2009 - 2010, RealDolmen (http://www.realdolmen.com)
  72. * @license http://phpazure.codeplex.com/license
  73. */
  74. class Microsoft_WindowsAzure_Storage_Queue extends Microsoft_WindowsAzure_Storage
  75. {
  76. /**
  77. * Maximal message size (in bytes)
  78. */
  79. const MAX_MESSAGE_SIZE = 8388608;
  80. /**
  81. * Maximal message ttl (in seconds)
  82. */
  83. const MAX_MESSAGE_TTL = 604800;
  84. /**
  85. * Creates a new Microsoft_WindowsAzure_Storage_Queue instance
  86. *
  87. * @param string $host Storage host name
  88. * @param string $accountName Account name for Windows Azure
  89. * @param string $accountKey Account key for Windows Azure
  90. * @param boolean $usePathStyleUri Use path-style URI's
  91. * @param Microsoft_WindowsAzure_RetryPolicy_RetryPolicyAbstract $retryPolicy Retry policy to use when making requests
  92. */
  93. public function __construct($host = Microsoft_WindowsAzure_Storage::URL_DEV_QUEUE, $accountName = Microsoft_WindowsAzure_Credentials_CredentialsAbstract::DEVSTORE_ACCOUNT, $accountKey = Microsoft_WindowsAzure_Credentials_CredentialsAbstract::DEVSTORE_KEY, $usePathStyleUri = false, Microsoft_WindowsAzure_RetryPolicy_RetryPolicyAbstract $retryPolicy = null)
  94. {
  95. parent::__construct($host, $accountName, $accountKey, $usePathStyleUri, $retryPolicy);
  96. // API version
  97. $this->_apiVersion = '2009-09-19';
  98. }
  99. /**
  100. * Check if a queue exists
  101. *
  102. * @param string $queueName Queue name
  103. * @return boolean
  104. */
  105. public function queueExists($queueName = '')
  106. {
  107. if ($queueName === '') {
  108. throw new Microsoft_WindowsAzure_Exception('Queue name is not specified.');
  109. }
  110. if (!self::isValidQueueName($queueName)) {
  111. throw new Microsoft_WindowsAzure_Exception('Queue name does not adhere to queue naming conventions. See http://msdn.microsoft.com/en-us/library/dd179349.aspx for more information.');
  112. }
  113. // List queues
  114. $queues = $this->listQueues($queueName, 1);
  115. foreach ($queues as $queue) {
  116. if ($queue->Name == $queueName) {
  117. return true;
  118. }
  119. }
  120. return false;
  121. }
  122. /**
  123. * Create queue
  124. *
  125. * @param string $queueName Queue name
  126. * @param array $metadata Key/value pairs of meta data
  127. * @return object Queue properties
  128. * @throws Microsoft_WindowsAzure_Exception
  129. */
  130. public function createQueue($queueName = '', $metadata = array())
  131. {
  132. if ($queueName === '') {
  133. throw new Microsoft_WindowsAzure_Exception('Queue name is not specified.');
  134. }
  135. if (!self::isValidQueueName($queueName)) {
  136. throw new Microsoft_WindowsAzure_Exception('Queue name does not adhere to queue naming conventions. See http://msdn.microsoft.com/en-us/library/dd179349.aspx for more information.');
  137. }
  138. // Create metadata headers
  139. $headers = array();
  140. $headers = array_merge($headers, $this->_generateMetadataHeaders($metadata));
  141. // Perform request
  142. $response = $this->_performRequest($queueName, '', Microsoft_Http_Client::PUT, $headers);
  143. if ($response->isSuccessful()) {
  144. return new Microsoft_WindowsAzure_Storage_QueueInstance(
  145. $queueName,
  146. $metadata
  147. );
  148. } else {
  149. throw new Microsoft_WindowsAzure_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
  150. }
  151. }
  152. /**
  153. * Get queue
  154. *
  155. * @param string $queueName Queue name
  156. * @return Microsoft_WindowsAzure_Storage_QueueInstance
  157. * @throws Microsoft_WindowsAzure_Exception
  158. */
  159. public function getQueue($queueName = '')
  160. {
  161. if ($queueName === '') {
  162. throw new Microsoft_WindowsAzure_Exception('Queue name is not specified.');
  163. }
  164. if (!self::isValidQueueName($queueName)) {
  165. throw new Microsoft_WindowsAzure_Exception('Queue name does not adhere to queue naming conventions. See http://msdn.microsoft.com/en-us/library/dd179349.aspx for more information.');
  166. }
  167. // Perform request
  168. $response = $this->_performRequest($queueName, '?comp=metadata', Microsoft_Http_Client::GET);
  169. if ($response->isSuccessful()) {
  170. // Parse metadata
  171. $metadata = $this->_parseMetadataHeaders($response->getHeaders());
  172. // Return queue
  173. $queue = new Microsoft_WindowsAzure_Storage_QueueInstance(
  174. $queueName,
  175. $metadata
  176. );
  177. $queue->ApproximateMessageCount = intval($response->getHeader('x-ms-approximate-message-count'));
  178. return $queue;
  179. } else {
  180. throw new Microsoft_WindowsAzure_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
  181. }
  182. }
  183. /**
  184. * Get queue metadata
  185. *
  186. * @param string $queueName Queue name
  187. * @return array Key/value pairs of meta data
  188. * @throws Microsoft_WindowsAzure_Exception
  189. */
  190. public function getQueueMetadata($queueName = '')
  191. {
  192. if ($queueName === '') {
  193. throw new Microsoft_WindowsAzure_Exception('Queue name is not specified.');
  194. }
  195. if (!self::isValidQueueName($queueName)) {
  196. throw new Microsoft_WindowsAzure_Exception('Queue name does not adhere to queue naming conventions. See http://msdn.microsoft.com/en-us/library/dd179349.aspx for more information.');
  197. }
  198. return $this->getQueue($queueName)->Metadata;
  199. }
  200. /**
  201. * Set queue metadata
  202. *
  203. * Calling the Set Queue Metadata operation overwrites all existing metadata that is associated with the queue. It's not possible to modify an individual name/value pair.
  204. *
  205. * @param string $queueName Queue name
  206. * @param array $metadata Key/value pairs of meta data
  207. * @throws Microsoft_WindowsAzure_Exception
  208. */
  209. public function setQueueMetadata($queueName = '', $metadata = array())
  210. {
  211. if ($queueName === '') {
  212. throw new Microsoft_WindowsAzure_Exception('Queue name is not specified.');
  213. }
  214. if (!self::isValidQueueName($queueName)) {
  215. throw new Microsoft_WindowsAzure_Exception('Queue name does not adhere to queue naming conventions. See http://msdn.microsoft.com/en-us/library/dd179349.aspx for more information.');
  216. }
  217. if (count($metadata) == 0) {
  218. return;
  219. }
  220. // Create metadata headers
  221. $headers = array();
  222. $headers = array_merge($headers, $this->_generateMetadataHeaders($metadata));
  223. // Perform request
  224. $response = $this->_performRequest($queueName, '?comp=metadata', Microsoft_Http_Client::PUT, $headers);
  225. if (!$response->isSuccessful()) {
  226. throw new Microsoft_WindowsAzure_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
  227. }
  228. }
  229. /**
  230. * Delete queue
  231. *
  232. * @param string $queueName Queue name
  233. * @throws Microsoft_WindowsAzure_Exception
  234. */
  235. public function deleteQueue($queueName = '')
  236. {
  237. if ($queueName === '') {
  238. throw new Microsoft_WindowsAzure_Exception('Queue name is not specified.');
  239. }
  240. if (!self::isValidQueueName($queueName)) {
  241. throw new Microsoft_WindowsAzure_Exception('Queue name does not adhere to queue naming conventions. See http://msdn.microsoft.com/en-us/library/dd179349.aspx for more information.');
  242. }
  243. // Perform request
  244. $response = $this->_performRequest($queueName, '', Microsoft_Http_Client::DELETE);
  245. if (!$response->isSuccessful()) {
  246. throw new Microsoft_WindowsAzure_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
  247. }
  248. }
  249. /**
  250. * List queues
  251. *
  252. * @param string $prefix Optional. Filters the results to return only queues whose name begins with the specified prefix.
  253. * @param int $maxResults Optional. Specifies the maximum number of queues to return per call to Azure storage. This does NOT affect list size returned by this function. (maximum: 5000)
  254. * @param string $marker Optional string value that identifies the portion of the list to be returned with the next list operation.
  255. * @param string $include Optional. Include this parameter to specify that the queue's metadata be returned as part of the response body. (allowed values: '', 'metadata')
  256. * @param int $currentResultCount Current result count (internal use)
  257. * @return array
  258. * @throws Microsoft_WindowsAzure_Exception
  259. */
  260. public function listQueues($prefix = null, $maxResults = null, $marker = null, $include = null, $currentResultCount = 0)
  261. {
  262. // Build query string
  263. $queryString = array('comp=list');
  264. if (!is_null($prefix)) {
  265. $queryString[] = 'prefix=' . $prefix;
  266. }
  267. if (!is_null($maxResults)) {
  268. $queryString[] = 'maxresults=' . $maxResults;
  269. }
  270. if (!is_null($marker)) {
  271. $queryString[] = 'marker=' . $marker;
  272. }
  273. if (!is_null($include)) {
  274. $queryString[] = 'include=' . $include;
  275. }
  276. $queryString = self::createQueryStringFromArray($queryString);
  277. // Perform request
  278. $response = $this->_performRequest('', $queryString, Microsoft_Http_Client::GET);
  279. if ($response->isSuccessful()) {
  280. $xmlQueues = $this->_parseResponse($response)->Queues->Queue;
  281. $xmlMarker = (string)$this->_parseResponse($response)->NextMarker;
  282. $queues = array();
  283. if (!is_null($xmlQueues)) {
  284. for ($i = 0; $i < count($xmlQueues); $i++) {
  285. $queues[] = new Microsoft_WindowsAzure_Storage_QueueInstance(
  286. (string)$xmlQueues[$i]->Name,
  287. $this->_parseMetadataElement($xmlQueues[$i])
  288. );
  289. }
  290. }
  291. $currentResultCount = $currentResultCount + count($queues);
  292. if (!is_null($maxResults) && $currentResultCount < $maxResults) {
  293. if (!is_null($xmlMarker) && $xmlMarker != '') {
  294. $queues = array_merge($queues, $this->listQueues($prefix, $maxResults, $xmlMarker, $include, $currentResultCount));
  295. }
  296. }
  297. if (!is_null($maxResults) && count($queues) > $maxResults) {
  298. $queues = array_slice($queues, 0, $maxResults);
  299. }
  300. return $queues;
  301. } else {
  302. throw new Microsoft_WindowsAzure_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
  303. }
  304. }
  305. /**
  306. * Put message into queue
  307. *
  308. * @param string $queueName Queue name
  309. * @param string $message Message
  310. * @param int $ttl Message Time-To-Live (in seconds). Defaults to 7 days if the parameter is omitted.
  311. * @throws Microsoft_WindowsAzure_Exception
  312. */
  313. public function putMessage($queueName = '', $message = '', $ttl = null)
  314. {
  315. if ($queueName === '') {
  316. throw new Microsoft_WindowsAzure_Exception('Queue name is not specified.');
  317. }
  318. if (!self::isValidQueueName($queueName)) {
  319. throw new Microsoft_WindowsAzure_Exception('Queue name does not adhere to queue naming conventions. See http://msdn.microsoft.com/en-us/library/dd179349.aspx for more information.');
  320. }
  321. if (strlen($message) > self::MAX_MESSAGE_SIZE) {
  322. throw new Microsoft_WindowsAzure_Exception('Message is too big. Message content should be < 8KB.');
  323. }
  324. if ($message == '') {
  325. throw new Microsoft_WindowsAzure_Exception('Message is not specified.');
  326. }
  327. if (!is_null($ttl) && ($ttl <= 0 || $ttl > self::MAX_MESSAGE_SIZE)) {
  328. throw new Microsoft_WindowsAzure_Exception('Message TTL is invalid. Maximal TTL is 7 days (' . self::MAX_MESSAGE_SIZE . ' seconds) and should be greater than zero.');
  329. }
  330. // Build query string
  331. $queryString = array();
  332. if (!is_null($ttl)) {
  333. $queryString[] = 'messagettl=' . $ttl;
  334. }
  335. $queryString = self::createQueryStringFromArray($queryString);
  336. // Build body
  337. $rawData = '';
  338. $rawData .= '<QueueMessage>';
  339. $rawData .= ' <MessageText>' . base64_encode($message) . '</MessageText>';
  340. $rawData .= '</QueueMessage>';
  341. // Perform request
  342. $response = $this->_performRequest($queueName . '/messages', $queryString, Microsoft_Http_Client::POST, array(), false, $rawData);
  343. if (!$response->isSuccessful()) {
  344. throw new Microsoft_WindowsAzure_Exception('Error putting message into queue.');
  345. }
  346. }
  347. /**
  348. * Get queue messages
  349. *
  350. * @param string $queueName Queue name
  351. * @param string $numOfMessages Optional. A nonzero integer value that specifies the number of messages to retrieve from the queue, up to a maximum of 32. By default, a single message is retrieved from the queue with this operation.
  352. * @param int $visibilityTimeout Optional. An integer value that specifies the message's visibility timeout in seconds. The maximum value is 2 hours. The default message visibility timeout is 30 seconds.
  353. * @param string $peek Peek only?
  354. * @return array
  355. * @throws Microsoft_WindowsAzure_Exception
  356. */
  357. public function getMessages($queueName = '', $numOfMessages = 1, $visibilityTimeout = null, $peek = false)
  358. {
  359. if ($queueName === '') {
  360. throw new Microsoft_WindowsAzure_Exception('Queue name is not specified.');
  361. }
  362. if (!self::isValidQueueName($queueName)) {
  363. throw new Microsoft_WindowsAzure_Exception('Queue name does not adhere to queue naming conventions. See http://msdn.microsoft.com/en-us/library/dd179349.aspx for more information.');
  364. }
  365. if ($numOfMessages < 1 || $numOfMessages > 32 || intval($numOfMessages) != $numOfMessages) {
  366. throw new Microsoft_WindowsAzure_Exception('Invalid number of messages to retrieve.');
  367. }
  368. if (!is_null($visibilityTimeout) && ($visibilityTimeout <= 0 || $visibilityTimeout > 7200)) {
  369. throw new Microsoft_WindowsAzure_Exception('Visibility timeout is invalid. Maximum value is 2 hours (7200 seconds) and should be greater than zero.');
  370. }
  371. // Build query string
  372. $queryString = array();
  373. if ($peek) {
  374. $queryString[] = 'peekonly=true';
  375. }
  376. if ($numOfMessages > 1) {
  377. $queryString[] = 'numofmessages=' . $numOfMessages;
  378. }
  379. if (!$peek && !is_null($visibilityTimeout)) {
  380. $queryString[] = 'visibilitytimeout=' . $visibilityTimeout;
  381. }
  382. $queryString = self::createQueryStringFromArray($queryString);
  383. // Perform request
  384. $response = $this->_performRequest($queueName . '/messages', $queryString, Microsoft_Http_Client::GET);
  385. if ($response->isSuccessful()) {
  386. // Parse results
  387. $result = $this->_parseResponse($response);
  388. if (!$result) {
  389. return array();
  390. }
  391. $xmlMessages = null;
  392. if (count($result->QueueMessage) > 1) {
  393. $xmlMessages = $result->QueueMessage;
  394. } else {
  395. $xmlMessages = array($result->QueueMessage);
  396. }
  397. $messages = array();
  398. for ($i = 0; $i < count($xmlMessages); $i++) {
  399. $messages[] = new Microsoft_WindowsAzure_Storage_QueueMessage(
  400. (string)$xmlMessages[$i]->MessageId,
  401. (string)$xmlMessages[$i]->InsertionTime,
  402. (string)$xmlMessages[$i]->ExpirationTime,
  403. ($peek ? '' : (string)$xmlMessages[$i]->PopReceipt),
  404. ($peek ? '' : (string)$xmlMessages[$i]->TimeNextVisible),
  405. (string)$xmlMessages[$i]->DequeueCount,
  406. base64_decode((string)$xmlMessages[$i]->MessageText)
  407. );
  408. }
  409. return $messages;
  410. } else {
  411. throw new Microsoft_WindowsAzure_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
  412. }
  413. }
  414. /**
  415. * Peek queue messages
  416. *
  417. * @param string $queueName Queue name
  418. * @param string $numOfMessages Optional. A nonzero integer value that specifies the number of messages to retrieve from the queue, up to a maximum of 32. By default, a single message is retrieved from the queue with this operation.
  419. * @return array
  420. * @throws Microsoft_WindowsAzure_Exception
  421. */
  422. public function peekMessages($queueName = '', $numOfMessages = 1)
  423. {
  424. return $this->getMessages($queueName, $numOfMessages, null, true);
  425. }
  426. /**
  427. * Clear queue messages
  428. *
  429. * @param string $queueName Queue name
  430. * @throws Microsoft_WindowsAzure_Exception
  431. */
  432. public function clearMessages($queueName = '')
  433. {
  434. if ($queueName === '') {
  435. throw new Microsoft_WindowsAzure_Exception('Queue name is not specified.');
  436. }
  437. if (!self::isValidQueueName($queueName)) {
  438. throw new Microsoft_WindowsAzure_Exception('Queue name does not adhere to queue naming conventions. See http://msdn.microsoft.com/en-us/library/dd179349.aspx for more information.');
  439. }
  440. // Perform request
  441. $response = $this->_performRequest($queueName . '/messages', '', Microsoft_Http_Client::DELETE);
  442. if (!$response->isSuccessful()) {
  443. throw new Microsoft_WindowsAzure_Exception('Error clearing messages from queue.');
  444. }
  445. }
  446. /**
  447. * Delete queue message
  448. *
  449. * @param string $queueName Queue name
  450. * @param Microsoft_WindowsAzure_Storage_QueueMessage $message Message to delete from queue. A message retrieved using "peekMessages" can NOT be deleted!
  451. * @throws Microsoft_WindowsAzure_Exception
  452. */
  453. public function deleteMessage($queueName = '', Microsoft_WindowsAzure_Storage_QueueMessage $message)
  454. {
  455. if ($queueName === '') {
  456. throw new Microsoft_WindowsAzure_Exception('Queue name is not specified.');
  457. }
  458. if (!self::isValidQueueName($queueName)) {
  459. throw new Microsoft_WindowsAzure_Exception('Queue name does not adhere to queue naming conventions. See http://msdn.microsoft.com/en-us/library/dd179349.aspx for more information.');
  460. }
  461. if ($message->PopReceipt == '') {
  462. throw new Microsoft_WindowsAzure_Exception('A message retrieved using "peekMessages" can NOT be deleted! Use "getMessages" instead.');
  463. }
  464. // Perform request
  465. $response = $this->_performRequest($queueName . '/messages/' . $message->MessageId, '?popreceipt=' . $message->PopReceipt, Microsoft_Http_Client::DELETE);
  466. if (!$response->isSuccessful()) {
  467. throw new Microsoft_WindowsAzure_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
  468. }
  469. }
  470. /**
  471. * Is valid queue name?
  472. *
  473. * @param string $queueName Queue name
  474. * @return boolean
  475. */
  476. public static function isValidQueueName($queueName = '')
  477. {
  478. if (preg_match("/^[a-z0-9][a-z0-9-]*$/", $queueName) === 0) {
  479. return false;
  480. }
  481. if (strpos($queueName, '--') !== false) {
  482. return false;
  483. }
  484. if (strtolower($queueName) != $queueName) {
  485. return false;
  486. }
  487. if (strlen($queueName) < 3 || strlen($queueName) > 63) {
  488. return false;
  489. }
  490. if (substr($queueName, -1) == '-') {
  491. return false;
  492. }
  493. return true;
  494. }
  495. /**
  496. * Get error message from Microsoft_Http_Response
  497. *
  498. * @param Microsoft_Http_Response $response Repsonse
  499. * @param string $alternativeError Alternative error message
  500. * @return string
  501. */
  502. protected function _getErrorMessage(Microsoft_Http_Response $response, $alternativeError = 'Unknown error.')
  503. {
  504. $response = $this->_parseResponse($response);
  505. if ($response && $response->Message) {
  506. return (string)$response->Message;
  507. } else {
  508. return $alternativeError;
  509. }
  510. }
  511. }