beginnerWJC commented on issue #8768:
URL: https://github.com/apache/apisix/issues/8768#issuecomment-1432812948

   this is my test plugin
   `package org.apache.apisix.plugin.runner.filter;
   
   import java.util.Map;
   import org.apache.apisix.plugin.runner.PostRequest;
   import org.apache.apisix.plugin.runner.PostResponse;
   import org.slf4j.Logger;
   import org.slf4j.LoggerFactory;
   import org.springframework.stereotype.Component;
   import com.alibaba.fastjson.JSON;
   
   @Component
   public class TestPostFilter implements PluginFilter {
        
        private final Logger logger = 
LoggerFactory.getLogger(TestPostFilter.class);
   
        @Override
        public String name() {
                return "TestPostFilter";
        }
        
        @Override
        public void postFilter(PostRequest request, PostResponse response, 
PluginFilterChain chain) {
                logger.info("TestPostFilter插件开始执行!");
                Map<String, String> headersMap = request.getUpstreamHeaders();
                logger.info("上游返回的headers:{}",JSON.toJSONString(headersMap));
                int statusCode = request.getUpstreamStatusCode();
                logger.info("上游返回的状态码为:{}",statusCode);
                if(statusCode == 204) {
                        logger.info("修改上游的状态码为200");
                        response.setStatusCode(200);
                }
                response.setHeader("apisix", "TestPostFilter");
                chain.postFilter(request, response);
       }
        
        @Override
        public Boolean requiredBody() {
                return true;
        }
   
   }`
   the router
   `{ "uri": "/oam/2.0/tenant/upload/vox", "name": "testfile", "methods": [ 
"POST" ], "plugins": { "ext-plugin-pre-req": { "conf": [ { "name": 
"TestPostFilter", "value": "" } ], "disable": false } }, "upstream_id": 
"435624104997946125", "status": 1 }`


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