PageRenderTime 58ms CodeModel.GetById 13ms app.highlight 37ms RepoModel.GetById 1ms 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
  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/**
 37 * @see Microsoft_WindowsAzure_Credentials_SharedKey
 38 */
 39require_once 'Microsoft/WindowsAzure/Credentials/SharedKey.php';
 40
 41/**
 42 * @see Microsoft_WindowsAzure_RetryPolicy_RetryPolicyAbstract
 43 */
 44require_once 'Microsoft/WindowsAzure/RetryPolicy/RetryPolicyAbstract.php';
 45
 46/**
 47 * @see Microsoft_Http_Client
 48 */
 49require_once 'Microsoft/Http/Client.php';
 50
 51/**
 52 * @see Microsoft_Http_Response
 53 */
 54require_once 'Microsoft/Http/Response.php';
 55
 56/**
 57 * @see Microsoft_WindowsAzure_Storage
 58 */
 59require_once 'Microsoft/WindowsAzure/Storage.php';
 60
 61/**
 62 * Microsoft_WindowsAzure_Storage_QueueInstance
 63 */
 64require_once 'Microsoft/WindowsAzure/Storage/QueueInstance.php';
 65
 66/**
 67 * Microsoft_WindowsAzure_Storage_QueueMessage
 68 */
 69require_once 'Microsoft/WindowsAzure/Storage/QueueMessage.php';
 70
 71/**
 72 * @see Microsoft_WindowsAzure_Exception
 73 */
 74require_once 'Microsoft/WindowsAzure/Exception.php';
 75
 76
 77/**
 78 * @category   Microsoft
 79 * @package    Microsoft_WindowsAzure
 80 * @subpackage Storage
 81 * @copyright  Copyright (c) 2009 - 2010, RealDolmen (http://www.realdolmen.com)
 82 * @license    http://phpazure.codeplex.com/license
 83 */
 84class Microsoft_WindowsAzure_Storage_Queue extends Microsoft_WindowsAzure_Storage
 85{
 86	/**
 87	 * Maximal message size (in bytes)
 88	 */
 89	const MAX_MESSAGE_SIZE = 8388608;
 90	
 91	/**
 92	 * Maximal message ttl (in seconds)
 93	 */
 94	const MAX_MESSAGE_TTL = 604800;
 95	
 96	/**
 97	 * Creates a new Microsoft_WindowsAzure_Storage_Queue instance
 98	 *
 99	 * @param string $host Storage host name
100	 * @param string $accountName Account name for Windows Azure
101	 * @param string $accountKey Account key for Windows Azure
102	 * @param boolean $usePathStyleUri Use path-style URI's
103	 * @param Microsoft_WindowsAzure_RetryPolicy_RetryPolicyAbstract $retryPolicy Retry policy to use when making requests
104	 */
105	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)
106	{
107		parent::__construct($host, $accountName, $accountKey, $usePathStyleUri, $retryPolicy);
108		
109		// API version
110		$this->_apiVersion = '2009-09-19';
111	}
112	
113	/**
114	 * Check if a queue exists
115	 * 
116	 * @param string $queueName Queue name
117	 * @return boolean
118	 */
119	public function queueExists($queueName = '')
120	{
121		if ($queueName === '') {
122			throw new Microsoft_WindowsAzure_Exception('Queue name is not specified.');
123		}
124		if (!self::isValidQueueName($queueName)) {
125		    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.');
126		}
127			
128		// List queues
129        $queues = $this->listQueues($queueName, 1);
130        foreach ($queues as $queue) {
131            if ($queue->Name == $queueName) {
132                return true;
133            }
134        }
135        
136        return false;
137	}
138	
139	/**
140	 * Create queue
141	 *
142	 * @param string $queueName Queue name
143	 * @param array  $metadata  Key/value pairs of meta data
144	 * @return object Queue properties
145	 * @throws Microsoft_WindowsAzure_Exception
146	 */
147	public function createQueue($queueName = '', $metadata = array())
148	{
149		if ($queueName === '') {
150			throw new Microsoft_WindowsAzure_Exception('Queue name is not specified.');
151		}
152		if (!self::isValidQueueName($queueName)) {
153		    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.');
154		}
155			
156		// Create metadata headers
157		$headers = array();
158		$headers = array_merge($headers, $this->_generateMetadataHeaders($metadata)); 
159		
160		// Perform request
161		$response = $this->_performRequest($queueName, '', Microsoft_Http_Client::PUT, $headers);	
162		if ($response->isSuccessful()) {
163		    return new Microsoft_WindowsAzure_Storage_QueueInstance(
164		        $queueName,
165		        $metadata
166		    );
167		} else {
168			throw new Microsoft_WindowsAzure_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
169		}
170	}
171	
172	/**
173	 * Get queue
174	 * 
175	 * @param string $queueName  Queue name
176	 * @return Microsoft_WindowsAzure_Storage_QueueInstance
177	 * @throws Microsoft_WindowsAzure_Exception
178	 */
179	public function getQueue($queueName = '')
180	{
181		if ($queueName === '') {
182			throw new Microsoft_WindowsAzure_Exception('Queue name is not specified.');
183		}
184		if (!self::isValidQueueName($queueName)) {
185		    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.');
186		}
187		    
188		// Perform request
189		$response = $this->_performRequest($queueName, '?comp=metadata', Microsoft_Http_Client::GET);	
190		if ($response->isSuccessful()) {
191		    // Parse metadata
192		    $metadata = $this->_parseMetadataHeaders($response->getHeaders());
193
194		    // Return queue
195		    $queue = new Microsoft_WindowsAzure_Storage_QueueInstance(
196		        $queueName,
197		        $metadata
198		    );
199		    $queue->ApproximateMessageCount = intval($response->getHeader('x-ms-approximate-message-count'));
200		    return $queue;
201		} else {
202		    throw new Microsoft_WindowsAzure_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
203		}
204	}
205	
206	/**
207	 * Get queue metadata
208	 * 
209	 * @param string $queueName  Queue name
210	 * @return array Key/value pairs of meta data
211	 * @throws Microsoft_WindowsAzure_Exception
212	 */
213	public function getQueueMetadata($queueName = '')
214	{
215		if ($queueName === '') {
216			throw new Microsoft_WindowsAzure_Exception('Queue name is not specified.');
217		}
218		if (!self::isValidQueueName($queueName)) {
219		    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.');
220		}
221			
222	    return $this->getQueue($queueName)->Metadata;
223	}
224	
225	/**
226	 * Set queue metadata
227	 * 
228	 * 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.
229	 *
230	 * @param string $queueName  Queue name
231	 * @param array  $metadata       Key/value pairs of meta data
232	 * @throws Microsoft_WindowsAzure_Exception
233	 */
234	public function setQueueMetadata($queueName = '', $metadata = array())
235	{
236		if ($queueName === '') {
237			throw new Microsoft_WindowsAzure_Exception('Queue name is not specified.');
238		}
239		if (!self::isValidQueueName($queueName)) {
240		    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.');
241		}
242		if (count($metadata) == 0) {
243		    return;
244		}
245		    
246		// Create metadata headers
247		$headers = array();
248		$headers = array_merge($headers, $this->_generateMetadataHeaders($metadata)); 
249		
250		// Perform request
251		$response = $this->_performRequest($queueName, '?comp=metadata', Microsoft_Http_Client::PUT, $headers);
252
253		if (!$response->isSuccessful()) {
254			throw new Microsoft_WindowsAzure_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
255		}
256	}
257	
258	/**
259	 * Delete queue
260	 *
261	 * @param string $queueName Queue name
262	 * @throws Microsoft_WindowsAzure_Exception
263	 */
264	public function deleteQueue($queueName = '')
265	{
266		if ($queueName === '') {
267			throw new Microsoft_WindowsAzure_Exception('Queue name is not specified.');
268		}
269		if (!self::isValidQueueName($queueName)) {
270		    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.');
271		}
272			
273		// Perform request
274		$response = $this->_performRequest($queueName, '', Microsoft_Http_Client::DELETE);
275		if (!$response->isSuccessful()) {
276			throw new Microsoft_WindowsAzure_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
277		}
278	}
279	
280	/**
281	 * List queues
282	 *
283	 * @param string $prefix     Optional. Filters the results to return only queues whose name begins with the specified prefix.
284	 * @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)
285	 * @param string $marker     Optional string value that identifies the portion of the list to be returned with the next list operation.
286	 * @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')
287	 * @param int    $currentResultCount Current result count (internal use)
288	 * @return array
289	 * @throws Microsoft_WindowsAzure_Exception
290	 */
291	public function listQueues($prefix = null, $maxResults = null, $marker = null, $include = null, $currentResultCount = 0)
292	{
293	    // Build query string
294		$queryString = array('comp=list');
295        if (!is_null($prefix)) {
296	        $queryString[] = 'prefix=' . $prefix;
297        }
298	    if (!is_null($maxResults)) {
299	        $queryString[] = 'maxresults=' . $maxResults;
300	    }
301	    if (!is_null($marker)) {
302	        $queryString[] = 'marker=' . $marker;
303	    }
304		if (!is_null($include)) {
305	        $queryString[] = 'include=' . $include;
306	    }
307	    $queryString = self::createQueryStringFromArray($queryString);
308	        
309		// Perform request
310		$response = $this->_performRequest('', $queryString, Microsoft_Http_Client::GET);	
311		if ($response->isSuccessful()) {
312			$xmlQueues = $this->_parseResponse($response)->Queues->Queue;
313			$xmlMarker = (string)$this->_parseResponse($response)->NextMarker;
314
315			$queues = array();
316			if (!is_null($xmlQueues)) {
317				for ($i = 0; $i < count($xmlQueues); $i++) {
318					$queues[] = new Microsoft_WindowsAzure_Storage_QueueInstance(
319						(string)$xmlQueues[$i]->Name,
320						$this->_parseMetadataElement($xmlQueues[$i])
321					);
322				}
323			}
324			$currentResultCount = $currentResultCount + count($queues);
325			if (!is_null($maxResults) && $currentResultCount < $maxResults) {
326    			if (!is_null($xmlMarker) && $xmlMarker != '') {
327    			    $queues = array_merge($queues, $this->listQueues($prefix, $maxResults, $xmlMarker, $include, $currentResultCount));
328    			}
329			}
330			if (!is_null($maxResults) && count($queues) > $maxResults) {
331			    $queues = array_slice($queues, 0, $maxResults);
332			}
333			    
334			return $queues;
335		} else {
336			throw new Microsoft_WindowsAzure_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
337		}
338	}
339	
340	/**
341	 * Put message into queue
342	 *
343	 * @param string $queueName  Queue name
344	 * @param string $message    Message
345	 * @param int    $ttl        Message Time-To-Live (in seconds). Defaults to 7 days if the parameter is omitted.
346	 * @throws Microsoft_WindowsAzure_Exception
347	 */
348	public function putMessage($queueName = '', $message = '', $ttl = null)
349	{
350		if ($queueName === '') {
351			throw new Microsoft_WindowsAzure_Exception('Queue name is not specified.');
352		}
353		if (!self::isValidQueueName($queueName)) {
354		    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.');
355		}
356		if (strlen($message) > self::MAX_MESSAGE_SIZE) {
357		    throw new Microsoft_WindowsAzure_Exception('Message is too big. Message content should be < 8KB.');
358		}
359		if ($message == '') {
360		    throw new Microsoft_WindowsAzure_Exception('Message is not specified.');
361		}
362		if (!is_null($ttl) && ($ttl <= 0 || $ttl > self::MAX_MESSAGE_SIZE)) {
363		    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.');
364		}
365		    
366	    // Build query string
367		$queryString = array();
368        if (!is_null($ttl)) {
369	        $queryString[] = 'messagettl=' . $ttl;
370        }
371	    $queryString = self::createQueryStringFromArray($queryString);
372	        
373	    // Build body
374	    $rawData = '';
375	    $rawData .= '<QueueMessage>';
376	    $rawData .= '    <MessageText>' . base64_encode($message) . '</MessageText>';
377	    $rawData .= '</QueueMessage>';
378	        
379		// Perform request
380		$response = $this->_performRequest($queueName . '/messages', $queryString, Microsoft_Http_Client::POST, array(), false, $rawData);
381
382		if (!$response->isSuccessful()) {
383			throw new Microsoft_WindowsAzure_Exception('Error putting message into queue.');
384		}
385	}
386	
387	/**
388	 * Get queue messages
389	 *
390	 * @param string $queueName         Queue name
391	 * @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.
392	 * @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.
393	 * @param string $peek              Peek only?
394	 * @return array
395	 * @throws Microsoft_WindowsAzure_Exception
396	 */
397	public function getMessages($queueName = '', $numOfMessages = 1, $visibilityTimeout = null, $peek = false)
398	{
399		if ($queueName === '') {
400			throw new Microsoft_WindowsAzure_Exception('Queue name is not specified.');
401		}
402		if (!self::isValidQueueName($queueName)) {
403		    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.');
404		}
405		if ($numOfMessages < 1 || $numOfMessages > 32 || intval($numOfMessages) != $numOfMessages) {
406		    throw new Microsoft_WindowsAzure_Exception('Invalid number of messages to retrieve.');
407		}
408		if (!is_null($visibilityTimeout) && ($visibilityTimeout <= 0 || $visibilityTimeout > 7200)) {
409		    throw new Microsoft_WindowsAzure_Exception('Visibility timeout is invalid. Maximum value is 2 hours (7200 seconds) and should be greater than zero.');
410		}
411		    
412	    // Build query string
413		$queryString = array();
414    	if ($peek) {
415    	    $queryString[] = 'peekonly=true';
416    	}
417    	if ($numOfMessages > 1) {
418	        $queryString[] = 'numofmessages=' . $numOfMessages;
419    	}
420    	if (!$peek && !is_null($visibilityTimeout)) {
421	        $queryString[] = 'visibilitytimeout=' . $visibilityTimeout;
422    	}   
423	    $queryString = self::createQueryStringFromArray($queryString);
424	        
425		// Perform request
426		$response = $this->_performRequest($queueName . '/messages', $queryString, Microsoft_Http_Client::GET);	
427		if ($response->isSuccessful()) {
428		    // Parse results
429			$result = $this->_parseResponse($response);
430		    if (!$result) {
431		        return array();
432		    }
433
434		    $xmlMessages = null;
435		    if (count($result->QueueMessage) > 1) {
436    		    $xmlMessages = $result->QueueMessage;
437    		} else {
438    		    $xmlMessages = array($result->QueueMessage);
439    		}
440
441			$messages = array();
442			for ($i = 0; $i < count($xmlMessages); $i++) {
443				$messages[] = new Microsoft_WindowsAzure_Storage_QueueMessage(
444					(string)$xmlMessages[$i]->MessageId,
445					(string)$xmlMessages[$i]->InsertionTime,
446					(string)$xmlMessages[$i]->ExpirationTime,
447					($peek ? '' : (string)$xmlMessages[$i]->PopReceipt),
448					($peek ? '' : (string)$xmlMessages[$i]->TimeNextVisible),
449					(string)$xmlMessages[$i]->DequeueCount,
450					base64_decode((string)$xmlMessages[$i]->MessageText)
451			    );
452			}
453			    
454			return $messages;
455		} else {
456			throw new Microsoft_WindowsAzure_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
457		}
458	}
459	
460	/**
461	 * Peek queue messages
462	 *
463	 * @param string $queueName         Queue name
464	 * @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.
465	 * @return array
466	 * @throws Microsoft_WindowsAzure_Exception
467	 */
468	public function peekMessages($queueName = '', $numOfMessages = 1)
469	{
470	    return $this->getMessages($queueName, $numOfMessages, null, true);
471	}
472	
473	/**
474	 * Clear queue messages
475	 *
476	 * @param string $queueName         Queue name
477	 * @throws Microsoft_WindowsAzure_Exception
478	 */
479	public function clearMessages($queueName = '')
480	{
481		if ($queueName === '') {
482			throw new Microsoft_WindowsAzure_Exception('Queue name is not specified.');
483		}
484		if (!self::isValidQueueName($queueName)) {
485		    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.');
486		}
487
488		// Perform request
489		$response = $this->_performRequest($queueName . '/messages', '', Microsoft_Http_Client::DELETE);	
490		if (!$response->isSuccessful()) {
491			throw new Microsoft_WindowsAzure_Exception('Error clearing messages from queue.');
492		}
493	}
494	
495	/**
496	 * Delete queue message
497	 *
498	 * @param string $queueName         					Queue name
499	 * @param Microsoft_WindowsAzure_Storage_QueueMessage $message Message to delete from queue. A message retrieved using "peekMessages" can NOT be deleted!
500	 * @throws Microsoft_WindowsAzure_Exception
501	 */
502	public function deleteMessage($queueName = '', Microsoft_WindowsAzure_Storage_QueueMessage $message)
503	{
504		if ($queueName === '') {
505			throw new Microsoft_WindowsAzure_Exception('Queue name is not specified.');
506		}
507		if (!self::isValidQueueName($queueName)) {
508		    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.');
509		}
510		if ($message->PopReceipt == '') {
511		    throw new Microsoft_WindowsAzure_Exception('A message retrieved using "peekMessages" can NOT be deleted! Use "getMessages" instead.');
512		}
513
514		// Perform request
515		$response = $this->_performRequest($queueName . '/messages/' . $message->MessageId, '?popreceipt=' . $message->PopReceipt, Microsoft_Http_Client::DELETE);	
516		if (!$response->isSuccessful()) {
517			throw new Microsoft_WindowsAzure_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
518		}
519	}
520	
521	/**
522	 * Is valid queue name?
523	 *
524	 * @param string $queueName Queue name
525	 * @return boolean
526	 */
527    public static function isValidQueueName($queueName = '')
528    {
529        if (preg_match("/^[a-z0-9][a-z0-9-]*$/", $queueName) === 0) {
530            return false;
531        }
532    
533        if (strpos($queueName, '--') !== false) {
534            return false;
535        }
536    
537        if (strtolower($queueName) != $queueName) {
538            return false;
539        }
540    
541        if (strlen($queueName) < 3 || strlen($queueName) > 63) {
542            return false;
543        }
544            
545        if (substr($queueName, -1) == '-') {
546            return false;
547        }
548    
549        return true;
550    }
551    
552	/**
553	 * Get error message from Microsoft_Http_Response
554	 * 
555	 * @param Microsoft_Http_Response $response Repsonse
556	 * @param string $alternativeError Alternative error message
557	 * @return string
558	 */
559	protected function _getErrorMessage(Microsoft_Http_Response $response, $alternativeError = 'Unknown error.')
560	{
561		$response = $this->_parseResponse($response);
562		if ($response && $response->Message) {
563		    return (string)$response->Message;
564		} else {
565		    return $alternativeError;
566		}
567	}
568}