Skip to content
Snippets Groups Projects
Commit 71b9929e authored by Nikhil Singh[MicroSoft]'s avatar Nikhil Singh[MicroSoft]
Browse files

Commit 9 Contents:

1-Handle NPE for Management Client
parent c8ac2195
No related branches found
No related tags found
2 merge requests!102Locking down maven central,!97Service Bus Create and Delete Support for Subscriptions
......@@ -15,6 +15,7 @@
package org.opengroup.osdu.register.provider.azure.subscriber.pubsub;
import com.microsoft.azure.CloudException;
import com.microsoft.azure.servicebus.management.ManagementClient;
import org.opengroup.osdu.azure.partition.PartitionServiceClient;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.AppException;
......@@ -30,6 +31,7 @@ import org.springframework.stereotype.Component;
public class PullSubscription implements IPubsubSubscription {
// TODO: UPDATE ERROR_MESSAGE FOR SERVICE BUS
private static final String RESOURCE_PROVISIONING_ERROR_MESSAGE = "Resource cannot be updated during provisioning";
private static final String MANAGEMENT_CLIENT_ERROR_MESSAGE = "Unable to create management client";
@Autowired
private IManagementClientFactory factory;
@Autowired
......@@ -43,7 +45,11 @@ public class PullSubscription implements IPubsubSubscription {
public void createSubscription(String subscriptionId, String topicAliasName) {
try {
factory.getManager().createSubscription(topicAliasName, subscriptionId);
ManagementClient managementClient = factory.getManager();
if (managementClient == null) {
throw new AppException(500, "Null Pointer Exception", MANAGEMENT_CLIENT_ERROR_MESSAGE);
}
managementClient.createSubscription(topicAliasName, subscriptionId);
} catch (Exception e) {
if (e.getMessage().equals(RESOURCE_PROVISIONING_ERROR_MESSAGE)) {
logger.error("Another request is trying to create the same Pull subscription");
......@@ -57,7 +63,11 @@ public class PullSubscription implements IPubsubSubscription {
public void deleteSubscription(String subscriptionId, String topicAliasName) {
try {
factory.getManager().deleteSubscription(topicAliasName, subscriptionId);
ManagementClient managementClient = factory.getManager();
if (managementClient == null) {
throw new AppException(500, "Null Pointer Exception", MANAGEMENT_CLIENT_ERROR_MESSAGE);
}
managementClient.deleteSubscription(topicAliasName, subscriptionId);
} catch (Exception e) {
if (e instanceof CloudException) {
CloudException cloudException = (CloudException) e;
......@@ -72,7 +82,11 @@ public class PullSubscription implements IPubsubSubscription {
public void checkIfSubscriptionExists(String subscriptionId, String topicAliasName) {
try {
factory.getManager().getSubscription(topicAliasName, subscriptionId);
ManagementClient managementClient = factory.getManager();
if (managementClient == null) {
throw new AppException(500, "Null Pointer Exception", MANAGEMENT_CLIENT_ERROR_MESSAGE);
}
managementClient.getSubscription(topicAliasName, subscriptionId);
} catch (Exception e) {
if (e instanceof NullPointerException) {
logger.error(String.format("Pull Subscription with id %s does not exist.", subscriptionId));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment