use of org.wso2.carbon.apimgt.api.model.webhooks.Topic in project carbon-apimgt by wso2.
the class WebhooksApiServiceImpl method webhooksSubscriptionsGet.
public Response webhooksSubscriptionsGet(String applicationId, String apiId, String xWSO2Tenant, MessageContext messageContext) {
if (StringUtils.isNotEmpty(applicationId)) {
String username = RestApiCommonUtil.getLoggedInUsername();
try {
APIConsumer apiConsumer = RestApiCommonUtil.getConsumer(username);
WebhookSubscriptionListDTO WebhookSubscriptionListDTO;
Set<Subscription> subscriptionSet = apiConsumer.getTopicSubscriptions(applicationId, apiId);
WebhookSubscriptionListDTO = AsyncAPIMappingUtil.fromSubscriptionListToDTO(subscriptionSet);
return Response.ok().entity(WebhookSubscriptionListDTO).build();
} catch (APIManagementException e) {
if (RestApiUtil.isDueToResourceNotFound(e) || RestApiUtil.isDueToAuthorizationFailure(e)) {
RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_API, apiId, e, log);
} else {
RestApiUtil.handleInternalServerError("Failed to get topic subscriptions of Async API " + apiId, e, log);
}
}
} else {
RestApiUtil.handleBadRequest("Application Id cannot be empty", log);
}
return null;
}
use of org.wso2.carbon.apimgt.api.model.webhooks.Topic in project carbon-apimgt by wso2.
the class AsyncAPIMappingUtil method fromTopicToDTO.
/**
* Converts Topic object to DTO.
*
* @param topic Topic object
* @return TopicDTO
*/
public static TopicDTO fromTopicToDTO(Topic topic) {
TopicDTO topicDTO = new TopicDTO();
topicDTO.setApiId(topic.getApiId());
topicDTO.setName(topic.getName());
topicDTO.setType(topic.getType());
return topicDTO;
}
use of org.wso2.carbon.apimgt.api.model.webhooks.Topic in project carbon-apimgt by wso2.
the class SampleTestObjectCreator method createDefaultSiddhiAppforAppPolicy.
public static String createDefaultSiddhiAppforAppPolicy() {
ApplicationPolicy policy = createDefaultApplicationPolicy();
RequestCountLimit limit = (RequestCountLimit) createDefaultApplicationPolicy().getDefaultQuotaPolicy().getLimit();
String siddhiApp = "@App:name('application_" + policy.getPolicyName() + "')\n" + "@App:description('ExecutionPlan for app_" + policy.getPolicyName() + "')\n" + "@source(type='inMemory', topic='apim', @map(type='passThrough'))\n" + "define stream RequestStream (messageID string, appKey string, appTier string, " + "subscriptionKey string," + " apiKey string, apiTier string, subscriptionTier string, resourceKey string," + " resourceTier string," + " userId string, apiContext string, apiVersion string, appTenant string, apiTenant string," + " appId " + "string, apiName string, propertiesMap string);\n" + "@sink(type='jms', @map(type='text'),\n" + "factory.initial='org.wso2.andes.jndi.PropertiesFileInitialContextFactory'," + " provider.url='tcp://localhost:5672', destination='TEST.FOO', connection.factory." + "type='topic',\n" + "connection.factory.jndi.name='TopicConnectionFactory')\n" + "define stream GlobalThrottleStream (throttleKey string, isThrottled bool" + ", expiryTimeStamp long);\n" + "FROM RequestStream\n" + "SELECT messageID, (appTier == '" + policy.getPolicyName() + "') AS isEligible, appKey AS throttleKey, " + "propertiesMap\n" + "INSERT INTO EligibilityStream;\n" + "FROM EligibilityStream[isEligible==true]#throttler:timeBatch(" + policy.getDefaultQuotaPolicy().getLimit().getUnitTime() + " " + policy.getDefaultQuotaPolicy().getLimit().getTimeUnit() + ", 0)\n" + "select throttleKey, (count(messageID) >= " + limit.getRequestCount() + ")" + " as isThrottled, expiryTimeStamp group by throttleKey\n" + "INSERT ALL EVENTS into ResultStream;\n" + "from ResultStream#throttler:emitOnStateChange(throttleKey, isThrottled)\n" + "select *\n" + "insert into GlobalThrottleStream;\n";
return siddhiApp;
}
use of org.wso2.carbon.apimgt.api.model.webhooks.Topic in project carbon-apimgt by wso2.
the class SampleTestObjectCreator method createDefaultSiddhiAppForAPILevelDefaultThrottlePolicy.
public static String createDefaultSiddhiAppForAPILevelDefaultThrottlePolicy() {
APIPolicy apiPolicy = createDefaultAPIPolicy();
String siddhiApp = "\n@App:name('resource_" + apiPolicy.getPolicyName() + "_default')" + "\n@App:description('ExecutionPlan for resource_" + apiPolicy.getPolicyName() + "_default')\n" + "\n@source(type='inMemory', topic='apim', @map(type='passThrough'))" + "\ndefine stream RequestStream (messageID string, appKey string," + " appTier string, subscriptionKey string," + " apiKey string, apiTier string, subscriptionTier string, resourceKey string," + " resourceTier string, userId string, apiContext string, apiVersion string, appTenant string," + " apiTenant string," + " appId string, apiName string, propertiesMap string);\n" + "\n@sink(type='jms', @map(type='text')," + "\nfactory.initial='org.wso2.andes.jndi.PropertiesFileInitialContextFactory'," + " provider.url='tcp://localhost:5672'," + " destination='TEST.FOO', connection.factory.type='topic'," + "\nconnection.factory.jndi.name='TopicConnectionFactory')" + "\ndefine stream GlobalThrottleStream (throttleKey string, isThrottled bool," + " expiryTimeStamp long);\n" + "\nFROM RequestStream" + "\nSELECT messageID, (resourceTier == 'SampleAPIPolicy' AND " + "NOT(((3232238595l<=cast(map:get(propertiesMap,'ip'),'Long')" + " AND 3232258067l>=cast(map:get(propertiesMap,'ip'),'Long')) AND " + "(cast(map:get(propertiesMap,'ip'),'Long')==2066353720l)) " + "OR ((regex:find('Chrome',cast(map:get(propertiesMap,'Browser'),'string')))" + " AND (regex:find('attributed'," + "cast(map:get(propertiesMap,'/path/path2'),'string')))" + " AND (cast(map:get(propertiesMap,'Location'),'string')=='Colombo'))))" + " AS isEligible, resourceKey AS throttleKey, propertiesMap" + "\nINSERT INTO EligibilityStream;\n" + "\nFROM EligibilityStream[isEligible==true]#throttler:timeBatch(1000 s, 0)" + "\nselect throttleKey, (count(messageID) >= 10000) as isThrottled," + " expiryTimeStamp group by throttleKey" + "\nINSERT ALL EVENTS into ResultStream;\n" + "\nfrom ResultStream#throttler:emitOnStateChange(throttleKey, isThrottled)" + "\nselect *" + "\ninsert into GlobalThrottleStream;\n";
return siddhiApp;
}
use of org.wso2.carbon.apimgt.api.model.webhooks.Topic in project siddhi by wso2.
the class InMemoryTransportTestCase method inMemoryWithFailingSource.
@Test
public void inMemoryWithFailingSource() throws InterruptedException {
log.info("Test failing inMemorySource");
String streams = "" + "@app:name('TestSiddhiApp')" + "@source(type='testFailingInMemory', topic='WSO2', @map(type='passThrough')) " + "define stream FooStream (symbol string, price float, volume long); " + "define stream BarStream (symbol string, price float, volume long); ";
String query = "" + "from FooStream " + "select * " + "insert into BarStream; ";
SiddhiManager siddhiManager = new SiddhiManager();
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
siddhiAppRuntime.addCallback("BarStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
for (Event event : events) {
wso2Count.incrementAndGet();
}
}
});
siddhiAppRuntime.start();
InMemoryBroker.publish("WSO2", new Event(System.currentTimeMillis(), new Object[] { "WSO2", 55.6f, 100L }));
InMemoryBroker.publish("IBM", new Event(System.currentTimeMillis(), new Object[] { "IBM", 75.6f, 100L }));
TestFailingInMemorySource.fail = true;
TestFailingInMemorySource.connectionCallback.onError(new ConnectionUnavailableException("Connection Lost"));
Thread.sleep(500);
InMemoryBroker.publish("WSO2", new Event(System.currentTimeMillis(), new Object[] { "WSO2", 57.6f, 100L }));
InMemoryBroker.publish("WSO2", new Event(System.currentTimeMillis(), new Object[] { "WSO2", 57.6f, 100L }));
InMemoryBroker.publish("WSO2", new Event(System.currentTimeMillis(), new Object[] { "WSO2", 57.6f, 100L }));
TestFailingInMemorySource.fail = false;
Thread.sleep(5500);
InMemoryBroker.publish("WSO2", new Event(System.currentTimeMillis(), new Object[] { "WSO2", 55.6f, 100L }));
InMemoryBroker.publish("IBM", new Event(System.currentTimeMillis(), new Object[] { "IBM", 75.6f, 100L }));
// assert event count
AssertJUnit.assertEquals("Number of WSO2 events", 2, wso2Count.get());
AssertJUnit.assertEquals("Number of errors", 1, TestFailingInMemorySource.numberOfErrorOccurred);
siddhiAppRuntime.shutdown();
}
Aggregations