Rdebu commented on issue #54:
URL:
https://github.com/apache/apisix-java-plugin-runner/issues/54#issuecomment-890501368
> > request.setArg("test_arg", "test_value");
> > response.setHeader("para_test", "test");
>
> `request.setArg("test_arg",
"test_value");`表示重写当前请求,看看:[https](https://github.com/apache/apisix-java-plugin-runner/blob/main/docs/en/latest/development.md#rewrite-request)
:
[//github.com/apache/apisix-java-plugin-runner/blob/main/docs/en/latest/development.md#rewrite-request](https://github.com/apache/apisix-java-plugin-runner/blob/main/docs/en/latest/development.md#rewrite-request)
>
> `response.setHeader("para_test",
"test");`表示停止当前请求,客户端会收到这里生成的相关参数。看看:[https](https://github.com/apache/apisix-java-plugin-runner/blob/main/docs/en/latest/development.md#stop-request)
:
[//github.com/apache/apisix-java-plugin-runner/blob/main/docs/en/latest/development.md#stop-request](https://github.com/apache/apisix-java-plugin-runner/blob/main/docs/en/latest/development.md#stop-request)
>
> **如果这两个都存在,那么请求将被停止。**
>
> 在`config.yaml`apisix的:
>
> ```
> ext-plugin:
> cmd: ['java', '-jar', '-Xmx4g', '-Xms4g',
'/root/IdeaProjects/apisix-java-plugin-runner/runner-dist/apisix-runner-bin-dist/target/apisix-runner-bin/apisix-runner-bin/apisix-java-plugin-runner.jar']
> ```
>
> apisix 中成功 jar 启动输出的日志`error.log`:
>
> ```
> 2021/07/31 20:53:07 [warn] 107773#107773: *69 [lua] init.lua:620:
> . ____ _ __ _ _
> /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
> ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
> \\/ ___)| |_)| | | | | || (_| | ) ) ) )
> ' |____| .__|_| |_|_| |_\__, | / / / /
> , context: ngx.timer
> 2021/07/31 20:53:07 [warn] 107773#107773: *69 [lua] init.lua:620:
=========|_|==============|___/=/_/_/_/
> , context: ngx.timer
> 2021/07/31 20:53:07 [warn] 107773#107773: *69 [lua] init.lua:620: ::
Spring Boot :: (v2.4.5), context: ngx.timer
> 2021/07/31 20:53:07 [warn] 107773#107773: *69 [lua] init.lua:620:
> , context: ngx.timer
> 2021/07/31 20:53:07 [warn] 107773#107773: *69 [lua] init.lua:620:
> , context: ngx.timer
> 2021/07/31 20:53:07 [warn] 107773#107773: *69 [lua] init.lua:620:
2021-07-31 20:53:07.993 INFO 107784 --- [ main]
o.a.a.p.r.PluginRunnerApplication : Starting PluginRunnerApplication
v0.1.0 using Java 11.0.11 on localhost.localdomain with PID 107784
(/root/IdeaProjects/apisix-java-plugin-runner/runner-dist/apisix-runner-bin-dist/target/apisix-runner-bin/apisix-runner-bin/apisix-java-plugin-runner.jar
started by root in /usr/local/apisix)
> , context: ngx.timer
> 2021/07/31 20:53:07 [warn] 107773#107773: *69 [lua] init.lua:620:
2021-07-31 20:53:07.996 INFO 107784 --- [ main]
o.a.a.p.r.PluginRunnerApplication : No active profile set, falling back
to default profiles: default
> , context: ngx.timer
> 2021/07/31 20:53:09 [warn] 107773#107773: *69 [lua] init.lua:620:
2021-07-31 20:53:09.618 INFO 107784 --- [ main]
o.a.a.p.r.PluginRunnerApplication : Started PluginRunnerApplication in
2.004 seconds (JVM running for 2.605)
> , context: ngx.timer
> 2021/07/31 20:53:09 [warn] 107773#107773: *69 [lua] init.lua:620:
2021-07-31 20:53:09.793 WARN 107784 --- [ main]
o.a.a.p.r.s.ApplicationRunner : java runner is listening on the
socket file: /usr/local/apisix/conf/apisix-107767.sock
> , context: ngx.timer
> ```
>
> 使用与您相同的环境和代码,这是我的复制结果:
>
> ```
> $ curl -i 127.0.0.1:9080/get
> HTTP/1.1 500 Internal Server Error
> Date: Sat, 31 Jul 2021 12:40:19 GMT
> Content-Type: text/html; charset=utf-8
> Content-Length: 553
> Connection: close
> para-test: test
> ETag: "610544ac-229"
> Server: APISIX/2.7
> ```
>
> 在`para-test`头已成功返回给客户端。
我懂了,之前理解错了,以为response是返回给客户端的response,没想到是停止请求的,谢谢大佬。之后还有个问题
一下代码的request.getConfig 他这个config是哪里的配置啊
String configStr = request.getConfig(this);
Gson gson = new Gson();
Map<String, Object> conf = new HashMap<>();
conf = gson.fromJson(configStr, conf.getClass());
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]