diff --git a/financial-services-accelerator/components/org.wso2.financial.services.accelerator.common/src/main/java/org/wso2/financial/services/accelerator/common/constant/FinancialServicesConstants.java b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.common/src/main/java/org/wso2/financial/services/accelerator/common/constant/FinancialServicesConstants.java
index 0d2591c4..ccc7707d 100644
--- a/financial-services-accelerator/components/org.wso2.financial.services.accelerator.common/src/main/java/org/wso2/financial/services/accelerator/common/constant/FinancialServicesConstants.java
+++ b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.common/src/main/java/org/wso2/financial/services/accelerator/common/constant/FinancialServicesConstants.java
@@ -82,5 +82,9 @@ public class FinancialServicesConstants {
"Identity.TokenSubject.RemoveUserStoreDomainFromSubject";
public static final String REMOVE_TENANT_DOMAIN_FROM_SUBJECT =
"Identity.TokenSubject.RemoveTenantDomainFromSubject";
+ public static final String PUBLISHER_HOSTNAME = "PublisherURL";
+ public static final String REQUEST_ROUTER = "Gateway.RequestRouter";
+ public static final String GATEWAY_CACHE_EXPIRY = "Gateway.Cache.GatewayCache.CacheAccessExpiry";
+ public static final String GATEWAY_CACHE_MODIFIED_EXPIRY = "Gateway.Cache.GatewayCache.CacheModifiedExpiry";
}
diff --git a/financial-services-accelerator/components/org.wso2.financial.services.accelerator.gateway/pom.xml b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.gateway/pom.xml
new file mode 100644
index 00000000..86ea23cf
--- /dev/null
+++ b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.gateway/pom.xml
@@ -0,0 +1,230 @@
+
+
+
+ * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + *
+ * http://www.apache.org/licenses/LICENSE-2.0 + *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.wso2.financial.services.accelerator.gateway.cache;
+
+import org.wso2.financial.services.accelerator.common.caching.FinancialServicesBaseCache;
+import org.wso2.financial.services.accelerator.gateway.internal.GatewayDataHolder;
+
+/**
+ * Cache definition to store API Resource Security Schemes
+ */
+public class GatewayCache extends FinancialServicesBaseCache
+ * WSO2 LLC. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.wso2.financial.services.accelerator.gateway.cache;
+
+
+import org.wso2.financial.services.accelerator.common.caching.FinancialServicesBaseCacheKey;
+
+import java.io.Serializable;
+import java.util.Objects;
+
+/**
+ * Cache Key for Financial Services Gateway cache.
+ */
+public class GatewayCacheKey extends FinancialServicesBaseCacheKey implements Serializable {
+
+ private static final long serialVersionUID = 883027070771592120L;
+ public String gatewayCacheKey;
+
+ public GatewayCacheKey(String gatewayCacheKey) {
+
+ this.gatewayCacheKey = gatewayCacheKey;
+ }
+
+ public static GatewayCacheKey of(String gatewayCacheKey) {
+
+ return new GatewayCacheKey(gatewayCacheKey);
+ }
+
+ @Override
+ public boolean equals(Object o) {
+
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ GatewayCacheKey that = (GatewayCacheKey) o;
+ return Objects.equals(gatewayCacheKey, that.gatewayCacheKey);
+ }
+
+ @Override
+ public int hashCode() {
+
+ return Objects.hash(gatewayCacheKey);
+ }
+}
diff --git a/financial-services-accelerator/components/org.wso2.financial.services.accelerator.gateway/src/main/java/org/wso2/financial/services/accelerator/gateway/executor/core/AbstractRequestRouter.java b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.gateway/src/main/java/org/wso2/financial/services/accelerator/gateway/executor/core/AbstractRequestRouter.java
new file mode 100644
index 00000000..aef8ca76
--- /dev/null
+++ b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.gateway/src/main/java/org/wso2/financial/services/accelerator/gateway/executor/core/AbstractRequestRouter.java
@@ -0,0 +1,85 @@
+/**
+ * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com).
+ *
+ * WSO2 LLC. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.wso2.financial.services.accelerator.gateway.executor.core;
+
+
+import org.wso2.financial.services.accelerator.common.util.FinancialServicesUtils;
+import org.wso2.financial.services.accelerator.common.util.Generated;
+import org.wso2.financial.services.accelerator.gateway.executor.model.FSAPIRequestContext;
+import org.wso2.financial.services.accelerator.gateway.executor.model.FSAPIResponseContext;
+import org.wso2.financial.services.accelerator.gateway.internal.GatewayDataHolder;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * Financial Services abstract Request Router.
+ */
+public abstract class AbstractRequestRouter {
+
+ private Map
+ * WSO2 LLC. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.wso2.financial.services.accelerator.gateway.executor.core;
+
+import org.wso2.financial.services.accelerator.gateway.executor.model.FSAPIRequestContext;
+import org.wso2.financial.services.accelerator.gateway.executor.model.FSAPIResponseContext;
+import org.wso2.financial.services.accelerator.gateway.util.GatewayConstants;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Financial Services Default Request Router.
+ */
+public class DefaultRequestRouter extends AbstractRequestRouter {
+
+ private static final List
+ * WSO2 LLC. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.wso2.financial.services.accelerator.gateway.executor.core;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.http.HttpStatus;
+import org.wso2.carbon.apimgt.common.gateway.dto.ExtensionResponseDTO;
+import org.wso2.carbon.apimgt.common.gateway.dto.ExtensionResponseStatus;
+import org.wso2.carbon.apimgt.common.gateway.dto.RequestContextDTO;
+import org.wso2.carbon.apimgt.common.gateway.dto.ResponseContextDTO;
+import org.wso2.carbon.apimgt.common.gateway.extensionlistener.ExtensionListener;
+import org.wso2.financial.services.accelerator.common.util.Generated;
+import org.wso2.financial.services.accelerator.gateway.cache.GatewayCacheKey;
+import org.wso2.financial.services.accelerator.gateway.executor.model.FSAPIRequestContext;
+import org.wso2.financial.services.accelerator.gateway.executor.model.FSAPIResponseContext;
+import org.wso2.financial.services.accelerator.gateway.internal.GatewayDataHolder;
+import org.wso2.financial.services.accelerator.gateway.util.GatewayConstants;
+
+import java.io.ByteArrayInputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Financial Services implementation for Extension listener.
+ */
+public class FSExtensionListenerImpl implements ExtensionListener {
+
+ private static final Log log = LogFactory.getLog(FSExtensionListenerImpl.class);
+
+ @Override
+ @Generated(message = "Ignoring since the method has covered in other tests")
+ public ExtensionResponseDTO preProcessRequest(RequestContextDTO requestContextDTO) {
+
+ FSAPIRequestContext fsapiRequestContext = new FSAPIRequestContext(requestContextDTO, new HashMap<>());
+ for (FinancialServicesGatewayExecutor gatewayExecutor :
+ GatewayDataHolder.getInstance().getRequestRouter().getExecutorsForRequest(fsapiRequestContext)) {
+ if (log.isDebugEnabled()) {
+ log.debug("Executing preProcessRequest for executor: " + gatewayExecutor.getClass().getName());
+ }
+ gatewayExecutor.preProcessRequest(fsapiRequestContext);
+ }
+
+ if (!fsapiRequestContext.isError()) {
+ setPropertiesToCache(requestContextDTO.getMsgInfo().getMessageId(), fsapiRequestContext.getContextProps());
+ }
+ return getResponseDTOForRequest(fsapiRequestContext);
+ }
+
+ @Override
+ @Generated(message = "Ignoring since the method has covered in other tests")
+ public ExtensionResponseDTO postProcessRequest(RequestContextDTO requestContextDTO) {
+
+ Map
+ * WSO2 LLC. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.wso2.financial.services.accelerator.gateway.executor.core;
+
+import org.wso2.financial.services.accelerator.gateway.executor.model.FSAPIRequestContext;
+import org.wso2.financial.services.accelerator.gateway.executor.model.FSAPIResponseContext;
+
+/**
+ * Financial Services executor interface.
+ */
+public interface FinancialServicesGatewayExecutor {
+
+ /**
+ * Method to handle pre request
+ *
+ * @param fsapiRequestContext FS request context object
+ */
+ public void preProcessRequest(FSAPIRequestContext fsapiRequestContext);
+
+ /**
+ * Method to handle post request
+ *
+ * @param fsapiRequestContext FS request context object
+ */
+ public void postProcessRequest(FSAPIRequestContext fsapiRequestContext);
+
+ /**
+ * Method to handle pre response
+ *
+ * @param fsapiResponseContext FS response context object
+ */
+ public void preProcessResponse(FSAPIResponseContext fsapiResponseContext);
+
+ /**
+ * Method to handle post response
+ *
+ * @param fsapiResponseContext FS response context object
+ */
+ public void postProcessResponse(FSAPIResponseContext fsapiResponseContext);
+}
diff --git a/financial-services-accelerator/components/org.wso2.financial.services.accelerator.gateway/src/main/java/org/wso2/financial/services/accelerator/gateway/executor/model/FSAPIRequestContext.java b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.gateway/src/main/java/org/wso2/financial/services/accelerator/gateway/executor/model/FSAPIRequestContext.java
new file mode 100644
index 00000000..5cc58b9e
--- /dev/null
+++ b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.gateway/src/main/java/org/wso2/financial/services/accelerator/gateway/executor/model/FSAPIRequestContext.java
@@ -0,0 +1,263 @@
+/**
+ * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com).
+ *
+ * WSO2 LLC. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.wso2.financial.services.accelerator.gateway.executor.model;
+
+import io.swagger.parser.OpenAPIParser;
+import io.swagger.v3.oas.models.OpenAPI;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.wso2.carbon.apimgt.common.gateway.dto.APIRequestInfoDTO;
+import org.wso2.carbon.apimgt.common.gateway.dto.MsgInfoDTO;
+import org.wso2.carbon.apimgt.common.gateway.dto.RequestContextDTO;
+import org.wso2.financial.services.accelerator.common.constant.FinancialServicesConstants;
+import org.wso2.financial.services.accelerator.common.constant.FinancialServicesErrorCodes;
+import org.wso2.financial.services.accelerator.gateway.cache.GatewayCacheKey;
+import org.wso2.financial.services.accelerator.gateway.internal.GatewayDataHolder;
+import org.wso2.financial.services.accelerator.gateway.util.GatewayConstants;
+import org.wso2.financial.services.accelerator.gateway.util.GatewayUtils;
+
+import java.io.UnsupportedEncodingException;
+import java.security.cert.Certificate;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+
+
+/**
+ * Financial services executor request context.
+ */
+public class FSAPIRequestContext extends RequestContextDTO {
+
+ private static final Log log = LogFactory.getLog(FSAPIRequestContext.class);
+ private final RequestContextDTO requestContextDTO;
+ private Map
+ * WSO2 LLC. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.wso2.financial.services.accelerator.gateway.executor.model;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.http.HttpStatus;
+import org.json.JSONObject;
+import org.json.XML;
+import org.wso2.carbon.apimgt.common.gateway.dto.APIRequestInfoDTO;
+import org.wso2.carbon.apimgt.common.gateway.dto.MsgInfoDTO;
+import org.wso2.carbon.apimgt.common.gateway.dto.ResponseContextDTO;
+import org.wso2.financial.services.accelerator.common.constant.FinancialServicesErrorCodes;
+import org.wso2.financial.services.accelerator.gateway.util.GatewayConstants;
+import org.wso2.financial.services.accelerator.gateway.util.GatewayUtils;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Financial services executor response context.
+ */
+public class FSAPIResponseContext extends ResponseContextDTO {
+
+ private static final Log log = LogFactory.getLog(FSAPIResponseContext.class);
+ private ResponseContextDTO responseContextDTO;
+ private Map
+ * WSO2 LLC. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.wso2.financial.services.accelerator.gateway.executor.model;
+
+import java.util.Map;
+
+/**
+ * Error model for Financial Services executors.
+ */
+public class FSExecutorError {
+
+ private String code;
+ private String title;
+ private String message;
+ private String httpStatusCode;
+ private Map
+ * WSO2 LLC. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.wso2.financial.services.accelerator.gateway.internal;
+
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.wso2.carbon.apimgt.impl.APIManagerConfigurationService;
+import org.wso2.financial.services.accelerator.common.config.FinancialServicesConfigurationService;
+import org.wso2.financial.services.accelerator.common.constant.FinancialServicesConstants;
+import org.wso2.financial.services.accelerator.common.exception.FinancialServicesException;
+import org.wso2.financial.services.accelerator.common.util.FinancialServicesUtils;
+import org.wso2.financial.services.accelerator.common.util.HTTPClientUtils;
+import org.wso2.financial.services.accelerator.gateway.cache.GatewayCache;
+import org.wso2.financial.services.accelerator.gateway.executor.core.AbstractRequestRouter;
+
+import java.util.Map;
+
+/**
+ * Data holder for executor core
+ */
+public class GatewayDataHolder {
+
+ private static volatile GatewayDataHolder instance;
+ private static volatile CloseableHttpClient httpClient;
+ private static volatile GatewayCache gatewayCache;
+ private FinancialServicesConfigurationService financialServicesConfigurationService;
+ private int gatewayCacheAccessExpiry;
+ private int gatewayCacheModifiedExpiry;
+ private APIManagerConfigurationService apiManagerConfigurationService;
+ private AbstractRequestRouter requestRouter;
+
+ private GatewayDataHolder() {
+
+ }
+
+ public static GatewayDataHolder getInstance() {
+
+ if (instance == null) {
+ synchronized (GatewayDataHolder.class) {
+ if (instance == null) {
+ instance = new GatewayDataHolder();
+ }
+ }
+ }
+ return instance;
+ }
+
+ public static CloseableHttpClient getHttpClient() throws FinancialServicesException {
+
+ if (httpClient == null) {
+ synchronized (GatewayDataHolder.class) {
+ if (httpClient == null) {
+ httpClient = HTTPClientUtils.getHttpsClient();
+ }
+ }
+ }
+ return httpClient;
+ }
+
+ public static GatewayCache getGatewayCache() {
+
+ if (gatewayCache == null) {
+ synchronized (GatewayDataHolder.class) {
+ if (gatewayCache == null) {
+ gatewayCache = new GatewayCache();
+ }
+ }
+ }
+ return gatewayCache;
+ }
+
+ public FinancialServicesConfigurationService getFinancialServicesConfigurationService() {
+
+ return financialServicesConfigurationService;
+ }
+
+ public void setFinancialServicesConfigurationService(
+ FinancialServicesConfigurationService financialServicesConfigurationService) {
+
+ this.financialServicesConfigurationService = financialServicesConfigurationService;
+ if (financialServicesConfigurationService != null) {
+ Map
+ * WSO2 LLC. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.wso2.financial.services.accelerator.gateway.internal;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.osgi.service.component.ComponentContext;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
+import org.osgi.service.component.annotations.ReferenceCardinality;
+import org.osgi.service.component.annotations.ReferencePolicy;
+import org.wso2.carbon.apimgt.impl.APIManagerConfigurationService;
+import org.wso2.financial.services.accelerator.common.config.FinancialServicesConfigurationService;
+
+/**
+ * Service class for executor core
+ */
+@Component(
+ name = "org.wso2.financial.services.accelerator.gateway.internal.GatewayServiceComponent",
+ immediate = true
+)
+public class GatewayServiceComponent {
+
+ private static final Log log = LogFactory.getLog(GatewayServiceComponent.class);
+
+ @Activate
+ protected void activate(ComponentContext context) {
+
+ log.debug("Financial services gateway component is activated ");
+ }
+
+ @Deactivate
+ protected void deactivate(ComponentContext context) {
+
+ log.debug("Financial services gateway component is deactivated ");
+ }
+
+ @Reference(
+ service = FinancialServicesConfigurationService.class,
+ cardinality = ReferenceCardinality.MANDATORY,
+ policy = ReferencePolicy.DYNAMIC,
+ unbind = "unsetConfigService"
+ )
+ public void setConfigService(FinancialServicesConfigurationService configurationService) {
+
+ GatewayDataHolder.getInstance().setFinancialServicesConfigurationService(configurationService);
+ }
+
+ public void unsetConfigService(FinancialServicesConfigurationService configurationService) {
+
+ GatewayDataHolder.getInstance().setFinancialServicesConfigurationService(null);
+ }
+
+ @Reference(
+ service = APIManagerConfigurationService.class,
+ cardinality = ReferenceCardinality.MANDATORY,
+ policy = ReferencePolicy.DYNAMIC,
+ unbind = "unSetAPIMConfigs"
+ )
+ public void setAPIMConfig(APIManagerConfigurationService apManagerConfigurationService) {
+
+ GatewayDataHolder.getInstance().setApiManagerConfiguration(apManagerConfigurationService);
+ }
+
+ public void unSetAPIMConfigs(APIManagerConfigurationService apManagerConfigurationService) {
+
+ GatewayDataHolder.getInstance().setApiManagerConfiguration(apManagerConfigurationService);
+ }
+}
diff --git a/financial-services-accelerator/components/org.wso2.financial.services.accelerator.gateway/src/main/java/org/wso2/financial/services/accelerator/gateway/util/GatewayConstants.java b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.gateway/src/main/java/org/wso2/financial/services/accelerator/gateway/util/GatewayConstants.java
new file mode 100644
index 00000000..39159bbf
--- /dev/null
+++ b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.gateway/src/main/java/org/wso2/financial/services/accelerator/gateway/util/GatewayConstants.java
@@ -0,0 +1,62 @@
+/**
+ * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com).
+ *
+ * WSO2 LLC. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.wso2.financial.services.accelerator.gateway.util;
+
+/**
+ * Class containing the constants for Financial Services Gateway module.
+ */
+public class GatewayConstants {
+
+ public static final String AUTH_HEADER = "Authorization";
+ public static final String BEARER_TAG = "Bearer ";
+ public static final String BASIC_TAG = "Basic ";
+ public static final String CONTENT_TYPE_TAG = "Content-Type";
+ public static final String JWT_CONTENT_TYPE = "application/jwt";
+ public static final String JSON_CONTENT_TYPE = "application/json";
+ public static final String JOSE_CONTENT_TYPE = "application/jose";
+ public static final String APPLICATION_XML_CONTENT_TYPE = "application/xml";
+ public static final String TEXT_XML_CONTENT_TYPE = "text/xml";
+ public static final String SOAP_BODY = "soapenv:Body";
+ public static final String SOAP_BODY_TEXT = "text";
+ public static final String SOAP_BODY_CONTENT = "content";
+ public static final String SOAP_JSON_OBJECT = "jsonObject";
+ public static final String COLON = ":";
+ public static final String SLASH = "/";
+ public static final String POST_HTTP_METHOD = "POST";
+ public static final String PUT_HTTP_METHOD = "PUT";
+ public static final String GET_HTTP_METHOD = "GET";
+ public static final String PATCH_HTTP_METHOD = "PATCH";
+ public static final String DELETE_HTTP_METHOD = "DELETE";
+ public static final String PUBLISHER_API_PATH = "api/am/publisher/apis/";
+ public static final String SWAGGER_ENDPOINT = "/swagger";
+ public static final String API_KEY_VALIDATOR_USERNAME = "APIKeyValidator.Username";
+ public static final String API_KEY_VALIDATOR_PASSWORD = "APIKeyValidator.Password";
+ public static final String API_TYPE_CONSENT = "consent";
+ public static final String API_TYPE_NON_REGULATORY = "non-regulatory";
+ public static final String API_TYPE_CUSTOM_PROP = "x-wso2-api-type";
+ public static final String EXECUTOR_TYPE_CONSENT = "Consent";
+ public static final String EXECUTOR_TYPE_DCR = "DCR";
+ public static final String EXECUTOR_TYPE_DEFAULT = "Default";
+ public static final String DCR_PATH = "/register";
+ public static final String CONTEXT_PROP_CACHE_KEY = "_contextProp";
+ public static final String ANALYTICS_PROP_CACHE_KEY = "_analyticsData";
+ public static final String ERROR_STATUS_PROP = "errorStatusCode";
+ public static final String IS_RETURN_RESPONSE = "isReturnResponse";
+ public static final String MODIFIED_STATUS = "ModifiedStatus";
+}
diff --git a/financial-services-accelerator/components/org.wso2.financial.services.accelerator.gateway/src/main/java/org/wso2/financial/services/accelerator/gateway/util/GatewayUtils.java b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.gateway/src/main/java/org/wso2/financial/services/accelerator/gateway/util/GatewayUtils.java
new file mode 100644
index 00000000..9c7ddc3b
--- /dev/null
+++ b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.gateway/src/main/java/org/wso2/financial/services/accelerator/gateway/util/GatewayUtils.java
@@ -0,0 +1,191 @@
+/**
+ * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com).
+ *
+ * WSO2 LLC. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.wso2.financial.services.accelerator.gateway.util;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.utils.URIBuilder;
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.json.XML;
+import org.wso2.financial.services.accelerator.common.constant.FinancialServicesConstants;
+import org.wso2.financial.services.accelerator.common.exception.FinancialServicesException;
+import org.wso2.financial.services.accelerator.common.exception.FinancialServicesRuntimeException;
+import org.wso2.financial.services.accelerator.common.util.Generated;
+import org.wso2.financial.services.accelerator.gateway.internal.GatewayDataHolder;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.net.URISyntaxException;
+import java.nio.charset.StandardCharsets;
+import java.util.Base64;
+
+/**
+ * Utility methods used in gateway modules.
+ */
+public class GatewayUtils {
+
+ /**
+ * Method to check whether the given string is a valid JWT token.
+ *
+ * @param jwtString JWT token string
+ * @return true if the given string is a valid JWT token, false otherwise
+ */
+ public static boolean isValidJWTToken(String jwtString) {
+
+ String[] jwtPart = jwtString.split("\\.");
+ if (jwtPart.length != 3) {
+ return false;
+ }
+ try {
+ decodeBase64(jwtPart[0]);
+ decodeBase64(jwtPart[1]);
+ } catch (UnsupportedEncodingException | JSONException | IllegalArgumentException e) {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Method to decode the base64 encoded JSON payload.
+ *
+ * @param payload base64 encoded payload
+ * @return Decoded JSON Object
+ * @throws UnsupportedEncodingException When encoding is not UTF-8
+ */
+ public static JSONObject decodeBase64(String payload) throws UnsupportedEncodingException {
+
+ return new JSONObject(new String(Base64.getDecoder().decode(payload),
+ String.valueOf(StandardCharsets.UTF_8)));
+ }
+
+ /**
+ * Method to obtain swagger definition from publisher API.
+ *
+ * @param apiId ID of the API
+ * @return String of swagger definition
+ */
+ @Generated(message = "Cannot test without running APIM. Integration test will be written for this")
+ public static String getSwaggerDefinition(String apiId) {
+
+ String publisherHostName =
+ GatewayDataHolder.getInstance().getFinancialServicesConfigurationService()
+ .getConfigurations()
+ .get(FinancialServicesConstants.PUBLISHER_HOSTNAME).toString();
+
+ String publisherAPIURL = publisherHostName.endsWith(GatewayConstants.SLASH) ?
+ publisherHostName + GatewayConstants.PUBLISHER_API_PATH + apiId + GatewayConstants.SWAGGER_ENDPOINT :
+ publisherHostName + GatewayConstants.SLASH + GatewayConstants.PUBLISHER_API_PATH + apiId +
+ GatewayConstants.SWAGGER_ENDPOINT;
+ try {
+ URIBuilder uriBuilder = new URIBuilder(publisherAPIURL);
+ HttpGet httpGet = new HttpGet(uriBuilder.build().toString());
+ String userName = getAPIMgtConfig(GatewayConstants.API_KEY_VALIDATOR_USERNAME);
+ String password = getAPIMgtConfig(GatewayConstants.API_KEY_VALIDATOR_PASSWORD);
+
+ httpGet.setHeader(GatewayConstants.AUTH_HEADER, GatewayUtils.getBasicAuthHeader(userName, password));
+ HttpResponse response = null;
+ response = GatewayDataHolder.getHttpClient().execute(httpGet);
+ InputStream in = response.getEntity().getContent();
+ return IOUtils.toString(in, String.valueOf(StandardCharsets.UTF_8));
+ } catch (IOException | FinancialServicesException | URISyntaxException e) {
+ throw new FinancialServicesRuntimeException("Failed to retrieve swagger definition from API", e);
+ }
+ }
+
+ /**
+ * Method to read API mgt configs when key is given.
+ *
+ * @param key config key
+ * @return config value
+ */
+ public static String getAPIMgtConfig(String key) {
+
+ return GatewayDataHolder.getInstance().getApiManagerConfigurationService()
+ .getAPIManagerConfiguration().getFirstProperty(key);
+ }
+
+ /**
+ * Method to obtain basic auth header.
+ *
+ * @param username Username of Auth header
+ * @param password Password of Auth header
+ * @return basic auth header
+ */
+ public static String getBasicAuthHeader(String username, String password) {
+
+ byte[] authHeader = Base64.getEncoder().encode((username + GatewayConstants.COLON + password)
+ .getBytes(StandardCharsets.UTF_8));
+ return GatewayConstants.BASIC_TAG + new String(authHeader, StandardCharsets.UTF_8);
+ }
+
+ public static String getTextPayload(String payload) {
+
+ return XML.toJSONObject(payload).getJSONObject(GatewayConstants.SOAP_BODY)
+ .getJSONObject(GatewayConstants.SOAP_BODY_TEXT).getString(GatewayConstants.SOAP_BODY_CONTENT);
+
+ }
+
+ /**
+ * Check the content type and http method of the request.
+ *
+ * @param contentType - contentType
+ * @param httpMethod - httpMethod
+ * @return true if the request is eligible
+ */
+ public static boolean isEligibleRequest(String contentType, String httpMethod) {
+
+ return (contentType.startsWith(GatewayConstants.JSON_CONTENT_TYPE) ||
+ contentType.startsWith(GatewayConstants.APPLICATION_XML_CONTENT_TYPE) ||
+ contentType.startsWith(GatewayConstants.TEXT_XML_CONTENT_TYPE)) &&
+ (GatewayConstants.POST_HTTP_METHOD.equals(httpMethod) || GatewayConstants.PUT_HTTP_METHOD
+ .equals(httpMethod));
+ }
+
+ /**
+ * Check the content type and http method of the response.
+ *
+ * @param contentType - contentType
+ * @param httpMethod - httpMethod
+ * @return true if the response is eligible
+ */
+ public static boolean isEligibleResponse(String contentType, String httpMethod) {
+
+ return (contentType.startsWith(GatewayConstants.JSON_CONTENT_TYPE) ||
+ contentType.startsWith(GatewayConstants.APPLICATION_XML_CONTENT_TYPE) ||
+ contentType.startsWith(GatewayConstants.TEXT_XML_CONTENT_TYPE)) &&
+ (GatewayConstants.GET_HTTP_METHOD.equals(httpMethod) || GatewayConstants.
+ POST_HTTP_METHOD.equals(httpMethod) || GatewayConstants.PUT_HTTP_METHOD.equals(httpMethod)
+ || GatewayConstants.PATCH_HTTP_METHOD.equals(httpMethod) || GatewayConstants.
+ DELETE_HTTP_METHOD.equals(httpMethod));
+ }
+
+ /**
+ * Method to extract JWT payload section as a string.
+ *
+ * @param jwtString full JWT
+ * @return Payload section of JWT
+ */
+ public static String getPayloadFromJWT(String jwtString) {
+
+ return jwtString.split("\\.")[1];
+ }
+}
diff --git a/financial-services-accelerator/components/org.wso2.financial.services.accelerator.gateway/src/main/resources/findbugs-exclude.xml b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.gateway/src/main/resources/findbugs-exclude.xml
new file mode 100644
index 00000000..9fa42f18
--- /dev/null
+++ b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.gateway/src/main/resources/findbugs-exclude.xml
@@ -0,0 +1,21 @@
+
+
+
+
+* WSO2 LLC. licenses this file to you under the Apache License,
+* Version 2.0 (the "License"); you may not use this file except
+* in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+
+package org.wso2.financial.services.accelerator.gateway;
+
+import java.util.AbstractMap;
+import java.util.Map;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+/**
+ * Constants for Gateway test cases.
+ */
+public class GatewayTestConstants {
+
+ public static final String VALID_EXECUTOR_CLASS =
+ "org.wso2.financial.services.accelerator.gateway.executor.core.MockOBExecutor";
+ public static final Map
+ * WSO2 LLC. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.wso2.financial.services.accelerator.gateway.executor.core;
+
+import io.swagger.v3.oas.models.OpenAPI;
+import org.mockito.Mockito;
+import org.testng.Assert;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+import org.wso2.carbon.apimgt.common.gateway.dto.MsgInfoDTO;
+import org.wso2.financial.services.accelerator.common.util.FinancialServicesUtils;
+import org.wso2.financial.services.accelerator.gateway.GatewayTestConstants;
+import org.wso2.financial.services.accelerator.gateway.executor.model.FSAPIRequestContext;
+import org.wso2.financial.services.accelerator.gateway.executor.model.FSAPIResponseContext;
+import org.wso2.financial.services.accelerator.gateway.util.GatewayConstants;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Test for default request router.
+ */
+public class DefaultRequestRouterTest {
+
+ DefaultRequestRouter defaultRequestRouter;
+ OpenAPI openAPI;
+
+ @BeforeClass
+ public void beforeClass() {
+
+ defaultRequestRouter = new DefaultRequestRouter();
+ defaultRequestRouter.setExecutorMap(initExecutors());
+ openAPI = new OpenAPI();
+ openAPI.setExtensions(new HashMap<>());
+ }
+
+ @Test(priority = 1)
+ public void testDCRRequestsForRouter() {
+
+ FSAPIRequestContext obapiRequestContext = Mockito.mock(FSAPIRequestContext.class);
+ FSAPIResponseContext obapiResponseContext = Mockito.mock(FSAPIResponseContext.class);
+ MsgInfoDTO msgInfoDTO = new MsgInfoDTO();
+ msgInfoDTO.setResource("/anyAPIcall/register");
+ Mockito.when(obapiRequestContext.getMsgInfo()).thenReturn(msgInfoDTO);
+ Mockito.when(obapiRequestContext.getOpenAPI()).thenReturn(openAPI);
+ Mockito.when(obapiResponseContext.getMsgInfo()).thenReturn(msgInfoDTO);
+ Assert.assertNotNull(defaultRequestRouter.getExecutorsForRequest(obapiRequestContext));
+ Assert.assertNotNull(defaultRequestRouter.getExecutorsForResponse(obapiResponseContext));
+
+ }
+
+ @Test(priority = 1)
+ public void testAccountRequestsForRouter() {
+
+ FSAPIRequestContext obapiRequestContext = Mockito.mock(FSAPIRequestContext.class);
+ FSAPIResponseContext obapiResponseContext = Mockito.mock(FSAPIResponseContext.class);
+ MsgInfoDTO msgInfoDTO = new MsgInfoDTO();
+ msgInfoDTO.setResource("/anyAPIcall");
+ Mockito.when(obapiRequestContext.getOpenAPI()).thenReturn(openAPI);
+ Mockito.when(obapiRequestContext.getMsgInfo()).thenReturn(msgInfoDTO);
+ Mockito.when(obapiResponseContext.getMsgInfo()).thenReturn(msgInfoDTO);
+ Assert.assertNotNull(defaultRequestRouter.getExecutorsForRequest(obapiRequestContext));
+ Assert.assertNotNull(defaultRequestRouter.getExecutorsForResponse(obapiResponseContext));
+ }
+
+ @Test(priority = 2)
+ public void testNonRegulatoryAPIcall() {
+
+ FSAPIRequestContext obapiRequestContext = Mockito.mock(FSAPIRequestContext.class);
+ FSAPIResponseContext obapiResponseContext = Mockito.mock(FSAPIResponseContext.class);
+ MsgInfoDTO msgInfoDTO = new MsgInfoDTO();
+ msgInfoDTO.setResource("/anyAPIcall");
+ Map
+ * WSO2 LLC. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.wso2.financial.services.accelerator.gateway.executor.core;
+
+import org.apache.http.HttpStatus;
+import org.json.JSONObject;
+import org.mockito.Mockito;
+import org.testng.Assert;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+import org.wso2.carbon.apimgt.common.gateway.dto.ExtensionResponseDTO;
+import org.wso2.carbon.apimgt.common.gateway.dto.ExtensionResponseStatus;
+import org.wso2.carbon.apimgt.common.gateway.dto.MsgInfoDTO;
+import org.wso2.financial.services.accelerator.gateway.GatewayTestConstants;
+import org.wso2.financial.services.accelerator.gateway.executor.model.FSAPIRequestContext;
+import org.wso2.financial.services.accelerator.gateway.executor.model.FSAPIResponseContext;
+import org.wso2.financial.services.accelerator.gateway.util.GatewayConstants;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Test for open Banking extension implementation.
+ */
+public class FSExtensionImplTest {
+
+ private static FSAPIRequestContext fsapiRequestContext;
+ private static FSAPIResponseContext fsapiResponseContext;
+ private static final FSExtensionListenerImpl fsExtensionListener = new FSExtensionListenerImpl();
+
+ @BeforeClass
+ public static void beforeClass() {
+
+ }
+
+ @Test(priority = 1)
+ public void testMinimumFlow() {
+
+ MsgInfoDTO msgInfoDTO = new MsgInfoDTO();
+ msgInfoDTO.setHeaders(new HashMap<>());
+
+ fsapiRequestContext = Mockito.mock(FSAPIRequestContext.class);
+ Mockito.when(fsapiRequestContext.isError()).thenReturn(false);
+ Mockito.when(fsapiRequestContext.getModifiedPayload()).thenReturn(null);
+ Mockito.when(fsapiRequestContext.getAddedHeaders()).thenReturn(new HashMap<>());
+ Mockito.when(fsapiRequestContext.getMsgInfo()).thenReturn(msgInfoDTO);
+
+ fsapiResponseContext = Mockito.mock(FSAPIResponseContext.class);
+ Mockito.when(fsapiResponseContext.isError()).thenReturn(false);
+ Mockito.when(fsapiResponseContext.getModifiedPayload()).thenReturn(null);
+ Mockito.when(fsapiResponseContext.getAddedHeaders()).thenReturn(new HashMap<>());
+ Mockito.when(fsapiResponseContext.getMsgInfo()).thenReturn(msgInfoDTO);
+
+ ExtensionResponseDTO responseDTOForRequest = fsExtensionListener.getResponseDTOForRequest(fsapiRequestContext);
+ Assert.assertEquals(responseDTOForRequest.getResponseStatus(), ExtensionResponseStatus.CONTINUE.toString());
+ Assert.assertNull(responseDTOForRequest.getHeaders());
+ Assert.assertNull(responseDTOForRequest.getPayload());
+ Assert.assertNull(responseDTOForRequest.getCustomProperty());
+ Assert.assertEquals(responseDTOForRequest.getStatusCode(), 0);
+
+ ExtensionResponseDTO responseDTOForResponse =
+ fsExtensionListener.getResponseDTOForResponse(fsapiResponseContext);
+
+ Assert.assertEquals(responseDTOForResponse.getResponseStatus(), ExtensionResponseStatus.CONTINUE.toString());
+ Assert.assertNull(responseDTOForResponse.getHeaders());
+ Assert.assertNull(responseDTOForResponse.getPayload());
+ Assert.assertNull(responseDTOForResponse.getCustomProperty());
+ Assert.assertEquals(responseDTOForResponse.getStatusCode(), 0);
+
+ }
+
+ @Test(priority = 1)
+ public void testAddedHeaders() {
+
+ fsapiRequestContext = Mockito.mock(FSAPIRequestContext.class);
+ fsapiResponseContext = Mockito.mock(FSAPIResponseContext.class);
+ Mockito.when(fsapiRequestContext.isError()).thenReturn(false);
+ Mockito.when(fsapiRequestContext.getModifiedPayload()).thenReturn(null);
+ MsgInfoDTO msgInfoDTO = new MsgInfoDTO();
+ msgInfoDTO.setHeaders(new HashMap<>());
+ Mockito.when(fsapiRequestContext.getMsgInfo()).thenReturn(msgInfoDTO);
+ Map
+ * WSO2 LLC. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.wso2.financial.services.accelerator.gateway.executor.core;
+
+
+import org.wso2.financial.services.accelerator.gateway.executor.model.FSAPIRequestContext;
+import org.wso2.financial.services.accelerator.gateway.executor.model.FSAPIResponseContext;
+
+/**
+ * Mock Open banking executor for testing.
+ */
+public class MockOBExecutor implements FinancialServicesGatewayExecutor {
+
+ @Override
+ public void preProcessRequest(FSAPIRequestContext fsapiRequestContext) {
+
+ fsapiRequestContext.setModifiedPayload("{}");
+ }
+
+ /**
+ * Method to handle post request.
+ *
+ * @param fsapiRequestContext FS request context object
+ */
+ @Override
+ public void postProcessRequest(FSAPIRequestContext fsapiRequestContext) {
+
+ }
+
+
+ /**
+ * Method to handle pre response.
+ *
+ * @param fsapiResponseContext FS response context object
+ */
+ @Override
+ public void preProcessResponse(FSAPIResponseContext fsapiResponseContext) {
+
+ }
+
+ /**
+ * Method to handle post response.
+ *
+ * @param fsapiResponseContext FS response context object
+ */
+ @Override
+ public void postProcessResponse(FSAPIResponseContext fsapiResponseContext) {
+
+ }
+
+}
diff --git a/financial-services-accelerator/components/org.wso2.financial.services.accelerator.gateway/src/test/java/org/wso2/financial/services/accelerator/gateway/util/GatewayUtilsTest.java b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.gateway/src/test/java/org/wso2/financial/services/accelerator/gateway/util/GatewayUtilsTest.java
new file mode 100644
index 00000000..bf07c177
--- /dev/null
+++ b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.gateway/src/test/java/org/wso2/financial/services/accelerator/gateway/util/GatewayUtilsTest.java
@@ -0,0 +1,108 @@
+/**
+ * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com).
+ *
+ * WSO2 LLC. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.wso2.financial.services.accelerator.gateway.util;
+
+import org.json.JSONObject;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+import org.wso2.financial.services.accelerator.gateway.GatewayTestConstants;
+
+import java.io.UnsupportedEncodingException;
+
+/**
+ * Test class for Gateway utility methods.
+ */
+public class GatewayUtilsTest {
+
+ @Test(priority = 1)
+ public void testIsValidJWTToken() {
+
+ Assert.assertTrue(GatewayUtils.isValidJWTToken(GatewayTestConstants.TEST_JWT));
+ }
+
+ @Test(priority = 2)
+ public void testB64Encode() throws UnsupportedEncodingException {
+
+ JSONObject payload = GatewayUtils.decodeBase64(GatewayTestConstants.B64_PAYLOAD);
+ Assert.assertEquals(payload.getString("sub"), "1234567890");
+ Assert.assertEquals(payload.getString("name"), "John Doe");
+ Assert.assertEquals(payload.getInt("iat"), 1516239022);
+ }
+
+ @Test(priority = 3)
+ public void testBasicAuthHeader() {
+
+ Assert.assertEquals(GatewayUtils.getBasicAuthHeader("admin", "admin"),
+ "Basic YWRtaW46YWRtaW4=");
+ }
+
+ @Test(priority = 4)
+ public void testGetTextPayload() {
+
+ Assert.assertEquals(GatewayUtils.getTextPayload(GatewayTestConstants.XML_PAYLOAD), "Test Content");
+ }
+
+ @Test (priority = 5)
+ public void testIsEligibleRequest() {
+
+ Assert.assertTrue(GatewayUtils.isEligibleRequest(GatewayConstants.JSON_CONTENT_TYPE,
+ GatewayConstants.POST_HTTP_METHOD));
+ Assert.assertTrue(GatewayUtils.isEligibleRequest(GatewayConstants.APPLICATION_XML_CONTENT_TYPE,
+ GatewayConstants.POST_HTTP_METHOD));
+ Assert.assertTrue(GatewayUtils.isEligibleRequest(GatewayConstants.TEXT_XML_CONTENT_TYPE,
+ GatewayConstants.POST_HTTP_METHOD));
+ Assert.assertTrue(GatewayUtils.isEligibleRequest(GatewayConstants.JSON_CONTENT_TYPE,
+ GatewayConstants.PUT_HTTP_METHOD));
+ Assert.assertTrue(GatewayUtils.isEligibleRequest(GatewayConstants.APPLICATION_XML_CONTENT_TYPE,
+ GatewayConstants.PUT_HTTP_METHOD));
+ Assert.assertTrue(GatewayUtils.isEligibleRequest(GatewayConstants.TEXT_XML_CONTENT_TYPE,
+ GatewayConstants.PUT_HTTP_METHOD));
+ }
+
+ @Test (priority = 6)
+ public void testIsEligibleResponse() {
+
+ Assert.assertTrue(GatewayUtils.isEligibleResponse(GatewayConstants.JSON_CONTENT_TYPE,
+ GatewayConstants.POST_HTTP_METHOD));
+ Assert.assertTrue(GatewayUtils.isEligibleResponse(GatewayConstants.APPLICATION_XML_CONTENT_TYPE,
+ GatewayConstants.POST_HTTP_METHOD));
+ Assert.assertTrue(GatewayUtils.isEligibleResponse(GatewayConstants.TEXT_XML_CONTENT_TYPE,
+ GatewayConstants.POST_HTTP_METHOD));
+ Assert.assertTrue(GatewayUtils.isEligibleResponse(GatewayConstants.JSON_CONTENT_TYPE,
+ GatewayConstants.PUT_HTTP_METHOD));
+ Assert.assertTrue(GatewayUtils.isEligibleResponse(GatewayConstants.APPLICATION_XML_CONTENT_TYPE,
+ GatewayConstants.PUT_HTTP_METHOD));
+ Assert.assertTrue(GatewayUtils.isEligibleResponse(GatewayConstants.TEXT_XML_CONTENT_TYPE,
+ GatewayConstants.PUT_HTTP_METHOD));
+ Assert.assertTrue(GatewayUtils.isEligibleResponse(GatewayConstants.JSON_CONTENT_TYPE,
+ GatewayConstants.GET_HTTP_METHOD));
+ Assert.assertTrue(GatewayUtils.isEligibleResponse(GatewayConstants.APPLICATION_XML_CONTENT_TYPE,
+ GatewayConstants.GET_HTTP_METHOD));
+ Assert.assertTrue(GatewayUtils.isEligibleResponse(GatewayConstants.TEXT_XML_CONTENT_TYPE,
+ GatewayConstants.GET_HTTP_METHOD));
+ }
+
+ @Test(priority = 7)
+ public void testJWTPayloadLoad() {
+
+ Assert.assertEquals(GatewayUtils.getPayloadFromJWT(GatewayTestConstants.TEST_JWT),
+ GatewayTestConstants.B64_PAYLOAD);
+ }
+
+}
diff --git a/financial-services-accelerator/components/org.wso2.financial.services.accelerator.gateway/src/test/resources/testng.xml b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.gateway/src/test/resources/testng.xml
new file mode 100644
index 00000000..8e4cd5f5
--- /dev/null
+++ b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.gateway/src/test/resources/testng.xml
@@ -0,0 +1,28 @@
+
+
+
+