Source:
private void handleCallback(WorkFlowRequest request, String status, Map<String, Object> additionalParams) throws WorkflowException { if (request != null) { WorkflowRequestDAO workflowRequestDAO = new WorkflowRequestDAO(); if (workflowRequestDAO.retrieveStatusOfWorkflow(request.getUuid()).equals(WorkflowRequestStatus.DELETED .toString())) { log.info("Callback received for request which is already deleted by user."); return; } String eventId = request.getEventType(); WorkflowRequestHandler requestHandler = WorkflowServiceDataHolder.getInstance().getRequestHandler(eventId); if (requestHandler == null) { throw new InternalWorkflowException("No request handlers registered for the id: " + eventId); } String requestId = request.getUuid(); if (request.getTenantId() == MultitenantConstants.INVALID_TENANT_ID) { throw new InternalWorkflowException( "Invalid tenant id for request " + eventId + " with id" + requestId); } PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext .getThreadLocalCarbonContext(); try { String tenantDomain = WorkflowServiceDataHolder.getInstance().getRealmService().getTenantManager() .getDomain(request.getTenantId()); carbonContext.setTenantId(request.getTenantId()); carbonContext.setTenantDomain(tenantDomain); requestHandler.onWorkflowCompletion(status, request, additionalParams); updateDBAtWorkflowCompletion(requestId, status); } catch (WorkflowException e) { updateDBAtWorkflowCompletion(requestId, WorkflowRequestStatus.FAILED.toString()); throw e; } catch (UserStoreException e) { updateDBAtWorkflowCompletion(requestId, WorkflowRequestStatus.FAILED.toString()); throw new InternalWorkflowException("Error when getting tenant domain for tenant id " + request .getTenantId()); } finally { PrivilegedCarbonContext.endTenantFlow(); } } }

Target:
private void handleCallback(WorkFlowRequest request, String status, Map<String, Object> additionalParams) throws WorkflowException { if (request != null) { WorkflowRequestDAO workflowRequestDAO = new WorkflowRequestDAO(); String requestId = request.getUuid(); if (workflowRequestDAO.retrieveStatusOfWorkflow(request.getUuid()).equals(WorkflowRequestStatus.DELETED .toString())) { log.info("Callback received for request " + requestId + " which is already deleted by user. "); return; } String eventId = request.getEventType(); WorkflowRequestHandler requestHandler = WorkflowServiceDataHolder.getInstance().getRequestHandler(eventId); if (requestHandler == null) { throw new InternalWorkflowException("No request handlers registered for the id: " + eventId); } if (request.getTenantId() == MultitenantConstants.INVALID_TENANT_ID) { throw new InternalWorkflowException( "Invalid tenant id for request " + eventId + " with id" + requestId); } PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext .getThreadLocalCarbonContext(); try { String tenantDomain = WorkflowServiceDataHolder.getInstance().getRealmService().getTenantManager() .getDomain(request.getTenantId()); carbonContext.setTenantId(request.getTenantId()); carbonContext.setTenantDomain(tenantDomain); requestHandler.onWorkflowCompletion(status, request, additionalParams); updateDBAtWorkflowCompletion(requestId, status); } catch (WorkflowException e) { updateDBAtWorkflowCompletion(requestId, WorkflowRequestStatus.FAILED.toString()); throw e; } catch (UserStoreException e) { updateDBAtWorkflowCompletion(requestId, WorkflowRequestStatus.FAILED.toString()); throw new InternalWorkflowException("Error when getting tenant domain for tenant id " + request .getTenantId()); } finally { PrivilegedCarbonContext.endTenantFlow(); } } }