From fde49ebe98ae41523b4d168f394785b435466e6e Mon Sep 17 00:00:00 2001 From: Connie Date: Mon, 7 Jun 2021 15:09:11 -0700 Subject: [PATCH 1/3] Adding missing return statement. --- .../messaging/eventhubs/implementation/ManagementChannel.java | 1 + 1 file changed, 1 insertion(+) diff --git a/sdk/eventhubs/azure-messaging-eventhubs/src/main/java/com/azure/messaging/eventhubs/implementation/ManagementChannel.java b/sdk/eventhubs/azure-messaging-eventhubs/src/main/java/com/azure/messaging/eventhubs/implementation/ManagementChannel.java index 9fd59529d17e4..b6ec17775aecb 100644 --- a/sdk/eventhubs/azure-messaging-eventhubs/src/main/java/com/azure/messaging/eventhubs/implementation/ManagementChannel.java +++ b/sdk/eventhubs/azure-messaging-eventhubs/src/main/java/com/azure/messaging/eventhubs/implementation/ManagementChannel.java @@ -162,6 +162,7 @@ private Mono getProperties(Map properties, Class respo .handle((message, sink) -> { if (RequestResponseUtils.isSuccessful(message)) { sink.next(messageSerializer.deserialize(message, responseType)); + return; } final AmqpResponseCode statusCode = RequestResponseUtils.getStatusCode(message); From c9a6f45847f3a2efca682046dbf22820b7b5db1c Mon Sep 17 00:00:00 2001 From: Connie Date: Mon, 7 Jun 2021 15:11:02 -0700 Subject: [PATCH 2/3] Using common logic for status codes. --- .../amqp/implementation/ManagementChannel.java | 7 +++---- .../implementation/ManagementChannel.java | 15 +++++++-------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/sdk/core/azure-core-amqp/src/main/java/com/azure/core/amqp/implementation/ManagementChannel.java b/sdk/core/azure-core-amqp/src/main/java/com/azure/core/amqp/implementation/ManagementChannel.java index f469f879dede0..04145e4ece7be 100644 --- a/sdk/core/azure-core-amqp/src/main/java/com/azure/core/amqp/implementation/ManagementChannel.java +++ b/sdk/core/azure-core-amqp/src/main/java/com/azure/core/amqp/implementation/ManagementChannel.java @@ -116,14 +116,13 @@ private Mono isAuthorized() { .next() .switchIfEmpty(Mono.error(new AmqpException(false, "Did not get response from tokenManager: " + entityPath, getErrorContext()))) .handle((response, sink) -> { - if (response != AmqpResponseCode.ACCEPTED && response != AmqpResponseCode.OK) { + if (RequestResponseUtils.isSuccessful(response)) { + sink.complete(); + } else { final String message = String.format("User does not have authorization to perform operation " + "on entity [%s]. Response: [%s]", entityPath, response); sink.error(ExceptionUtil.amqpResponseCodeToException(response.getValue(), message, getErrorContext())); - - } else { - sink.complete(); } }); } diff --git a/sdk/eventhubs/azure-messaging-eventhubs/src/main/java/com/azure/messaging/eventhubs/implementation/ManagementChannel.java b/sdk/eventhubs/azure-messaging-eventhubs/src/main/java/com/azure/messaging/eventhubs/implementation/ManagementChannel.java index b6ec17775aecb..254e37b16e662 100644 --- a/sdk/eventhubs/azure-messaging-eventhubs/src/main/java/com/azure/messaging/eventhubs/implementation/ManagementChannel.java +++ b/sdk/eventhubs/azure-messaging-eventhubs/src/main/java/com/azure/messaging/eventhubs/implementation/ManagementChannel.java @@ -162,15 +162,14 @@ private Mono getProperties(Map properties, Class respo .handle((message, sink) -> { if (RequestResponseUtils.isSuccessful(message)) { sink.next(messageSerializer.deserialize(message, responseType)); - return; - } - - final AmqpResponseCode statusCode = RequestResponseUtils.getStatusCode(message); - final String statusDescription = RequestResponseUtils.getStatusDescription(message); - final Throwable error = ExceptionUtil.amqpResponseCodeToException(statusCode.getValue(), - statusDescription, channel.getErrorContext()); + } else { + final AmqpResponseCode statusCode = RequestResponseUtils.getStatusCode(message); + final String statusDescription = RequestResponseUtils.getStatusDescription(message); + final Throwable error = ExceptionUtil.amqpResponseCodeToException(statusCode.getValue(), + statusDescription, channel.getErrorContext()); - sink.error(logger.logExceptionAsWarning(Exceptions.propagate(error))); + sink.error(logger.logExceptionAsWarning(Exceptions.propagate(error))); + } })); }); } From a2c7273e9bef5c25bac5a245b35fe735f0a799b0 Mon Sep 17 00:00:00 2001 From: Connie Date: Mon, 7 Jun 2021 16:23:27 -0700 Subject: [PATCH 3/3] Adding isSuccessful. --- .../azure/core/amqp/implementation/RequestResponseUtils.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sdk/core/azure-core-amqp/src/main/java/com/azure/core/amqp/implementation/RequestResponseUtils.java b/sdk/core/azure-core-amqp/src/main/java/com/azure/core/amqp/implementation/RequestResponseUtils.java index d61b8594b9de5..d0c2fead82a19 100644 --- a/sdk/core/azure-core-amqp/src/main/java/com/azure/core/amqp/implementation/RequestResponseUtils.java +++ b/sdk/core/azure-core-amqp/src/main/java/com/azure/core/amqp/implementation/RequestResponseUtils.java @@ -28,6 +28,10 @@ public class RequestResponseUtils { public static boolean isSuccessful(Message message) { final AmqpResponseCode statusCode = getStatusCode(message); + return isSuccessful(statusCode); + } + + public static boolean isSuccessful(AmqpResponseCode statusCode) { return statusCode == AmqpResponseCode.OK || statusCode == AmqpResponseCode.ACCEPTED; }