From 9d4defaa01224065bfc835c80f8922c820f98fef Mon Sep 17 00:00:00 2001 From: ayyoob Date: Fri, 15 Apr 2016 23:10:11 +0530 Subject: [PATCH] check whether the subscriber exist before creating --- .../pom.xml | 13 +++++++++++- .../APIManagementProviderServiceImpl.java | 20 +++++++++++-------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/pom.xml index bfe5a9177ba..b1c7c57bcbd 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/pom.xml @@ -77,7 +77,18 @@ commons-httpclient provided - + + org.wso2.carbon + org.wso2.carbon.base + + + com.googlecode.json-simple.wso2 + json-simple + + + org.wso2.carbon + org.wso2.carbon.user.api + org.wso2.carbon org.wso2.carbon.utils diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/src/main/java/org/wso2/carbon/apimgt/application/extension/APIManagementProviderServiceImpl.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/src/main/java/org/wso2/carbon/apimgt/application/extension/APIManagementProviderServiceImpl.java index e7eb8d6da9d..986e173f329 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/src/main/java/org/wso2/carbon/apimgt/application/extension/APIManagementProviderServiceImpl.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/src/main/java/org/wso2/carbon/apimgt/application/extension/APIManagementProviderServiceImpl.java @@ -286,14 +286,18 @@ public class APIManagementProviderServiceImpl implements APIManagementProviderSe try { APIConsumer consumer = APIManagerFactory.getInstance().getAPIConsumer(subscriberName); if (consumer != null) { - Subscriber subscriber = new Subscriber(subscriberName); - subscriber.setSubscribedDate(new Date()); - subscriber.setEmail(subscriberEmail); - subscriber.setTenantId(tenantId); - consumer.addSubscriber(subscriber, groupId); - if (log.isDebugEnabled()) { - log.debug("Successfully created subscriber with name : " + subscriberName + " with groupID : " + - groupId); + synchronized (consumer) { + if (consumer.getSubscriber(subscriberName) == null) { + Subscriber subscriber = new Subscriber(subscriberName); + subscriber.setSubscribedDate(new Date()); + subscriber.setEmail(subscriberEmail); + subscriber.setTenantId(tenantId); + consumer.addSubscriber(subscriber, groupId); + if (log.isDebugEnabled()) { + log.debug("Successfully created subscriber with name : " + subscriberName + + " with groupID : " + groupId); + } + } } } else { throw new APIManagerException("API provider configured for the given API configuration is null. " +