You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2022/12/07 13:20:57 UTC

[GitHub] [apisix-java-plugin-runner] zhlu001 opened a new issue, #219: help request: How to dynamic add/remove headers in "ext-plugin" with Java Runner

zhlu001 opened a new issue, #219:
URL: https://github.com/apache/apisix-java-plugin-runner/issues/219

   ### Description
   
   Is it possible to dynamic to add headers in the ext-plugin (We implement a java based plugin with "apisix-runner-starter, 0.4.0" )?
   the methods we tried this method: 
   ` public void filter(HttpRequest request, HttpResponse response, PluginFilterChain chain `
   ...
   `   request.getHeaders().put("abc","abc");
           request.getHeaders().put("567","565");`
   ...
   
   Expectation: 
   upstream api receives the combined headers (original + dynamic).    
   client 10 headers --> apisix ext-plugin(java runner) add 2 headers=> 12 headers -> upstream, 12 headers 
   
   Actual 
   upstream api still receives the original headers 
   client 10 headers --> apisix ext-plugin(java runner) add 2 headers=> 12 headers -> upstream, 10 headers 
   
   We noticed that line 223 in the "RpcCallHandler" in the "org.apache.apisix.plugin.runner.handler" ;package
   still using the original request, even the ext-plugin add or remove the header
   
   Typically, data transmission after plugin should expose interface to implementer. but currently, plugin only could change the header value, could not dynamically add / remove headers
   
   thx
   
   
   
   ### Environment
   
   - APISIX version (run `apisix version`):  3.0
   - Operating system (run `uname -a`): Centos7
   - OpenResty / Nginx version (run `openresty -V` or `nginx -V`):
   - etcd version, if relevant (run `curl http://127.0.0.1:9090/v1/server_info`): 3.5.x
   - APISIX Dashboard version, if relevant: 
   - Plugin runner version, for issues related to plugin runners:  apisix-runner-starter, 0.4.0
   - LuaRocks version, for installation issues (run `luarocks --version`):
   


-- 
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: notifications-unsubscribe@apisix.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix-java-plugin-runner] tzssangglass commented on issue #219: help request: How to dynamic add/remove headers in "ext-plugin" with Java Runner

Posted by GitBox <gi...@apache.org>.
tzssangglass commented on issue #219:
URL: https://github.com/apache/apisix-java-plugin-runner/issues/219#issuecomment-1340964149

   ref: https://github.com/apache/apisix-java-plugin-runner/blob/e18da5ca41607e7a6f79b53d9c1c85f0708025f4/sample/src/main/java/org/apache/apisix/plugin/runner/filter/RewriteRequestDemoFilter.java#L79
   
   use `request.setHeader`


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix-java-plugin-runner] zhlu001 commented on issue #219: help request: How to dynamic add/remove headers in "ext-plugin" with Java Runner

Posted by GitBox <gi...@apache.org>.
zhlu001 commented on issue #219:
URL: https://github.com/apache/apisix-java-plugin-runner/issues/219#issuecomment-1341909438

   Client (postman ) --> plugin --> upstream (Spring boot Rest )
   ***@***.***
   
   ***@***.***
   
   Best regards,
   
   Zhanpeng LU
   
   Business Analytics Asia Pacific (CI/PDD2)
   Bosch (China) Investment Ltd. | 333 Fuquan (N.) Road | Shanghai 200335 | P.R. CHINA
   ***@***.******@***.***>
   ​
   From: tzssangglass ***@***.***>
   Sent: Thursday, December 8, 2022 10:50
   To: apache/apisix-java-plugin-runner ***@***.***>
   Cc: LU Zhanpeng (CI/PDD2) ***@***.***>; Author ***@***.***>
   Subject: Re: [apache/apisix-java-plugin-runner] help request: How to dynamic add/remove headers in "ext-plugin" with Java Runner (Issue #219)
   
   
   Besides, we tested response.setheader(), somehow, it works. But we do not know why.
   
   You can test this in debug mode to make sure the request is entering the filter.
   
   —
   Reply to this email directly, view it on GitHub<https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fapache%2Fapisix-java-plugin-runner%2Fissues%2F219%23issuecomment-1341906325&data=05%7C01%7Czhanpeng.lu%40cn.bosch.com%7C3312c971c05341fc98eb08dad8c6d5c9%7C0ae51e1907c84e4bbb6d648ee58410f4%7C0%7C0%7C638060645745516713%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=Nx14eeg4LasbbRmk9D4%2BGZUfNFDtYlr7wduRhurpOwk%3D&reserved=0>, or unsubscribe<https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FARTFJ623PE6MQVHFIHEVXUTWMFEDXANCNFSM6AAAAAASWZ2MKQ&data=05%7C01%7Czhanpeng.lu%40cn.bosch.com%7C3312c971c05341fc98eb08dad8c6d5c9%7C0ae51e1907c84e4bbb6d648ee58410f4%7C0%7C0%7C638060645745516713%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=EMjbIvdgQ6lG0MEOmF%2FpJykQJmLANr3x%2FvMCNF
 aJMbQ%3D&reserved=0>.
   You are receiving this because you authored the thread.Message ID: ***@***.******@***.***>>
   


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix-java-plugin-runner] zhlu001 commented on issue #219: help request: How to dynamic add/remove headers in "ext-plugin" with Java Runner

Posted by GitBox <gi...@apache.org>.
zhlu001 commented on issue #219:
URL: https://github.com/apache/apisix-java-plugin-runner/issues/219#issuecomment-1341820916

   Hi tzssanglass,
   Thanks for your reply, we've tried. it doesn't work. 
   client  (original 10 header)--> plugin (add 2 headers) -> upstream(still 10 headers)
   
   we debugged following. in the plugin operated header does not impact original headers, 
   request.setHeader
   request.getHeaders().put()
   request.getHeaders().clear()
   
   
   In above debugger info, We noticed that line 223 in the "RpcCallHandler" in the "org.apache.apisix.plugin.runner.handler";package
   still using the original request, even the ext-plugin add or remove the header


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix-java-plugin-runner] tzssangglass commented on issue #219: help request: How to dynamic add/remove headers in "ext-plugin" with Java Runner

Posted by GitBox <gi...@apache.org>.
tzssangglass commented on issue #219:
URL: https://github.com/apache/apisix-java-plugin-runner/issues/219#issuecomment-1341872721

   I can't reproduce your problem.
   
   filter:
   
   ```java
   package com.example.demo;
   
   import org.apache.apisix.plugin.runner.HttpRequest;
   import org.apache.apisix.plugin.runner.HttpResponse;
   import org.apache.apisix.plugin.runner.filter.PluginFilter;
   import org.apache.apisix.plugin.runner.filter.PluginFilterChain;
   import org.slf4j.Logger;
   import org.slf4j.LoggerFactory;
   import org.springframework.stereotype.Component;
   
   @Component
   public class DemoFilter implements PluginFilter {
       private final Logger logger = LoggerFactory.getLogger(DemoFilter.class);
   
       @Override
       public String name() {
           return "DemoFilter";
       }
   
       @Override
       public void filter(HttpRequest request, HttpResponse response, PluginFilterChain chain) {
           logger.warn("DemoFilter is running");
           request.setHeader("X-APISIX-Plugin-Runner", "0.4.0");
           chain.filter(request, response);
       }
   }
   ```
   
   route:
   
   ```shell
   curl -i http://127.0.0.1:9080/apisix/admin/routes/1  -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
   {
       "uri": "/get",
       "plugins": {
           "ext-plugin-pre-req": {
               "conf" : [
                   {"name": "DemoFilter", "value": "{\"enable\":\"feature\"}"}
               ]
           }
       },
       "upstream": {
           "type": "roundrobin",
           "nodes": {
               "httpbin.org:80": 1
           }
       }
   }'
   ```
   
   test:
   
   ```shell
   curl http://127.0.0.1:9080/get
   {
     "args": {},
     "headers": {
       "Accept": "*/*",
       "Host": "127.0.0.1",
       "User-Agent": "curl/7.79.1",
       "X-Apisix-Plugin-Runner": "0.4.0",
       "X-Forwarded-Host": "127.0.0.1"
     },
     "origin": "127.0.0.1, 103.116.72.14",
     "url": "http://127.0.0.1/get"
   }
   ```
   
   you can see: `"X-Apisix-Plugin-Runner": "0.4.0"` that upstream receive


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix-java-plugin-runner] tzssangglass commented on issue #219: help request: How to dynamic add/remove headers in "ext-plugin" with Java Runner

Posted by GitBox <gi...@apache.org>.
tzssangglass commented on issue #219:
URL: https://github.com/apache/apisix-java-plugin-runner/issues/219#issuecomment-1341906325

   > Besides, we tested response.setheader(), somehow, it works. But we do not know why.
   
   You can test this in debug mode to make sure the request is entering the filter.


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix-java-plugin-runner] zhlu001 commented on issue #219: help request: How to dynamic add/remove headers in "ext-plugin" with Java Runner

Posted by GitBox <gi...@apache.org>.
zhlu001 commented on issue #219:
URL: https://github.com/apache/apisix-java-plugin-runner/issues/219#issuecomment-1341875833

   Hi,
   
   We use spring boot  as receiver with ***@***.***”.
   Besides, we tested response.setheader(), somehow, it works. But we do not know why.
   
   Thx.
   
   Best regards,
   
   Zhanpeng LU
   
   Business Analytics Asia Pacific (CI/PDD2)
   Bosch (China) Investment Ltd. | 333 Fuquan (N.) Road | Shanghai 200335 | P.R. CHINA
   ***@***.******@***.***>
   ​
   From: tzssangglass ***@***.***>
   Sent: Thursday, December 8, 2022 10:06
   To: apache/apisix-java-plugin-runner ***@***.***>
   Cc: LU Zhanpeng (CI/PDD2) ***@***.***>; Author ***@***.***>
   Subject: Re: [apache/apisix-java-plugin-runner] help request: How to dynamic add/remove headers in "ext-plugin" with Java Runner (Issue #219)
   
   
   I can't reproduce your problem.
   
   filter:
   
   package com.example.demo;
   
   
   
   import org.apache.apisix.plugin.runner.HttpRequest;
   
   import org.apache.apisix.plugin.runner.HttpResponse;
   
   import org.apache.apisix.plugin.runner.filter.PluginFilter;
   
   import org.apache.apisix.plugin.runner.filter.PluginFilterChain;
   
   import org.slf4j.Logger;
   
   import org.slf4j.LoggerFactory;
   
   import org.springframework.stereotype.Component;
   
   
   
   @Component
   
   public class DemoFilter implements PluginFilter {
   
       private final Logger logger = LoggerFactory.getLogger(DemoFilter.class);
   
   
   
       @Override
   
       public String name() {
   
           return "DemoFilter";
   
       }
   
   
   
       @Override
   
       public void filter(HttpRequest request, HttpResponse response, PluginFilterChain chain) {
   
           logger.warn("DemoFilter is running");
   
           request.setHeader("X-APISIX-Plugin-Runner", "0.4.0");
   
           chain.filter(request, response);
   
       }
   
   }
   
   route:
   
   curl -i http://127.0.0.1:9080/apisix/admin/routes/1  -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
   
   {
   
       "uri": "/get",
   
       "plugins": {
   
           "ext-plugin-pre-req": {
   
               "conf" : [
   
                   {"name": "DemoFilter", "value": "{\"enable\":\"feature\"}"}
   
               ]
   
           }
   
       },
   
       "upstream": {
   
           "type": "roundrobin",
   
           "nodes": {
   
               "httpbin.org:80": 1
   
           }
   
       }
   
   }'
   
   test:
   
   curl http://127.0.0.1:9080/get
   
   {
   
     "args": {},
   
     "headers": {
   
       "Accept": "*/*",
   
       "Host": "127.0.0.1",
   
       "User-Agent": "curl/7.79.1",
   
       "X-Apisix-Plugin-Runner": "0.4.0",
   
       "X-Forwarded-Host": "127.0.0.1"
   
     },
   
     "origin": "127.0.0.1, 103.116.72.14",
   
     "url": "http://127.0.0.1/get"
   
   }
   
   you can see: "X-Apisix-Plugin-Runner": "0.4.0" that upstream receive
   
   —
   Reply to this email directly, view it on GitHub<https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fapache%2Fapisix-java-plugin-runner%2Fissues%2F219%23issuecomment-1341872721&data=05%7C01%7Czhanpeng.lu%40cn.bosch.com%7C8269ea59b61d41a1da4a08dad8c0b373%7C0ae51e1907c84e4bbb6d648ee58410f4%7C0%7C0%7C638060619398523548%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=2FwWEBMdVOGYp0A38czGP6DxQNMES3S0aoNF%2BngYUdo%3D&reserved=0>, or unsubscribe<https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FARTFJ6ZIUWTWPDGFTBJJY23WME67BANCNFSM6AAAAAASWZ2MKQ&data=05%7C01%7Czhanpeng.lu%40cn.bosch.com%7C8269ea59b61d41a1da4a08dad8c0b373%7C0ae51e1907c84e4bbb6d648ee58410f4%7C0%7C0%7C638060619398523548%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=js%2FscMNX3FvzNjLIESv6JuJkt6WfGyyabSbmBiHN
 qnY%3D&reserved=0>.
   You are receiving this because you authored the thread.Message ID: ***@***.******@***.***>>
   


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix-java-plugin-runner] tzssangglass commented on issue #219: help request: How to dynamic add/remove headers in "ext-plugin" with Java Runner

Posted by GitBox <gi...@apache.org>.
tzssangglass commented on issue #219:
URL: https://github.com/apache/apisix-java-plugin-runner/issues/219#issuecomment-1342505774

   Such a conversation is meaningless and difficult to carry on. You can try to reproduce the steps I gave above.
   
   and read: https://github.com/apache/apisix-java-plugin-runner/blob/main/docs/en/latest/how-it-works.md#debug


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org