This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, go to 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.conf
file.Get the container Id of the Docker image with the API:
docker ps
Copy the
micro-gw.conf
file from the Docker image to the host:docker cp <CONTAINER_ID>:/home/ballerina/conf/micro-gw.conf <DEST_PATH>
- Open the
micro-gw.conf
file. 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”
You can follow these above steps and customise all the filters listed under the
[openbanking.au.filters]
tag in themicro-gw.conf
file.Download the wso2ob-custom-filter script from the docker image. This script is to pack the
.jar
files that contain the custom filter logics to a running docker container:docker cp <CONTAINER_ID>:/home/ballerina/resources/wso2ob-custom-filter.sh
Execute the command below, to pack a
.jar
file: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) { } }
The package name and the class name should be the same as the above as this classpath is already configured in the Swagger file of the project.
Get the container Id of the Docker image with the API:
docker ps
Download the wso2ob-custom-filter script from the docker image. This script is to pack the
.jar
files that contain the custom interceptor logic to a running Docker container:docker cp <CONTAINER_ID>:/home/ballerina/resources/wso2ob-custom-filter.sh
Execute the following command, to pack a
.jar
file:wso2ob-custom-filter.sh <DOCKER_CONTAINER_NAME> <PATH_TO_INTERCEPTOR_JAR> <PATH_TO_MGW_CONF>