use of org.wso2.carbon.apimgt.impl.dto.WebhooksDTO in project carbon-apimgt by wso2.
the class SubscriptionDataStore method initializeStore.
/**
* This method is used to initilize a task to retrieve subscriptions.
*/
private void initializeStore() {
this.subscribersMap = new ConcurrentHashMap<>();
this.throttlingStatusMap = new ConcurrentHashMap<>();
executor.submit(() -> {
List<WebhooksDTO> subscriptions = loadSubscriptions();
for (WebhooksDTO subscriber : subscriptions) {
String subscriptionKey = subscriber.getApiUUID() + "_" + subscriber.getTopicName();
String throttleKey = subscriber.getAppID() + "_" + subscriber.getApiUUID();
addSubscriber(subscriptionKey, subscriber);
throttlingStatusMap.put(throttleKey, false);
}
});
}
use of org.wso2.carbon.apimgt.impl.dto.WebhooksDTO in project carbon-apimgt by wso2.
the class GatewayJMSMessageListener method handleAsyncWebhooksUnSubscriptionMessage.
private synchronized void handleAsyncWebhooksUnSubscriptionMessage(JsonNode payloadData) {
if (log.isDebugEnabled()) {
log.debug("Received event for - Async Webhooks API unsubscription for : " + payloadData.get(APIConstants.Webhooks.API_UUID).asText());
}
String apiKey = payloadData.get(APIConstants.Webhooks.API_UUID).textValue();
String tenantDomain = payloadData.get(APIConstants.Webhooks.TENANT_DOMAIN).textValue();
String topicName = payloadData.get(APIConstants.Webhooks.TOPIC).textValue();
WebhooksDTO subscriber = new WebhooksDTO();
subscriber.setCallbackURL(payloadData.get(APIConstants.Webhooks.CALLBACK).textValue());
subscriber.setAppID(payloadData.get(APIConstants.Webhooks.APP_ID).textValue());
subscriber.setSecret(payloadData.get(APIConstants.Webhooks.SECRET).textValue());
ServiceReferenceHolder.getInstance().getSubscriptionsDataService().removeSubscription(apiKey, topicName, tenantDomain, subscriber);
}
use of org.wso2.carbon.apimgt.impl.dto.WebhooksDTO in project carbon-apimgt by wso2.
the class GatewayJMSMessageListener method handleAsyncWebhooksSubscriptionMessage.
private synchronized void handleAsyncWebhooksSubscriptionMessage(JsonNode payloadData) {
if (log.isDebugEnabled()) {
log.debug("Received event for - Async Webhooks API subscription for : " + payloadData.get(APIConstants.Webhooks.API_UUID).asText());
}
String apiUUID = payloadData.get(APIConstants.Webhooks.API_UUID).textValue();
String appID = payloadData.get(APIConstants.Webhooks.APP_ID).textValue();
String tenantDomain = payloadData.get(APIConstants.Webhooks.TENANT_DOMAIN).textValue();
boolean isThrottled = payloadData.get(APIConstants.Webhooks.IS_THROTTLED).asBoolean();
ServiceReferenceHolder.getInstance().getSubscriptionsDataService().updateThrottleStatus(appID, apiUUID, tenantDomain, isThrottled);
if (!isThrottled) {
String topicName = payloadData.get(APIConstants.Webhooks.TOPIC).textValue();
WebhooksDTO subscriber = new WebhooksDTO();
subscriber.setApiUUID(apiUUID);
subscriber.setApiContext(payloadData.get(APIConstants.Webhooks.API_CONTEXT).textValue());
subscriber.setApiName(payloadData.get(APIConstants.Webhooks.API_NAME).textValue());
subscriber.setApiVersion(payloadData.get(APIConstants.Webhooks.API_VERSION).textValue());
subscriber.setAppID(appID);
subscriber.setCallbackURL(payloadData.get(APIConstants.Webhooks.CALLBACK).textValue());
subscriber.setTenantDomain(tenantDomain);
subscriber.setTenantId(payloadData.get(APIConstants.Webhooks.TENANT_ID).intValue());
subscriber.setSecret(payloadData.get(APIConstants.Webhooks.SECRET).textValue());
subscriber.setExpiryTime(payloadData.get(APIConstants.Webhooks.EXPIRY_AT).asLong());
subscriber.setTopicName(topicName);
subscriber.setApiTier(payloadData.get(APIConstants.Webhooks.API_TIER).textValue());
subscriber.setApplicationTier(payloadData.get(APIConstants.Webhooks.APPLICATION_TIER).textValue());
subscriber.setTier(payloadData.get(APIConstants.Webhooks.TIER).textValue());
subscriber.setSubscriberName(payloadData.get(APIConstants.Webhooks.SUBSCRIBER_NAME).textValue());
ServiceReferenceHolder.getInstance().getSubscriptionsDataService().addSubscription(apiUUID, topicName, tenantDomain, subscriber);
}
}
use of org.wso2.carbon.apimgt.impl.dto.WebhooksDTO in project carbon-apimgt by wso2.
the class SubscriberInfoLoader method mediate.
// private final GenericRequestDataCollector dataCollector = null;
@Override
public boolean mediate(MessageContext messageContext) {
List<WebhooksDTO> subscribersList = (List<WebhooksDTO>) messageContext.getProperty(APIConstants.Webhooks.SUBSCRIBERS_LIST_PROPERTY);
int index = (Integer) messageContext.getProperty(APIConstants.CLONED_ITERATION_INDEX_PROPERTY);
WebhooksDTO subscriber = subscribersList.get(index - 1);
if (subscriber != null) {
boolean canProceed = handleThrottle(subscriber, messageContext);
if (!canProceed) {
return false;
}
messageContext.setProperty(APIConstants.Webhooks.SUBSCRIBER_CALLBACK_PROPERTY, subscriber.getCallbackURL());
messageContext.setProperty(APIConstants.Webhooks.SUBSCRIBER_SECRET_PROPERTY, subscriber.getSecret());
messageContext.setProperty(APIConstants.Webhooks.SUBSCRIBER_APPLICATION_ID_PROPERTY, subscriber.getAppID());
}
return true;
}
use of org.wso2.carbon.apimgt.impl.dto.WebhooksDTO in project carbon-apimgt by wso2.
the class SubscriptionDataStore method loadSubscriptions.
/**
* This method is used to load subscription list.
*
* @return the subscription list.
*/
private List<WebhooksDTO> loadSubscriptions() {
String responseString = invokeService();
List<WebhooksDTO> subscriptions = new ArrayList<>();
if (responseString != null && !responseString.isEmpty()) {
subscriptions = new Gson().fromJson(responseString, WebhooksListDTO.class).getList();
}
return subscriptions;
}
Aggregations