check whether the subscriber exist before creating

4.x.x
ayyoob 9 years ago
parent afe965e787
commit 9d4defaa01

@ -77,7 +77,18 @@
<artifactId>commons-httpclient</artifactId> <artifactId>commons-httpclient</artifactId>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.base</artifactId>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple.wso2</groupId>
<artifactId>json-simple</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.user.api</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.wso2.carbon</groupId> <groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.utils</artifactId> <artifactId>org.wso2.carbon.utils</artifactId>

@ -286,14 +286,18 @@ public class APIManagementProviderServiceImpl implements APIManagementProviderSe
try { try {
APIConsumer consumer = APIManagerFactory.getInstance().getAPIConsumer(subscriberName); APIConsumer consumer = APIManagerFactory.getInstance().getAPIConsumer(subscriberName);
if (consumer != null) { if (consumer != null) {
synchronized (consumer) {
if (consumer.getSubscriber(subscriberName) == null) {
Subscriber subscriber = new Subscriber(subscriberName); Subscriber subscriber = new Subscriber(subscriberName);
subscriber.setSubscribedDate(new Date()); subscriber.setSubscribedDate(new Date());
subscriber.setEmail(subscriberEmail); subscriber.setEmail(subscriberEmail);
subscriber.setTenantId(tenantId); subscriber.setTenantId(tenantId);
consumer.addSubscriber(subscriber, groupId); consumer.addSubscriber(subscriber, groupId);
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Successfully created subscriber with name : " + subscriberName + " with groupID : " + log.debug("Successfully created subscriber with name : " + subscriberName +
groupId); " with groupID : " + groupId);
}
}
} }
} else { } else {
throw new APIManagerException("API provider configured for the given API configuration is null. " + throw new APIManagerException("API provider configured for the given API configuration is null. " +

Loading…
Cancel
Save