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 2021/09/23 07:53:04 UTC

[GitHub] [apisix-java-plugin-runner] Rdebu opened a new issue #72: bug: 按照官方步骤创建了两个Filter,两个不同的请求都成功,但是第二个请求后重新第一个请求会报错

Rdebu opened a new issue #72:
URL: https://github.com/apache/apisix-java-plugin-runner/issues/72


   ### Issue description
   按照官方步骤创建了两个Filter,两个不同的请求都成功,但是第二个请求后重新第一个请求会报错
   ### Environment
   apisix 2.7 + apisix-java-plugin-runner 0.1 + apisix-Dashboard 2.8
   * your apisix-java-plugin-runner version
   0.1
   ### Minimal test code / Steps to reproduce the issue
   
   1.  我创建TokenFilter与TokenValidor两个Filter放到了 package-info.java同级目录下
   
   2. TokenFilter的代码
   package org.apache.apisix.plugin.runner.filter;
   
   import com.google.gson.Gson;
   import lombok.extern.slf4j.Slf4j;
   import org.apache.apisix.plugin.runner.HttpRequest;
   import org.apache.apisix.plugin.runner.HttpResponse;
   import org.springframework.stereotype.Component;
   import reactor.core.publisher.Mono;
   
   import java.util.HashMap;
   import java.util.Map;
   
   @Slf4j
   @Component
   public class TokenFilter implements PluginFilter {
   
     @Override
     public String name() {
       return "TokenFilter";
     }
   
     @Override
     public Mono<Void> filter(HttpRequest request, HttpResponse response,
                              PluginFilterChain chain) {
       // parse `conf` to json
       String configStr = request.getConfig(this);
       Gson gson = new Gson();
       Map<String, Object> conf = new HashMap<>();
       conf = gson.fromJson(configStr, conf.getClass());
   
       // get configuration parameters
       String token = request.getHeader((String) conf.get("validate_header"));
       log.info("token: {}", token);
       String validateUrl = (String) conf.get("validate_url");
       log.info("validateUrl: {}", validateUrl);
       boolean flag = validate(token, validateUrl);
   //    log.info(
   //        "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
   //    log.info(
   //        "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
   //    log.info(
   //        "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
   //    log.info(
   //        "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
       log.info(
           "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
       log.info(
           "???????????????????????????????????????????????????????????????????????");
       log.info(
           "8888888888888888888888888****************************ssssssssss********");
       // token verification results
       if (!flag) {
         log.info("test------------------failed");
         String rejectedCode = (String) conf.get("rejected_code");
         response.setStatusCode(Integer.parseInt(rejectedCode));
         return chain.filter(request, response);
       }
   
       log.info("test------------------success");
       return chain.filter(request, response);
     }
   
     private Boolean validate(String token, String validateUrl) {
       if ("123456".equals(token) && "vU".equals(validateUrl)) {
         return true;
       }
       return false;
     }
   }
   3. TokenValidator的代码
   package org.apache.apisix.plugin.runner.filter;
   
   import com.google.gson.Gson;
   import lombok.extern.slf4j.Slf4j;
   import org.apache.apisix.plugin.runner.HttpRequest;
   import org.apache.apisix.plugin.runner.HttpResponse;
   import org.springframework.stereotype.Component;
   import reactor.core.publisher.Mono;
   
   import java.util.HashMap;
   import java.util.Map;
   
   @Slf4j
   @Component
   public class TokenValidator implements PluginFilter {
   
     @Override
     public String name() {
       return "TokenValidator";
     }
   
     @Override
     public Mono<Void> filter(HttpRequest request, HttpResponse response,
                              PluginFilterChain chain) {
       // parse `conf` to json
       String configStr = request.getConfig(this);
       Gson gson = new Gson();
       Map<String, Object> conf = new HashMap<>();
       conf = gson.fromJson(configStr, conf.getClass());
   
       // get configuration parameters
       String token = request.getHeader((String) conf.get("validate_header"));
       log.info("token: {}", token);
       String validateUrl = (String) conf.get("validate_url");
       log.info("validateUrl: {}", validateUrl);
       boolean flag = validate(token, validateUrl);
       log.info(
           "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
       log.info(
               "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
       log.info(
               "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
       log.info(
               "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
       log.info(
               "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
       log.info(
               "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
       log.info(
               "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
       log.info(
           "???????????????????????????????????????????????????????????????????????");
       log.info(
           "8888888888888888888888888****************************ssssssssss********");
       // token verification results
       if (!flag) {
         log.info("test------------------failed");
         String rejectedCode = (String) conf.get("rejected_code");
         response.setStatusCode(Integer.parseInt(rejectedCode));
         return chain.filter(request, response);
       }
   
       log.info("test------------------success");
       return chain.filter(request, response);
     }
   
     private Boolean validate(String token, String validateUrl) {
       if ("123456".equals(token) && "vU".equals(validateUrl)) {
         return true;
       }
       return false;
     }
   }
   4. 在apisix-dashboard 中配置两个路由
   
   {
     "uri": "/get",
     "name": "TokenValidator",
     "desc": "TokenValidator",
     "methods": [
       "GET"
     ],
     "plugins": {
       "ext-plugin-pre-req": {
         "conf": [
           {
             "name": "TokenValidator",
             "value": "{\"validate_header\":\"token\",\"validate_url\":\"vU\",\"rejected_code\":\"403\"}"
           }
         ]
       }
     },
     "upstream": {
       "nodes": [
         {
           "host": "httpbin.org",
           "port": 80,
           "weight": 1
         }
       ],
       "timeout": {
         "connect": 6,
         "send": 6,
         "read": 6
       },
       "type": "roundrobin",
       "scheme": "http",
       "pass_host": "pass"
     },
     "labels": {
       "API_VERSION": "V1"
     },
     "status": 1
   }
   
   与
   
   {
     "uri": "/forms/post",
     "name": "TokenFilter",
     "desc": "TokenFilter",
     "methods": [
       "GET"
     ],
     "plugins": {
       "ext-plugin-pre-req": {
         "conf": [
           {
             "name": "TokenFilter",
             "value": "{\"validate_header\":\"token\",\"validate_url\":\"vU\",\"rejected_code\":\"403\"}"
           }
         ]
       }
     },
     "upstream": {
       "nodes": [
         {
           "host": "httpbin.org",
           "port": 80,
           "weight": 1
         }
       ],
       "timeout": {
         "connect": 6,
         "send": 6,
         "read": 6
       },
       "type": "roundrobin",
       "scheme": "http",
       "pass_host": "pass"
     },
     "labels": {
       "API_VERSION": "V1"
     },
     "status": 1
   }
   
   5. 启动apisix
   6. 访问 curl -H 'token: 123456' 127.0.0.1:9080/get -i  成功
   ![image](https://user-images.githubusercontent.com/58921097/134471819-c739863a-168e-4555-8dbd-1e6877fe6f41.png)
   
   7. 访问 curl -H 'token: 123456' 127.0.0.1:9080/forms/post -i 成功
   ![image](https://user-images.githubusercontent.com/58921097/134471887-016d865c-9571-4624-a549-786faf643e37.png)
   
   8. 第六步第七步的步骤可以替换,主要是访问了第七步的步骤,重新访问第六步的步骤,就会报503的错误
   ![image](https://user-images.githubusercontent.com/58921097/134471982-c2af540b-b703-4d2d-9f29-0cf03eabd7ce.png)
   
   
   ### What's the actual result? (including assertion message & call stack if applicable)
   2021/09/23 15:37:30 [error] 3745#3745: *903 [lua] init.lua:553: phase_func(): failed to receive RPC_HTTP_REQ_CALL: closed, client: 127.0.0.1, server: _, request: "GET /forms/post HTTP/1.1", host: "127.0.0.1:9080"
   2021/09/23 15:37:30 [warn] 3745#3745: *903 [lua] plugin.lua:646: run_plugin(): ext-plugin-pre-req exits with http status code 503, client: 127.0.0.1, server: _, request: "GET /forms/post HTTP/1.1", host: "127.0.0.1:9080"
   HTTP/1.1 503 Service Temporarily Unavailable
   Date: Thu, 23 Sep 2021 07:37:30 GMT
   Content-Type: text/html; charset=utf-8
   Content-Length: 194
   Connection: keep-alive
   Server: APISIX/2.7
   
   <html>
   <head><title>503 Service Temporarily Unavailable</title></head>
   <body>
   <center><h1>503 Service Temporarily Unavailable</h1></center>
   <hr><center>openresty</center>
   </body>
   </html>
   
   
   ![image](https://user-images.githubusercontent.com/58921097/134471999-084dd8af-8d18-40e6-b29c-5189465f46a5.png)
   
   ### What's the expected result?
   预期结果为步骤6的正常访问结果


-- 
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 #72: bug: Following the official steps to create two filters, two different requests are successful, but the second request is followed by an error on the first request

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


   Please use this PR to verify that it is fixed: https://github.com/apache/apisix-java-plugin-runner/pull/73


-- 
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 #72: bug: Following the official steps to create two filters, two different requests are successful, but the second request is followed by an error on the first request

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


   no more response, considered as resolved, feel free to reopen this.


-- 
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] Rdebu commented on issue #72: bug: 按照官方步骤创建了两个Filter,两个不同的请求都成功,但是第二个请求后重新第一个请求会报错

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


   此后要是多次访问会出现503的请求,另一个请求也会响应503


-- 
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] Rdebu commented on issue #72: bug: Following the official steps to create two filters, two different requests are successful, but the second request is followed by an error on the first request

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


   > 只需使用此分支:
   > ![图片](https://user-images.githubusercontent.com/30819887/134609091-d08851b3-1d0e-46a1-8a43-400e5458dc90.png)
   
   okok 我试试   哈哈哈哈 github还没完明白 


-- 
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 #72: bug: Following the official steps to create two filters, two different requests are successful, but the second request is followed by an error on the first request

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


   just use this branch: 
   ![image](https://user-images.githubusercontent.com/30819887/134609091-d08851b3-1d0e-46a1-8a43-400e5458dc90.png)
   


-- 
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] Rdebu commented on issue #72: bug: Following the official steps to create two filters, two different requests are successful, but the second request is followed by an error on the first request

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


   > Please use this PR to verify that it is fixed: #73
   
   所以我只要根据这6个链接 修改相应的源码就可以正常访问了是吗
   ![image](https://user-images.githubusercontent.com/58921097/134608325-d6653c1b-e664-4ce3-a264-c65c00c1956c.png)
   


-- 
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 closed issue #72: bug: Following the official steps to create two filters, two different requests are successful, but the second request is followed by an error on the first request

Posted by GitBox <gi...@apache.org>.
tzssangglass closed issue #72:
URL: https://github.com/apache/apisix-java-plugin-runner/issues/72


   


-- 
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