use of org.wso2.carbon.apimgt.gateway.handlers.streaming.sse.analytics.SseResponseEventDataProvider in project carbon-apimgt by wso2.
the class SseApiHandler method isThrottled.
private boolean isThrottled(org.apache.axis2.context.MessageContext axisCtx, MessageContext synCtx) {
AuthenticationContext authenticationContext = APISecurityUtils.getAuthenticationContext(synCtx);
ThrottleInfo throttleInfo = getThrottlingInfo(authenticationContext, synCtx);
boolean isThrottled = SseUtils.isRequestBlocked(authenticationContext, throttleInfo.getApiContext(), throttleInfo.getApiVersion(), authenticationContext.getUsername(), throttleInfo.getRemoteIp(), CarbonContext.getThreadLocalCarbonContext().getTenantDomain());
if (!isThrottled) {
// do throttling if request is not blocked by global conditions only
isThrottled = SseUtils.isThrottled(throttleInfo.getSubscriberTenantDomain(), throttleInfo.getResourceLevelThrottleKey(), throttleInfo.getSubscriptionLevelThrottleKey(), throttleInfo.getApplicationLevelThrottleKey());
}
if (isThrottled) {
handleThrottledOut(synCtx);
return true;
}
if (APIUtil.isAnalyticsEnabled()) {
AnalyticsDataProvider provider = new SseResponseEventDataProvider(synCtx);
axisCtx.setProperty(SSE_ANALYTICS_INFO, provider);
}
return false;
}
use of org.wso2.carbon.apimgt.gateway.handlers.streaming.sse.analytics.SseResponseEventDataProvider in project carbon-apimgt by wso2.
the class SseResponseStreamInterceptor method publishAnalyticsData.
private void publishAnalyticsData(int eventCount, MessageContext axi2Ctx) throws AnalyticsException {
Object responseEventProvider = axi2Ctx.getProperty(SSE_ANALYTICS_INFO);
if (responseEventProvider == null) {
log.error("SSE Analytics event provider is null.");
return;
}
SseResponseEventDataProvider provider = (SseResponseEventDataProvider) responseEventProvider;
provider.setResponseCode((int) axi2Ctx.getProperty(SynapseConstants.HTTP_SC));
GenericRequestDataCollector dataCollector = new GenericRequestDataCollector(provider);
for (int count = 0; count < eventCount; count++) {
dataCollector.collectData();
}
}
Aggregations