diff --git a/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/api/WebSocketAPI.java b/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/api/WebSocketAPI.java index 2463686f63..761413021f 100644 --- a/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/api/WebSocketAPI.java +++ b/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/api/WebSocketAPI.java @@ -25,6 +25,7 @@ import org.wso2.choreo.connect.discovery.api.Scopes; import org.wso2.choreo.connect.discovery.api.SecurityList; import org.wso2.choreo.connect.discovery.api.SecurityScheme; +import org.wso2.choreo.connect.enforcer.analytics.AnalyticsFilter; import org.wso2.choreo.connect.enforcer.commons.Filter; import org.wso2.choreo.connect.enforcer.commons.model.APIConfig; import org.wso2.choreo.connect.enforcer.commons.model.BackendJWTConfiguration; @@ -39,6 +40,7 @@ import org.wso2.choreo.connect.enforcer.security.AuthFilter; import org.wso2.choreo.connect.enforcer.throttle.ThrottleConstants; import org.wso2.choreo.connect.enforcer.throttle.ThrottleFilter; +import org.wso2.choreo.connect.enforcer.util.FilterUtils; import org.wso2.choreo.connect.enforcer.websocket.WebSocketMetaDataFilter; import org.wso2.choreo.connect.enforcer.websocket.WebSocketThrottleFilter; import org.wso2.choreo.connect.enforcer.websocket.WebSocketThrottleResponse; @@ -165,11 +167,18 @@ public String init(Api api) { public ResponseObject process(RequestContext requestContext) { ResponseObject responseObject = new ResponseObject(); responseObject.setRequestPath(requestContext.getRequestPath()); + boolean analyticsEnabled = ConfigHolder.getInstance().getConfig().getAnalyticsConfig().isEnabled(); + responseObject.setApiUuid(apiConfig.getUuid()); Utils.populateRemoveAndProtectedHeaders(requestContext); if (executeFilterChain(requestContext)) { + + if (analyticsEnabled) { + AnalyticsFilter.getInstance().handleSuccessRequest(requestContext); + } + responseObject.setRemoveHeaderMap(requestContext.getRemoveHeaders()); responseObject.setQueryParamsToRemove(requestContext.getQueryParamsToRemove()); responseObject.setQueryParamMap(requestContext.getQueryParameters()); @@ -203,6 +212,11 @@ public ResponseObject process(RequestContext requestContext) { if (requestContext.getAddHeaders() != null && requestContext.getAddHeaders().size() > 0) { responseObject.setHeaderMap(requestContext.getAddHeaders()); } + + if (analyticsEnabled && !FilterUtils.isSkippedAnalyticsFaultEvent(responseObject.getErrorCode())) { + AnalyticsFilter.getInstance().handleFailureRequest(requestContext); + responseObject.setMetaDataMap(new HashMap<>(0)); + } } return responseObject; }