apache / apache/apisix-java-plugin-runner

request help: I want to check in ext-plugin-post-resp plugin according to upstream response status.

Đang mở
#255 3 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Java
Star
152
Fork
102
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

### Issue description
When the upstream response status is 400 or 500, the postfilter cannot check the status.

my post filter is
```
@Override
public void postFilter(PostRequest request, PostResponse response, PluginFilterChain chain) {
log.info("--------------------post filter start------------11111111");
log.info(request.getUpstreamHeaders().toString());
log.info(request.getUpstreamStatusCode().toString());
log.info(request.getBody());
chain.postFilter(request, response);
}
```

When the upstream responds with 200, the log is
```
--------------------post filter start------------11111111
{Keep-Alive=timeout=60, Transfer-Encoding=chunked, test=1234, Connection=keep-alive, Date=Fri, 14 Jul 2023 02:12:15 GMT, Content-Type=application/json}
200
{"createdDate":null,"modifiedDate":null,"id":null,"name":"ccs","apiCode":"abcd"}
```

but, 400 or 500
```
--------------------post filter start------------11111111
{}
0
{"createdDate":null,"modifiedDate":null,"id":null,"name":"ccs","apiCode":"abcd"}
```
I want to process logic based on the upstream response status(200, 400, 500)
**can u check this problems?**
@nic-chen

and one more thing..
In about half of all calls, postfilter throws java.lang.IndexOutOfBoundsException: null.
error.log is
```
2023/07/14 11:35:23 [warn] 6638#6638: *17534332 [lua] init.lua:953: 2023-07-14 11:35:23.257 INFO 6652 --- [tLoopGroup-34-5] c.d.p.F.TestFilter : --------------------post filter start------------11111111
, context: ngx.timer
2023/07/14 11:35:23 [warn] 6638#6638: *17534332 [lua] init.lua:953: 2023-07-14 11:35:23.257 ERROR 6652 --- [tLoopGroup-34-5] o.a.a.p.r.h.RpcCallHandler : handle request error:

java.lang.IndexOutOfBoundsException: null
at java.nio.Buffer.checkIndex(Buffer.java:693) ~[?:?]
at java.nio.DirectByteBuffer.getInt(DirectByteBuffer.java:758) ~[?:?]
at com.google.flatbuffers.Table.__vector_len(Table.java:125) ~[flatbuffers-java-2.0.0.jar!/:?]
at io.github.api7.A6.HTTPRespCall.Req.headersLength(Req.java:22) ~[A6-0.6.0-RELEASE.jar!/:?]
at org.apache.apisix.plugin.runner.PostRequest.getUpstreamHeaders(PostRequest.java:81) ~[apisix-runner-plugin-sdk-0.4.0.jar!/:0.4.0]
at com.platform.Filter.TestFilter.postFilter(TestFilter.java:127) ~[classes!/:1.0.0]
at org.apache.apisix.plugin.runner.filter.PluginFilterChain.postFilter(PluginFilterChain.java:64) ~[apisix-runner-plugin-sdk-0.4.0.jar!/:0.4.0]
at org.apache.apisix.plugin.runner.handler.RpcCallHandler.doPostFilter(RpcCallHandler.java:211) ~[apisix-runner-core-0.4.0.jar!/:0.4.0]
at org.apache.apisix.plugin.runner.handler.RpcCallHandler.handleExtraInfo(RpcCallHandler.java:243) ~[apisix-runner-core-0.4.0.jar!/:0.4.0]
at org.apache.apisix.plugin.runner.handler.RpcCallHandler.channelRead0(RpcCallHandler.java:92) ~[apisix-runner-core-0.4.0.jar!/:0.4.0]
at org.apache.apisix.plugin.runner.handler.RpcCallHandler.channelRead0(RpcCallHandler.java:54) ~[apisix-runner-core-0.4.0.jar!/:0.4.0]
at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:99) ~[netty-transport-4.1.78.Final.jar!/:4.1.78.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) ~[netty-transport-4.1.78.Final.jar!/:4.1.78.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) ~[netty-transport-4.1.78.Final.jar!/:4.1.78.Final]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) ~[netty-transport-4.1.78.Final.jar!/:4.1.78.Final]
at org.apache.apisix.plugin.runner.handler.PrepareConfHandler.channelRead0(PrepareConfHandler.java:57) ~[apisix-runner-core-0.4.0.jar!/:0.4.0]
at org.apache.apisix.plugin.runner.handler.PrepareConfHandler.channelRead0(PrepareConfHandler.java:45) ~[apisix-runner-core-0.4.0.jar!/:0.4.0]
at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:99) ~[netty-transport-4.1.78.Final.jar!/:4.1.78.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) ~[netty-transport-4.1.78.Final.jar!/:4.1.78.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) ~[netty-transport-4.1.78.Final.jar!/:4.1.78.Final]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) ~[netty-transport-4.1.78.Final.jar!/:4.1.78.Final]
at org.apache.apisix.plugin.runner.handler.PayloadDecoder.channelRead0(PayloadDecoder.java:45) ~[apisix-runner-core-0.4.0.jar!/:0.4.0]
at org.apache.apisix.plugin.runner.handler.PayloadDecoder.channelRead0(PayloadDecoder.java:38) ~[apisix-runner-core-0.4.0.jar!/:0.4.0]
at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:99) ~[netty-transport-4.1.78.Final.jar!/:4.1.78.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) ~[netty-transport-4.1.78.Final.jar!/:4.1.78.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) ~[netty-transport-4.1.78.Final.jar!/:4.1.78.Final]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) ~[nett, context: ngx.timer
2023/07/14 11:35:23 [warn] 6638#6638: *17534332 [lua] init.lua:953: y-transport-4.1.78.Final.jar!/:4.1.78.Final]
at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:327) ~[netty-codec-4.1.78.Final.jar!/:4.1.78.Final]
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:299) ~[netty-codec-4.1., context: ngx.timer
2023/07/14 11:35:23 [warn] 6638#6638: *17534332 [lua] init.lua:953: 78.Final.jar!/:4.1.78.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) ~[netty-transport-4.1.78.Final.jar!/:4.1.78.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) ~[netty-transport-4.1.78.Final.jar!/:4.1.78.Final]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) ~[netty-transport-4.1.78.Final.jar!/:4.1.78.Final]
at io.netty.handler.logging.LoggingHandler.channelRead(LoggingHandler.java:280) ~[netty-handler-4.1.78.Final.jar!/:4.1.78.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) ~[netty-transport-4.1.78.Final.jar!/:4.1.78.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) ~[netty-transport-4.1.78.Final.jar!/:4.1.78.Final]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) ~[netty-transport-4.1.78.Final.jar!/:4.1.78.Final]
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410) ~[netty-transport-4.1.78.Final.jar!/:4.1.78.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) ~[netty-transport-4.1.78.Final.jar!/:4.1.78.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) ~[netty-transport-4.1.78.Final.jar!/:4.1.78.Final]
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919) ~[netty-transport-4.1.78.Final.jar!/:4.1.78.Final]
at io.netty.channel.epoll.AbstractEpollStreamChannel$EpollStreamUnsafe.epollInReady(AbstractEpollStreamChannel.java:800) ~[netty-transport-classes-epoll-4.1.78.Final.jar!/:4.1.78.Final]
at io.netty.channel.epoll.EpollDomainSocketChannel$EpollDomainUnsafe.epollInReady(EpollDomainSocketChannel.java:138) ~[netty-transport-classes-epoll-4.1.78.Final.jar!/:4.1.78.Final]
at io.netty.channel.epoll.EpollEventLoop.processReady(EpollEventLoop.java:487) ~[netty-transport-classes-epoll-4.1.78.Final.jar!/:4.1.78.Final]
at io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:385) ~[netty-transport-classes-epoll-4.1.78.Final.jar!/:4.1.78.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997) ~[netty-common-4.1.78.Final.jar!/:4.1.78.Final]
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.78.Final.jar!/:4.1.78.Final]
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-common-4.1.78.Final.jar!/:4.1.78.Final]
at java.lang.Thread.run(Thread.java:829) ~[?:?]
```
TestFilter.java:127 line is **'log.info(request.getUpstreamHeaders().toString())'**

thx in advance

### Environment
apisix 3.2.0, 3.2.1
apisix-java-plugin-runner 0.4.0

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.