apisix-java-plugin-runner
apisix-java-plugin-runner copied to clipboard
request help: Custom filter performed twice?
Issue description
one request, but custom filter performed twice. my flow is : request > apisix + apisix runner(include custom filter) > my Backend Service A > my Backend Service B. and Service A redirect to service B. in this case, Is it normal for custom filters to work twice? (i guess that's right...)
I want the custom filter to work once regardless of the redirect(1 request -> custom filter work once -> 1 response) What should I do ??
Thank you in advance @tzssangglass
Environment
ubuntu
- your apisix-java-plugin-runner version 0.3.0
how did you config route? like: https://github.com/apache/apisix-java-plugin-runner/blob/d5421c292ef0d0ea93fb484afef668d7e2fc8767/tests/e2e/plugins/plugins_post_with_vars_test.go#L38-L64?
my route is,
{ "uri": "/*", "name": "test", "methods": [ "GET" ], "plugins": { "ext-plugin-pre-req": { "conf": [ { "name": "HiFilter", "value": "{\"apiCode\":\"apiCode\",\"rejected_code\":\"403\"}" } ] } }, "upstream_id": "99", "status": 1 }
my backend, (serviceA = /test2, serviceB = /test)
my custom filter,
my error log,
Please refer to the above. thanks, @tzssangglass
When you request APISIX once, output TWICE?
twice?
When you request APISIX once, output
TWICE?
twice?
yes.. Need more information? Redirect doesn't seem to matter.
request > apisix + apisix runner(include custom filter) > my Backend Service A > my Backend Service B. and Service A redirect to service B.
can you provide more info about this?
can you provide more info about this?
my demo project git: https://github.com/Cheol-Soon-Choi/demo_runner I think it's because of my project config or filter process?
my backend is
my route, upstream is
when i call (get) localhost:9080/test2 -> logged twice when i call (get) localhost:9080/test -> logged once
As you can see, this demo_runner project is also logged twice.
maybe @tzssangglass can reproduce twice logging like me. Thank you for your review.
Since the url is /* in my router settings, the custom filter works once in the /test2 call, and the custom filter works once more in the redirected /test call, so is it logged twice in total??
Solved the problem. It happened because the router was set to duplicate. I'm sorry I'm not used to it. @tzssangglass
Additionally, When I call apisix gw using resttemplate, the returned result is fine, but the custom filter doesn't seem to work. on the other way, When i call apisix gw directly, the custom filter works fine. Is there anything I missed in this process?
Since the url is /* in my router settings, the custom filter works once in the /test2 call, and the custom filter works once more in the redirected /test call, so is it logged twice in total??
If you are saying that a redirect request occurred on the client side, then yes, APISIX processed the request twice and the java plugin runner will also process it twice.
Additionally, When I call apisix gw using resttemplate, the returned result is fine, but the custom filter doesn't seem to work. on the other way, When i call apisix gw directly, the custom filter works fine.
It looks like the resttemplate sends a different request than the one sent by the direct call.