From edb99723b666242ae3b634377232e41d1a4105f9 Mon Sep 17 00:00:00 2001 From: Ashirwada Date: Tue, 29 Oct 2024 08:44:40 +0530 Subject: [PATCH] Fixed review comments --- .../core/FSExtensionListenerImpl.java | 100 +++++++++--------- .../consent/ConsentEnforcementExecutor.java | 66 ++++++------ .../DefaultErrorHandlingExecutor.java | 60 +++++------ 3 files changed, 113 insertions(+), 113 deletions(-) diff --git a/financial-services-accelerator/components/org.wso2.financial.services.accelerator.gateway/src/main/java/org/wso2/financial/services/accelerator/gateway/executor/core/FSExtensionListenerImpl.java b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.gateway/src/main/java/org/wso2/financial/services/accelerator/gateway/executor/core/FSExtensionListenerImpl.java index 01de306e..9f33d8e4 100644 --- a/financial-services-accelerator/components/org.wso2.financial.services.accelerator.gateway/src/main/java/org/wso2/financial/services/accelerator/gateway/executor/core/FSExtensionListenerImpl.java +++ b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.gateway/src/main/java/org/wso2/financial/services/accelerator/gateway/executor/core/FSExtensionListenerImpl.java @@ -49,19 +49,19 @@ public class FSExtensionListenerImpl implements ExtensionListener { @Generated(message = "Ignoring since the method has covered in other tests") public ExtensionResponseDTO preProcessRequest(RequestContextDTO requestContextDTO) { - FSAPIRequestContext fsapiRequestContext = new FSAPIRequestContext(requestContextDTO, new HashMap<>()); + FSAPIRequestContext fsApiRequestContext = new FSAPIRequestContext(requestContextDTO, new HashMap<>()); for (FinancialServicesGatewayExecutor gatewayExecutor : - GatewayDataHolder.getInstance().getRequestRouter().getExecutorsForRequest(fsapiRequestContext)) { + GatewayDataHolder.getInstance().getRequestRouter().getExecutorsForRequest(fsApiRequestContext)) { if (log.isDebugEnabled()) { log.debug("Executing preProcessRequest for executor: " + gatewayExecutor.getClass().getName()); } - gatewayExecutor.preProcessRequest(fsapiRequestContext); + gatewayExecutor.preProcessRequest(fsApiRequestContext); } - if (!fsapiRequestContext.isError()) { - setPropertiesToCache(requestContextDTO.getMsgInfo().getMessageId(), fsapiRequestContext.getContextProps()); + if (!fsApiRequestContext.isError()) { + setPropertiesToCache(requestContextDTO.getMsgInfo().getMessageId(), fsApiRequestContext.getContextProps()); } - return getResponseDTOForRequest(fsapiRequestContext); + return getResponseDTOForRequest(fsApiRequestContext); } @Override @@ -71,20 +71,20 @@ public ExtensionResponseDTO postProcessRequest(RequestContextDTO requestContextD Map contextProps = getPropertiesFromCache(requestContextDTO.getMsgInfo().getMessageId() + GatewayConstants.CONTEXT_PROP_CACHE_KEY); - FSAPIRequestContext fsapiRequestContext = new FSAPIRequestContext(requestContextDTO, contextProps); + FSAPIRequestContext fsApiRequestContext = new FSAPIRequestContext(requestContextDTO, contextProps); for (FinancialServicesGatewayExecutor gatewayExecutor : - GatewayDataHolder.getInstance().getRequestRouter().getExecutorsForRequest(fsapiRequestContext)) { + GatewayDataHolder.getInstance().getRequestRouter().getExecutorsForRequest(fsApiRequestContext)) { if (log.isDebugEnabled()) { log.debug("Executing postProcessRequest for executor: " + gatewayExecutor.getClass().getName()); } - gatewayExecutor.postProcessRequest(fsapiRequestContext); + gatewayExecutor.postProcessRequest(fsApiRequestContext); } - if (!fsapiRequestContext.isError()) { + if (!fsApiRequestContext.isError()) { setPropertiesToCache(requestContextDTO.getMsgInfo().getMessageId() + - GatewayConstants.CONTEXT_PROP_CACHE_KEY, fsapiRequestContext.getContextProps()); + GatewayConstants.CONTEXT_PROP_CACHE_KEY, fsApiRequestContext.getContextProps()); } - return getResponseDTOForRequest(fsapiRequestContext); + return getResponseDTOForRequest(fsApiRequestContext); } @Override @@ -93,20 +93,20 @@ public ExtensionResponseDTO preProcessResponse(ResponseContextDTO responseContex Map contextProps = getPropertiesFromCache(responseContextDTO.getMsgInfo().getMessageId() + GatewayConstants.CONTEXT_PROP_CACHE_KEY); - FSAPIResponseContext fsapiResponseContext = new FSAPIResponseContext(responseContextDTO, contextProps); + FSAPIResponseContext fsApiResponseContext = new FSAPIResponseContext(responseContextDTO, contextProps); for (FinancialServicesGatewayExecutor gatewayExecutor : - GatewayDataHolder.getInstance().getRequestRouter().getExecutorsForResponse(fsapiResponseContext)) { + GatewayDataHolder.getInstance().getRequestRouter().getExecutorsForResponse(fsApiResponseContext)) { if (log.isDebugEnabled()) { log.debug("Executing preProcessResponse for executor: " + gatewayExecutor.getClass().getName()); } - gatewayExecutor.preProcessResponse(fsapiResponseContext); + gatewayExecutor.preProcessResponse(fsApiResponseContext); } - if (!fsapiResponseContext.isError()) { + if (!fsApiResponseContext.isError()) { setPropertiesToCache(responseContextDTO.getMsgInfo().getMessageId() + - GatewayConstants.CONTEXT_PROP_CACHE_KEY, fsapiResponseContext.getContextProps()); + GatewayConstants.CONTEXT_PROP_CACHE_KEY, fsApiResponseContext.getContextProps()); } - return getResponseDTOForResponse(fsapiResponseContext); + return getResponseDTOForResponse(fsApiResponseContext); } @Override @@ -115,15 +115,15 @@ public ExtensionResponseDTO postProcessResponse(ResponseContextDTO responseConte Map contextProps = getPropertiesFromCache(responseContextDTO.getMsgInfo().getMessageId() + GatewayConstants.CONTEXT_PROP_CACHE_KEY); - FSAPIResponseContext fsapiResponseContext = new FSAPIResponseContext(responseContextDTO, contextProps); + FSAPIResponseContext fsApiResponseContext = new FSAPIResponseContext(responseContextDTO, contextProps); for (FinancialServicesGatewayExecutor gatewayExecutor : - GatewayDataHolder.getInstance().getRequestRouter().getExecutorsForResponse(fsapiResponseContext)) { + GatewayDataHolder.getInstance().getRequestRouter().getExecutorsForResponse(fsApiResponseContext)) { if (log.isDebugEnabled()) { log.debug("Executing postProcessResponse for executor: " + gatewayExecutor.getClass().getName()); } - gatewayExecutor.postProcessResponse(fsapiResponseContext); + gatewayExecutor.postProcessResponse(fsApiResponseContext); } - ExtensionResponseDTO responseDTOForResponse = getResponseDTOForResponse(fsapiResponseContext); + ExtensionResponseDTO responseDTOForResponse = getResponseDTOForResponse(fsApiResponseContext); removePropertiesFromCache(responseContextDTO.getMsgInfo().getMessageId() + GatewayConstants.CONTEXT_PROP_CACHE_KEY); return responseDTOForResponse; @@ -132,27 +132,27 @@ public ExtensionResponseDTO postProcessResponse(ResponseContextDTO responseConte /** * Method to get response DTO for request path. * - * @param fsapiRequestContext API Request Context + * @param fsApiRequestContext API Request Context * @return ExtensionResponseDTO Extension Response DTO */ - protected ExtensionResponseDTO getResponseDTOForRequest(FSAPIRequestContext fsapiRequestContext) { + protected ExtensionResponseDTO getResponseDTOForRequest(FSAPIRequestContext fsApiRequestContext) { ExtensionResponseDTO extensionResponseDTO = new ExtensionResponseDTO(); - if (fsapiRequestContext.isError()) { - int statusCode = (!fsapiRequestContext.getContextProps().containsKey(GatewayConstants.ERROR_STATUS_PROP)) ? - HttpStatus.SC_INTERNAL_SERVER_ERROR : Integer.parseInt(fsapiRequestContext + if (fsApiRequestContext.isError()) { + int statusCode = (!fsApiRequestContext.getContextProps().containsKey(GatewayConstants.ERROR_STATUS_PROP)) ? + HttpStatus.SC_INTERNAL_SERVER_ERROR : Integer.parseInt(fsApiRequestContext .getContextProperty(GatewayConstants.ERROR_STATUS_PROP).toString()); extensionResponseDTO.setStatusCode(statusCode); extensionResponseDTO.setResponseStatus(ExtensionResponseStatus.RETURN_ERROR.toString()); - } else if (fsapiRequestContext.getContextProps().containsKey(GatewayConstants.IS_RETURN_RESPONSE) && - Boolean.parseBoolean(fsapiRequestContext.getContextProps() + } else if (fsApiRequestContext.getContextProps().containsKey(GatewayConstants.IS_RETURN_RESPONSE) && + Boolean.parseBoolean(fsApiRequestContext.getContextProps() .get(GatewayConstants.IS_RETURN_RESPONSE).toString())) { - Map headers = fsapiRequestContext.getMsgInfo().getHeaders(); + Map headers = fsApiRequestContext.getMsgInfo().getHeaders(); headers.put(GatewayConstants.CONTENT_TYPE_TAG, GatewayConstants.JSON_CONTENT_TYPE); - fsapiRequestContext.getMsgInfo().setHeaders(headers); + fsApiRequestContext.getMsgInfo().setHeaders(headers); extensionResponseDTO.setHeaders(headers); - if (fsapiRequestContext.getContextProps().containsKey(GatewayConstants.MODIFIED_STATUS)) { - extensionResponseDTO.setStatusCode(Integer.parseInt(fsapiRequestContext.getContextProps() + if (fsApiRequestContext.getContextProps().containsKey(GatewayConstants.MODIFIED_STATUS)) { + extensionResponseDTO.setStatusCode(Integer.parseInt(fsApiRequestContext.getContextProps() .get(GatewayConstants.MODIFIED_STATUS).toString())); } extensionResponseDTO.setResponseStatus(ExtensionResponseStatus.RETURN_ERROR.toString()); @@ -160,40 +160,40 @@ protected ExtensionResponseDTO getResponseDTOForRequest(FSAPIRequestContext fsap extensionResponseDTO.setResponseStatus(ExtensionResponseStatus.CONTINUE.toString()); } - String modifiedPayload = fsapiRequestContext.getModifiedPayload(); + String modifiedPayload = fsApiRequestContext.getModifiedPayload(); if (modifiedPayload != null) { extensionResponseDTO.setPayload(new ByteArrayInputStream(modifiedPayload.getBytes(StandardCharsets.UTF_8))); } - setHeadersToResponse(extensionResponseDTO, fsapiRequestContext.getAddedHeaders(), - fsapiRequestContext.getMsgInfo().getHeaders()); + setHeadersToResponse(extensionResponseDTO, fsApiRequestContext.getAddedHeaders(), + fsApiRequestContext.getMsgInfo().getHeaders()); return extensionResponseDTO; } /** * Method to get response DTO for response path. * - * @param fsapiResponseContext API Response Context + * @param fsApiResponseContext API Response Context * @return ExtensionResponseDTO Extension Response DTO */ - protected ExtensionResponseDTO getResponseDTOForResponse(FSAPIResponseContext fsapiResponseContext) { + protected ExtensionResponseDTO getResponseDTOForResponse(FSAPIResponseContext fsApiResponseContext) { ExtensionResponseDTO extensionResponseDTO = new ExtensionResponseDTO(); - if (fsapiResponseContext.isError()) { - int statusCode = (!fsapiResponseContext.getContextProps().containsKey(GatewayConstants.ERROR_STATUS_PROP)) ? - HttpStatus.SC_INTERNAL_SERVER_ERROR : Integer.parseInt(fsapiResponseContext + if (fsApiResponseContext.isError()) { + int statusCode = (!fsApiResponseContext.getContextProps().containsKey(GatewayConstants.ERROR_STATUS_PROP)) ? + HttpStatus.SC_INTERNAL_SERVER_ERROR : Integer.parseInt(fsApiResponseContext .getContextProperty(GatewayConstants.ERROR_STATUS_PROP).toString()); extensionResponseDTO.setStatusCode(statusCode); extensionResponseDTO.setResponseStatus(ExtensionResponseStatus.RETURN_ERROR.toString()); - } else if (fsapiResponseContext.getContextProps().containsKey(GatewayConstants.IS_RETURN_RESPONSE) && - Boolean.parseBoolean(fsapiResponseContext.getContextProps() + } else if (fsApiResponseContext.getContextProps().containsKey(GatewayConstants.IS_RETURN_RESPONSE) && + Boolean.parseBoolean(fsApiResponseContext.getContextProps() .get(GatewayConstants.IS_RETURN_RESPONSE).toString())) { - Map headers = fsapiResponseContext.getMsgInfo().getHeaders(); + Map headers = fsApiResponseContext.getMsgInfo().getHeaders(); headers.put(GatewayConstants.CONTENT_TYPE_TAG, GatewayConstants.JSON_CONTENT_TYPE); - fsapiResponseContext.getMsgInfo().setHeaders(headers); + fsApiResponseContext.getMsgInfo().setHeaders(headers); extensionResponseDTO.setHeaders(headers); - if (fsapiResponseContext.getContextProps().containsKey(GatewayConstants.MODIFIED_STATUS)) { - extensionResponseDTO.setStatusCode((Integer.parseInt(fsapiResponseContext.getContextProps() + if (fsApiResponseContext.getContextProps().containsKey(GatewayConstants.MODIFIED_STATUS)) { + extensionResponseDTO.setStatusCode((Integer.parseInt(fsApiResponseContext.getContextProps() .get(GatewayConstants.MODIFIED_STATUS).toString()))); } extensionResponseDTO.setResponseStatus(ExtensionResponseStatus.RETURN_ERROR.toString()); @@ -201,13 +201,13 @@ protected ExtensionResponseDTO getResponseDTOForResponse(FSAPIResponseContext fs extensionResponseDTO.setResponseStatus(ExtensionResponseStatus.CONTINUE.toString()); } - String modifiedPayload = fsapiResponseContext.getModifiedPayload(); + String modifiedPayload = fsApiResponseContext.getModifiedPayload(); if (modifiedPayload != null) { extensionResponseDTO.setPayload(new ByteArrayInputStream(modifiedPayload.getBytes(StandardCharsets.UTF_8))); } - setHeadersToResponse(extensionResponseDTO, fsapiResponseContext.getAddedHeaders(), - fsapiResponseContext.getMsgInfo().getHeaders()); + setHeadersToResponse(extensionResponseDTO, fsApiResponseContext.getAddedHeaders(), + fsApiResponseContext.getMsgInfo().getHeaders()); return extensionResponseDTO; } diff --git a/financial-services-accelerator/components/org.wso2.financial.services.accelerator.gateway/src/main/java/org/wso2/financial/services/accelerator/gateway/executor/impl/consent/ConsentEnforcementExecutor.java b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.gateway/src/main/java/org/wso2/financial/services/accelerator/gateway/executor/impl/consent/ConsentEnforcementExecutor.java index 787de8c9..30ab8f33 100644 --- a/financial-services-accelerator/components/org.wso2.financial.services.accelerator.gateway/src/main/java/org/wso2/financial/services/accelerator/gateway/executor/impl/consent/ConsentEnforcementExecutor.java +++ b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.gateway/src/main/java/org/wso2/financial/services/accelerator/gateway/executor/impl/consent/ConsentEnforcementExecutor.java @@ -87,42 +87,42 @@ public class ConsentEnforcementExecutor implements FinancialServicesGatewayExecu /** * Method to handle request. * - * @param fsapiRequestContext FS request context object + * @param fsApiRequestContext FS request context object */ @Generated(message = "Unit testable components are covered") @Override - public void preProcessRequest(FSAPIRequestContext fsapiRequestContext) { + public void preProcessRequest(FSAPIRequestContext fsApiRequestContext) { } /** * Method to handle post request. * - * @param fsapiRequestContext FS request context object + * @param fsApiRequestContext FS request context object */ @Override - public void postProcessRequest(FSAPIRequestContext fsapiRequestContext) { + public void postProcessRequest(FSAPIRequestContext fsApiRequestContext) { // Consent ID is required for consent enforcement. If the consent ID is null, we are assume this is a // pre-consent creation call. Therefore consent enforcement is not required. - if (fsapiRequestContext.isError() || fsapiRequestContext.getConsentId() == null) { + if (fsApiRequestContext.isError() || fsApiRequestContext.getConsentId() == null) { return; } - Map requestHeaders = fsapiRequestContext.getMsgInfo().getHeaders(); + Map requestHeaders = fsApiRequestContext.getMsgInfo().getHeaders(); Map additionalParams = new HashMap<>(); - additionalParams.put(ELECTED_RESOURCE_TAG, fsapiRequestContext.getMsgInfo().getElectedResource()); - additionalParams.put(CONSENT_ID_TAG, fsapiRequestContext.getConsentId()); - additionalParams.put(USER_ID_TAG, fsapiRequestContext.getApiRequestInfo().getUsername()); - additionalParams.put(CLIENT_ID_TAG, fsapiRequestContext.getApiRequestInfo().getConsumerKey()); - additionalParams.put(RESOURCE_PARAMS, getResourceParamMap(fsapiRequestContext)); + additionalParams.put(ELECTED_RESOURCE_TAG, fsApiRequestContext.getMsgInfo().getElectedResource()); + additionalParams.put(CONSENT_ID_TAG, fsApiRequestContext.getConsentId()); + additionalParams.put(USER_ID_TAG, fsApiRequestContext.getApiRequestInfo().getUsername()); + additionalParams.put(CLIENT_ID_TAG, fsApiRequestContext.getApiRequestInfo().getConsumerKey()); + additionalParams.put(RESOURCE_PARAMS, getResourceParamMap(fsApiRequestContext)); JSONObject validationRequest; - if (StringUtils.isNotBlank(fsapiRequestContext.getModifiedPayload())) { + if (StringUtils.isNotBlank(fsApiRequestContext.getModifiedPayload())) { validationRequest = createValidationRequestPayload(requestHeaders, - fsapiRequestContext.getModifiedPayload(), additionalParams); + fsApiRequestContext.getModifiedPayload(), additionalParams); } else { validationRequest = createValidationRequestPayload(requestHeaders, - fsapiRequestContext.getRequestPayload(), additionalParams); + fsApiRequestContext.getRequestPayload(), additionalParams); } String enforcementJWTPayload = generateJWT(validationRequest.toString()); JSONObject jsonResponse; @@ -130,7 +130,7 @@ public void postProcessRequest(FSAPIRequestContext fsapiRequestContext) { String response = invokeConsentValidationService(enforcementJWTPayload); jsonResponse = new JSONObject(response); } catch (IOException | FinancialServicesException e) { - handleError(fsapiRequestContext, FinancialServicesErrorCodes.CONSENT_VALIDATION_REQUEST_FAILURE, + handleError(fsApiRequestContext, FinancialServicesErrorCodes.CONSENT_VALIDATION_REQUEST_FAILURE, e.getMessage(), FinancialServicesErrorCodes.SERVER_ERROR_CODE); return; } @@ -140,18 +140,18 @@ public void postProcessRequest(FSAPIRequestContext fsapiRequestContext) { String errorCode = jsonResponse.get(ERROR_CODE).toString(); String errorMessage = jsonResponse.get(ERROR_MESSAGE).toString(); String httpCode = jsonResponse.get(HTTP_CODE).toString(); - handleError(fsapiRequestContext, errorCode, errorMessage, httpCode); + handleError(fsApiRequestContext, errorCode, errorMessage, httpCode); return; } else if (!jsonResponse.isNull(MODIFIED_PAYLOAD)) { Object modifiedPayloadObj = jsonResponse.get(MODIFIED_PAYLOAD); if (modifiedPayloadObj != null) { - fsapiRequestContext.setModifiedPayload(modifiedPayloadObj.toString()); + fsApiRequestContext.setModifiedPayload(modifiedPayloadObj.toString()); } } else if (!jsonResponse.isNull(CONSENT_INFO)) { Object consentInformationObj = jsonResponse.get(CONSENT_INFO); if (consentInformationObj != null) { requestHeaders.put(INFO_HEADER_TAG, consentInformationObj.toString()); - fsapiRequestContext.setAddedHeaders(requestHeaders); + fsApiRequestContext.setAddedHeaders(requestHeaders); } } } @@ -159,20 +159,20 @@ public void postProcessRequest(FSAPIRequestContext fsapiRequestContext) { /** * Method to handle response. * - * @param fsapiResponseContext FS response context object + * @param fsApiResponseContext FS response context object */ @Override - public void preProcessResponse(FSAPIResponseContext fsapiResponseContext) { + public void preProcessResponse(FSAPIResponseContext fsApiResponseContext) { } /** * Method to handle post response. * - * @param fsapiResponseContext FS response context object + * @param fsApiResponseContext FS response context object */ @Override - public void postProcessResponse(FSAPIResponseContext fsapiResponseContext) { + public void postProcessResponse(FSAPIResponseContext fsApiResponseContext) { } @@ -260,19 +260,19 @@ private String invokeConsentValidationService(String enforcementJWTPayload) thro /** * Method to handle errors. * - * @param fsapiRequestContext API Context + * @param fsApiRequestContext API Context * @param errorCode Error Code * @param errorMessage Error Message * @param httpCode HTTP status code ( in 4XX range) */ - protected void handleError(FSAPIRequestContext fsapiRequestContext, String errorCode, String errorMessage, + protected void handleError(FSAPIRequestContext fsApiRequestContext, String errorCode, String errorMessage, String httpCode) { - fsapiRequestContext.setError(true); - ArrayList errors = fsapiRequestContext.getErrors(); + fsApiRequestContext.setError(true); + ArrayList errors = fsApiRequestContext.getErrors(); errors.add(new FSExecutorError(errorCode, ERROR_TITLE, errorMessage, httpCode)); - fsapiRequestContext.setErrors(errors); - fsapiRequestContext.addContextProperty(GatewayConstants.ERROR_STATUS_PROP, httpCode); + fsApiRequestContext.setErrors(errors); + fsApiRequestContext.addContextProperty(GatewayConstants.ERROR_STATUS_PROP, httpCode); } /** @@ -302,16 +302,16 @@ protected JSONObject createValidationRequestPayload(Map requestH /** * Method to construct resource parameter map to invoke the validation service. * - * @param fsapiRequestContext FS request context object + * @param fsApiRequestContext FS request context object * @return A Map containing resource path(ex: /aisp/accounts/{AccountId}?queryParam=urlEncodedQueryParamValue), * http method and context(ex: /open-banking/v3.1/aisp) */ - private Map getResourceParamMap(FSAPIRequestContext fsapiRequestContext) { + private Map getResourceParamMap(FSAPIRequestContext fsApiRequestContext) { Map resourceMap = new HashMap<>(); - resourceMap.put(RESOURCE_TAG, fsapiRequestContext.getMsgInfo().getResource()); - resourceMap.put(HTTP_METHOD, fsapiRequestContext.getMsgInfo().getHttpMethod()); - resourceMap.put(CONTEXT_TAG, fsapiRequestContext.getApiRequestInfo().getContext()); + resourceMap.put(RESOURCE_TAG, fsApiRequestContext.getMsgInfo().getResource()); + resourceMap.put(HTTP_METHOD, fsApiRequestContext.getMsgInfo().getHttpMethod()); + resourceMap.put(CONTEXT_TAG, fsApiRequestContext.getApiRequestInfo().getContext()); return resourceMap; } diff --git a/financial-services-accelerator/components/org.wso2.financial.services.accelerator.gateway/src/main/java/org/wso2/financial/services/accelerator/gateway/executor/impl/error/handling/DefaultErrorHandlingExecutor.java b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.gateway/src/main/java/org/wso2/financial/services/accelerator/gateway/executor/impl/error/handling/DefaultErrorHandlingExecutor.java index aca18060..6eeca3aa 100644 --- a/financial-services-accelerator/components/org.wso2.financial.services.accelerator.gateway/src/main/java/org/wso2/financial/services/accelerator/gateway/executor/impl/error/handling/DefaultErrorHandlingExecutor.java +++ b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.gateway/src/main/java/org/wso2/financial/services/accelerator/gateway/executor/impl/error/handling/DefaultErrorHandlingExecutor.java @@ -42,55 +42,55 @@ public class DefaultErrorHandlingExecutor implements FinancialServicesGatewayExe /** * Method to handle pre request. * - * @param fsapiRequestContext FS request context object + * @param fsApiRequestContext FS request context object */ @Override - public void preProcessRequest(FSAPIRequestContext fsapiRequestContext) { + public void preProcessRequest(FSAPIRequestContext fsApiRequestContext) { - handleRequestError(fsapiRequestContext); + handleRequestError(fsApiRequestContext); } /** * Method to handle post request. * - * @param fsapiRequestContext FS request context object + * @param fsApiRequestContext FS request context object */ @Override - public void postProcessRequest(FSAPIRequestContext fsapiRequestContext) { + public void postProcessRequest(FSAPIRequestContext fsApiRequestContext) { - handleRequestError(fsapiRequestContext); + handleRequestError(fsApiRequestContext); } /** * Method to handle pre response. * - * @param fsapiResponseContext FS response context object + * @param fsApiResponseContext FS response context object */ @Override - public void preProcessResponse(FSAPIResponseContext fsapiResponseContext) { + public void preProcessResponse(FSAPIResponseContext fsApiResponseContext) { - handleResponseError(fsapiResponseContext); + handleResponseError(fsApiResponseContext); } /** * Method to handle post response. * - * @param fsapiResponseContext FS response context object + * @param fsApiResponseContext FS response context object */ @Override - public void postProcessResponse(FSAPIResponseContext fsapiResponseContext) { + public void postProcessResponse(FSAPIResponseContext fsApiResponseContext) { - handleResponseError(fsapiResponseContext); + handleResponseError(fsApiResponseContext); } - private void handleRequestError(FSAPIRequestContext fsapiRequestContext) { + private void handleRequestError(FSAPIRequestContext fsApiRequestContext) { - if (!fsapiRequestContext.isError()) { + if (!fsApiRequestContext.isError()) { return; } JSONObject payload = new JSONObject(); - ArrayList errors = fsapiRequestContext.getErrors(); + ArrayList errors = fsApiRequestContext.getErrors(); JSONArray errorList = getErrorJSON(errors); HashSet statusCodes = new HashSet<>(); @@ -100,31 +100,31 @@ private void handleRequestError(FSAPIRequestContext fsapiRequestContext) { payload.put(ERRORS_TAG, errorList); if (errorList.length() != 0) { - fsapiRequestContext.setModifiedPayload(payload.toString()); - Map addedHeaders = fsapiRequestContext.getAddedHeaders(); + fsApiRequestContext.setModifiedPayload(payload.toString()); + Map addedHeaders = fsApiRequestContext.getAddedHeaders(); addedHeaders.put(GatewayConstants.CONTENT_TYPE_TAG, GatewayConstants.JSON_CONTENT_TYPE); - fsapiRequestContext.setAddedHeaders(addedHeaders); + fsApiRequestContext.setAddedHeaders(addedHeaders); } int statusCode; - if (fsapiRequestContext.getContextProps().containsKey(GatewayConstants.ERROR_STATUS_PROP)) { - statusCode = Integer.parseInt(fsapiRequestContext + if (fsApiRequestContext.getContextProps().containsKey(GatewayConstants.ERROR_STATUS_PROP)) { + statusCode = Integer.parseInt(fsApiRequestContext .getContextProperty(GatewayConstants.ERROR_STATUS_PROP).toString()); } else if (isAnyClientErrors(statusCodes)) { statusCode = HttpStatus.SC_BAD_REQUEST; } else { statusCode = HttpStatus.SC_INTERNAL_SERVER_ERROR; } - fsapiRequestContext.addContextProperty(GatewayConstants.ERROR_STATUS_PROP, + fsApiRequestContext.addContextProperty(GatewayConstants.ERROR_STATUS_PROP, String.valueOf(statusCode)); } - private void handleResponseError(FSAPIResponseContext fsapiResponseContext) { + private void handleResponseError(FSAPIResponseContext fsApiResponseContext) { - if (!fsapiResponseContext.isError()) { + if (!fsApiResponseContext.isError()) { return; } JSONObject payload = new JSONObject(); - ArrayList errors = fsapiResponseContext.getErrors(); + ArrayList errors = fsApiResponseContext.getErrors(); JSONArray errorList = getErrorJSON(errors); HashSet statusCodes = new HashSet<>(); @@ -133,20 +133,20 @@ private void handleResponseError(FSAPIResponseContext fsapiResponseContext) { } payload.put(ERRORS_TAG, errorList); - fsapiResponseContext.setModifiedPayload(payload.toString()); - Map addedHeaders = fsapiResponseContext.getAddedHeaders(); + fsApiResponseContext.setModifiedPayload(payload.toString()); + Map addedHeaders = fsApiResponseContext.getAddedHeaders(); addedHeaders.put(GatewayConstants.CONTENT_TYPE_TAG, GatewayConstants.JSON_CONTENT_TYPE); - fsapiResponseContext.setAddedHeaders(addedHeaders); + fsApiResponseContext.setAddedHeaders(addedHeaders); int statusCode; - if (fsapiResponseContext.getContextProps().containsKey(GatewayConstants.ERROR_STATUS_PROP)) { - statusCode = Integer.parseInt(fsapiResponseContext + if (fsApiResponseContext.getContextProps().containsKey(GatewayConstants.ERROR_STATUS_PROP)) { + statusCode = Integer.parseInt(fsApiResponseContext .getContextProperty(GatewayConstants.ERROR_STATUS_PROP).toString()); } else if (isAnyClientErrors(statusCodes)) { statusCode = HttpStatus.SC_BAD_REQUEST; } else { statusCode = HttpStatus.SC_INTERNAL_SERVER_ERROR; } - fsapiResponseContext.addContextProperty(GatewayConstants.ERROR_STATUS_PROP, + fsApiResponseContext.addContextProperty(GatewayConstants.ERROR_STATUS_PROP, String.valueOf(statusCode)); }