After a successful request, you can then use the information returned in the web service response.
You can verify that the request was successful by checking for the ResponseStatus block in each response. If the response inclueds a ResponseStatus with Success in the Response element, the request succeeded. However, if instead of a ResponseStatus block an Error element is returned, it will also include an error message indicating why the request failed. You can start troubleshooting the error in the request by viewing the errors returned in the response.
Here's the code snippet from our example that does this.
EnqueueSample.java: If the request fails, an exception with cause of failure is generated by Axis-generated code.
try {
:
:
:
String msgId = msgQueue.sendMessage( message );
log.info( "Sent message with id " + msgId );
} catch ( Exception ex ) {
log.error( "EXCEPTION", ex );
}Enqueue.cs:
try
{
:
:
:
//pass the message to be enqueued onto the queue at the supplied url
messageID = SimpleQueueServiceClient.Client.sendMessage(queueUrl, message);
if (messageID == null)
{
Console.Out.WriteLine("Error adding \"" + message + "\"onto queue" + queueName
+ "\" located at " + queueUrl);
return;
}
}
catch (System.Web.Services.Protocols.SoapException e)
{
Console.Out.WriteLine(e.Message);
return;
}
Console.Out.WriteLine("Enqueued \"" + message + "\" id=" + messageID + "\nonto \"" + queueName
+ "\" located at " + queueUrl);sqs-enqueue-sample.pl: If the request fails, the cause of failure is output by checkStatus().
my $send_message_response = sendMessage($queue_url, $rest_or_query, \%message_param_hash);
if (!QueueServiceMethods::checkStatus($send_message_response, $QueueServiceMethods::send_message_status_xpath)) {
print "\nCould not send message $message to queue $queue_url\n";
exit;
}
print "OK\n";QueueServiceMethods.pm:
sub checkStatus {
my ($response, $status_xpath) = @_;
my $status = $response->findvalue($status_xpath);
if (!($status eq $SUCCESS)) {
print "Expected status: [$SUCCESS], got: [$status]\n";
return 0;
}
else {
return 1;
}
}Finally, we can add code to delete the message so that it is not retrieved again. Here's the code snippet from our example that does this.
msgQueue.deleteMessage( msg.getMessageId() ); log.info( "Deleted message id " + msg.getMessageId());
//remove the message off of the queue string success = SimpleQueueServiceClient.Client.deleteMessage(queueUrl, message);
# Delete the read message, if any
print "Deleting message $message_body from queue $queue_name...";
my $message_id_to_delete = $message_id;
my %delete_param_hash = ('MessageId' => $message_id_to_delete);
my $delete_message_response = deleteMessage($queue_url, $rest_or_query, \%delete_param_hash);