use of org.wso2.siddhi.core.event.Event in project carbon-apimgt by wso2.
the class APIGatewayPublisherImpl method addThreatProtectionPolicy.
/**
* {@inheritDoc}
*/
@Override
public void addThreatProtectionPolicy(ThreatProtectionPolicy policy) throws GatewayException {
ThreatProtectionEvent event = new ThreatProtectionEvent(APIMgtConstants.GatewayEventTypes.THREAT_PROTECTION_POLICY_ADD);
event.setPolicy(policy);
publishToThreatProtectionTopic(event);
}
use of org.wso2.siddhi.core.event.Event in project carbon-apimgt by wso2.
the class ConfigureJsonAnalyzer method execute.
@Override
public BValue[] execute(Context context) {
String event = getStringArgument(context, 0);
// configure json analyzer
BStruct jsonInfo = ((BStruct) getRefArgument(context, 0));
if (jsonInfo != null) {
String jsonPolicyId = jsonInfo.getStringField(0);
switch(event) {
case THREAT_PROTECTION_POLICY_ADD:
case THREAT_PROTECTION_POLICY_UPDATE:
String name = jsonInfo.getStringField(1);
int propertyCount = (int) jsonInfo.getIntField(0);
int stringLength = (int) jsonInfo.getIntField(1);
int arrayElementCount = (int) jsonInfo.getIntField(2);
int keyLength = (int) jsonInfo.getIntField(3);
int maxJSONDepth = (int) jsonInfo.getIntField(4);
JSONConfig jsonConfig = new JSONConfig();
jsonConfig.setName(name);
jsonConfig.setMaxPropertyCount(propertyCount);
jsonConfig.setMaxStringLength(stringLength);
jsonConfig.setMaxArrayElementCount(arrayElementCount);
jsonConfig.setMaxKeyLength(keyLength);
jsonConfig.setMaxJsonDepth(maxJSONDepth);
// put into ConfigurationHolder
ConfigurationHolder.addJsonConfig(jsonPolicyId, jsonConfig);
break;
case THREAT_PROTECTION_POLICY_DELETE:
ConfigurationHolder.removeJsonConfig(jsonPolicyId);
break;
default:
log.warn("Unknown event type for Threat Protection Policy. Event: " + event);
break;
}
}
return getBValues(new BBoolean(true));
}
use of org.wso2.siddhi.core.event.Event in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testObserverEventListener.
@Test(description = "Event Observers for event listening")
public void testObserverEventListener() throws APIManagementException {
EventLogger observer = Mockito.mock(EventLogger.class);
APIStoreImpl apiStore = getApiStoreImpl();
apiStore.registerObserver(observer);
Event event = Event.APP_CREATION;
String username = USER_NAME;
Map<String, String> metaData = new HashMap<>();
ZonedDateTime eventTime = ZonedDateTime.now(ZoneOffset.UTC);
apiStore.notifyObservers(event, username, eventTime, metaData);
Mockito.verify(observer, Mockito.times(1)).captureEvent(event, username, eventTime, metaData);
}
Aggregations