From 457d911af6e128fb7d963151f99d2d748e79e167 Mon Sep 17 00:00:00 2001 From: frascu Date: Mon, 1 Mar 2021 12:36:01 +0100 Subject: [PATCH 1/2] add check existing queue --- .../ServiceBusAdministrationAsyncClient.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/sdk/servicebus/azure-messaging-servicebus/src/main/java/com/azure/messaging/servicebus/administration/ServiceBusAdministrationAsyncClient.java b/sdk/servicebus/azure-messaging-servicebus/src/main/java/com/azure/messaging/servicebus/administration/ServiceBusAdministrationAsyncClient.java index 17d493a5f63bf..d716c9246d444 100644 --- a/sdk/servicebus/azure-messaging-servicebus/src/main/java/com/azure/messaging/servicebus/administration/ServiceBusAdministrationAsyncClient.java +++ b/sdk/servicebus/azure-messaging-servicebus/src/main/java/com/azure/messaging/servicebus/administration/ServiceBusAdministrationAsyncClient.java @@ -2229,6 +2229,12 @@ private Response deserializeQueue(Response response) { } else if (entry.getContent() == null) { logger.info("entry.getContent() is null. The entity may not exist. {}", entry); return new SimpleResponse<>(response.getRequest(), response.getStatusCode(), response.getHeaders(), null); + } else if (entry.getContent().getQueueDescription() == null) { + final TopicDescriptionEntry entryTopic = deserialize(response.getValue(), TopicDescriptionEntry.class); + if (entryTopic != null && entryTopic.getContent() != null && entryTopic.getContent().getTopicDescription() != null) { + throw logger.logExceptionAsError( + new RuntimeException(String.format("'[%s]' is not a queue, it is a topic.", entryTopic.getTitle()))); + } } final QueueProperties result = EntityHelper.toModel(entry.getContent().getQueueDescription()); @@ -2308,6 +2314,12 @@ private Response deserializeTopic(Response response) { } else if (entry.getContent() == null) { logger.warning("entry.getContent() is null. There should have been content returned. Entry: {}", entry); return new SimpleResponse<>(response.getRequest(), response.getStatusCode(), response.getHeaders(), null); + } else if (entry.getContent().getTopicDescription() == null) { + final QueueDescriptionEntry entryTopic = deserialize(response.getValue(), QueueDescriptionEntry.class); + if (entryTopic != null && entryTopic.getContent() != null && entryTopic.getContent().getQueueDescription() != null) { + throw logger.logExceptionAsError( + new RuntimeException(String.format("'[%s]' is not a topic, it is a queue.", entryTopic.getTitle()))); + } } final TopicProperties result = EntityHelper.toModel(entry.getContent().getTopicDescription()); From 97055468c43e8b6e2a7f6aab1f7e1c46d93e1ecc Mon Sep 17 00:00:00 2001 From: frascu Date: Thu, 3 Jun 2021 11:04:11 +0200 Subject: [PATCH 2/2] return an empty simple response --- .../ServiceBusAdministrationAsyncClient.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sdk/servicebus/azure-messaging-servicebus/src/main/java/com/azure/messaging/servicebus/administration/ServiceBusAdministrationAsyncClient.java b/sdk/servicebus/azure-messaging-servicebus/src/main/java/com/azure/messaging/servicebus/administration/ServiceBusAdministrationAsyncClient.java index d716c9246d444..39976980d2657 100644 --- a/sdk/servicebus/azure-messaging-servicebus/src/main/java/com/azure/messaging/servicebus/administration/ServiceBusAdministrationAsyncClient.java +++ b/sdk/servicebus/azure-messaging-servicebus/src/main/java/com/azure/messaging/servicebus/administration/ServiceBusAdministrationAsyncClient.java @@ -2232,8 +2232,8 @@ private Response deserializeQueue(Response response) { } else if (entry.getContent().getQueueDescription() == null) { final TopicDescriptionEntry entryTopic = deserialize(response.getValue(), TopicDescriptionEntry.class); if (entryTopic != null && entryTopic.getContent() != null && entryTopic.getContent().getTopicDescription() != null) { - throw logger.logExceptionAsError( - new RuntimeException(String.format("'[%s]' is not a queue, it is a topic.", entryTopic.getTitle()))); + logger.warning("'{}' is not a queue, it is a topic.", entryTopic.getTitle()); + return new SimpleResponse<>(response.getRequest(), response.getStatusCode(), response.getHeaders(), null); } } @@ -2315,10 +2315,10 @@ private Response deserializeTopic(Response response) { logger.warning("entry.getContent() is null. There should have been content returned. Entry: {}", entry); return new SimpleResponse<>(response.getRequest(), response.getStatusCode(), response.getHeaders(), null); } else if (entry.getContent().getTopicDescription() == null) { - final QueueDescriptionEntry entryTopic = deserialize(response.getValue(), QueueDescriptionEntry.class); - if (entryTopic != null && entryTopic.getContent() != null && entryTopic.getContent().getQueueDescription() != null) { - throw logger.logExceptionAsError( - new RuntimeException(String.format("'[%s]' is not a topic, it is a queue.", entryTopic.getTitle()))); + final QueueDescriptionEntry entryQueue = deserialize(response.getValue(), QueueDescriptionEntry.class); + if (entryQueue != null && entryQueue.getContent() != null && entryQueue.getContent().getQueueDescription() != null) { + logger.warning("'{}' is not a topic, it is a queue.", entryQueue.getTitle()); + return new SimpleResponse<>(response.getRequest(), response.getStatusCode(), response.getHeaders(), null); } }