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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to