From 6764ebf012d13186fadbec08c94f7169e5b51a8f Mon Sep 17 00:00:00 2001 From: tzssangglass Date: Sat, 1 Jan 2022 14:40:19 +0800 Subject: [PATCH 1/3] docs: adding function definitions for the PluginFilter interface Signed-off-by: tzssangglass --- README.md | 2 +- docs/en/latest/development.md | 68 ++++++++++++++++++++++ docs/zh/{Quick Start.md => quick-start.md} | 0 3 files changed, 69 insertions(+), 1 deletion(-) rename docs/zh/{Quick Start.md => quick-start.md} (100%) diff --git a/README.md b/README.md index d68789c4..b8795af6 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ security, traffic control, serverless, analytics & monitoring, transformations, It also provides highly extensible API, allowing common phases to be mounted, and users can use these api to develop their own plugins. -APISIX supports writing plugins in multiple languages in version [2.7.0](https://github.com/apache/apisix/blob/master/CHANGELOG.md#270), +APISIX supports writing plugins in multiple languages in version [2.10.2](https://github.com/apache/apisix/blob/master/CHANGELOG.md#2102), this project is APISIX Java side implementation that supports writing plugins in java. diff --git a/docs/en/latest/development.md b/docs/en/latest/development.md index 1eeaa1a4..db007a76 100644 --- a/docs/en/latest/development.md +++ b/docs/en/latest/development.md @@ -87,6 +87,74 @@ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13 apisix-java-plugin-runner will look for implementation classes named `FooFilter`, and the name of each filter's implementation class is the return value of its overridden function `public String name()`. +#### The functions must be implemented of filter execution + +- `String name();` + + description: return the name of plugin filter + + code example: + + ```java + @Override + public String name() { + return "FooFilter"; + } + ``` + +- `void filter(HttpRequest request, HttpResponse response, PluginFilterChain chain);` + + description: implementing custom business logic + + code example: + + ```java + @Override + public void filter(HttpRequest request, HttpResponse response, PluginFilterChain chain) { + // get conf of current filter + String configStr = request.getConfig(this); + Gson gson = new Gson(); + Map conf = new HashMap<>(); + // convert according to the actual configured conf type + conf = gson.fromJson(configStr, conf.getClass()); + + // get extra info + String remoteAddr = request.getVars("remote_addr"); + String serverPort = request.getVars("server_port"); + String body = request.getBody(); + + chain.filter(request, response); + } + ``` + +- `List requiredVars();` + + description: declare in advance the nginx variables you want to use in the current filter + + code example: + + ```java + @Override + public List requiredVars() { + List vars = new ArrayList<>(); + vars.add("remote_addr"); + vars.add("server_port"); + return vars; + } + ``` + +- `Boolean requiredBody();` + + description: whether the request body is required in the current filter, true means yes. + + code example: + + ```java + @Override + public Boolean requiredBody() { + return true; + } + ``` #### Rewrite Request diff --git a/docs/zh/Quick Start.md b/docs/zh/quick-start.md similarity index 100% rename from docs/zh/Quick Start.md rename to docs/zh/quick-start.md From ce67d3d0a06dfafcfadc063eab3bf34b81862f9c Mon Sep 17 00:00:00 2001 From: tzssangglass Date: Mon, 3 Jan 2022 11:02:47 +0800 Subject: [PATCH 2/3] use version matrix Signed-off-by: tzssangglass --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b8795af6..8cc98348 100644 --- a/README.md +++ b/README.md @@ -20,9 +20,15 @@ security, traffic control, serverless, analytics & monitoring, transformations, It also provides highly extensible API, allowing common phases to be mounted, and users can use these api to develop their own plugins. -APISIX supports writing plugins in multiple languages in version [2.10.2](https://github.com/apache/apisix/blob/master/CHANGELOG.md#2102), this project is APISIX Java side implementation that supports writing plugins in java. +Version Matrix +------------- + +| apisix-java-plugin-runner | APISIX | +|---------------------------|---------------------------------------------------------------------------| +| 0.1.0 | [2.7.0](https://github.com/apache/apisix/blob/master/CHANGELOG.md#270) | +| 0.2.0 | [2.10.2](https://github.com/apache/apisix/blob/master/CHANGELOG.md#2102) | How it Works ------------- From f11b0e9982cd59dfdda4b3790aad073959ac3302 Mon Sep 17 00:00:00 2001 From: tzssangglass Date: Mon, 3 Jan 2022 11:09:27 +0800 Subject: [PATCH 3/3] update Signed-off-by: tzssangglass --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8cc98348..c006b7d8 100644 --- a/README.md +++ b/README.md @@ -25,10 +25,10 @@ this project is APISIX Java side implementation that supports writing plugins in Version Matrix ------------- -| apisix-java-plugin-runner | APISIX | -|---------------------------|---------------------------------------------------------------------------| -| 0.1.0 | [2.7.0](https://github.com/apache/apisix/blob/master/CHANGELOG.md#270) | -| 0.2.0 | [2.10.2](https://github.com/apache/apisix/blob/master/CHANGELOG.md#2102) | +| apisix-java-plugin-runner | APISIX | +|---------------------------|-----------------------------------------------------------------------------| +| 0.1.0 | >= [2.7.0](https://github.com/apache/apisix/blob/master/CHANGELOG.md#270) | +| 0.2.0 | >= [2.10.2](https://github.com/apache/apisix/blob/master/CHANGELOG.md#2102) | How it Works -------------