This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.
Custom filters and interceptors for WSO2 API Microgateway
You can customise the WSO2 Open Banking filters and interceptors that are used in WSO2 API Microgatway.
Adding a filter
Filters are a set of execution points in the request and response flow which will intercept the request before going to the backend service and intercept the response before forwarding to the client. Filters are applied to all the APIs exposed via microgateway. This section explains how to add a customise the logic to and implement an Open Banking filter.
Implement Java class following the Open Banking Microgateway Filter template given below:
public class SampleFilter { public static boolean handleRequest(Request httpRequest) throws OpenBankingMicrogatewayException { // filter request logic return true; } public static boolean handleResponse(Response httpResponse) throws OpenBankingMicrogatewayException { // filter response logic return true; } }All the configurations related to WSO2 API Microgateway and WSO2 Open Banking are available in the
micro-gw.conffile.Get the container Id of the Docker image with the API:
docker psCopy the
micro-gw.conffile from the Docker image to the host:docker cp <CONTAINER_ID>:/home/ballerina/conf/micro-gw.conf <DEST_PATH>
Open the
micro-gw.conffile.Add the classpath of the custom filter implementation under the
[openbanking.au.filters]tag. For example,[openbanking.au.filters] SchemaValidationFilter= “com.wso2.finance.open.banking.mg.au.schema.validation.filter.SchemaValidationFilter”Download the wso2ob-custom-filter script from the docker image. This script is to pack the
.jarfiles that contain the custom filter logics to a running docker container:docker cp <CONTAINER_ID>:/home/ballerina/resources/wso2ob-custom-filter.shExecute the command below, to pack a
.jarfile:wso2ob-custom-filter.sh <DOCKER_CONTAINER_NAME> <PATH_TO_CUSTOM_FILTER_JAR> <PATH_TO_MGW_CONF>
Adding an interceptor
Interceptors in the API Microgateway carry out transformations and mediations on the requests and responses. Microgateway defines Java interfaces to write interceptors.
Implement a Java class by following the given template:
package com.wso2.finance.open.banking.mg.interceptor; public class OpenBankingInterceptor implements Interceptor { public boolean interceptRequest(Caller caller, Request request) { } public boolean interceptResponse(Caller caller, Request request) { } }Get the container Id of the Docker image with the API:
docker psDownload the wso2ob-custom-filter script from the docker image. This script is to pack the
.jarfiles that contain the custom interceptor logic to a running Docker container:docker cp <CONTAINER_ID>:/home/ballerina/resources/wso2ob-custom-filter.shExecute the following command, to pack a
.jarfile:wso2ob-custom-filter.sh <DOCKER_CONTAINER_NAME> <PATH_TO_INTERCEPTOR_JAR> <PATH_TO_MGW_CONF>