dreamhead / moco

Easy Setup Stub Server
MIT License
4.36k stars 1.08k forks source link

Post json array error! Please help #267

Closed lidd1986 closed 4 years ago

lidd1986 commented 4 years ago

Config like this:

[{
  "request" :
  {
    "uri" : "/test",
    "method" : "POST",
    "json_paths" : {
        "$.detail_item_list[*].number": {
             "match": "\\d+"
         }
    }
  },
  "response" :
  {
    "status" : "200",
    "text" : "OK"
  }
}]

When i post the following body, error happend. It seems that it is related to the integer array type.

{
    "detail_item_list":[
    {
        "number": 100
     }]
}

28 十月 2019 11:03:46 [pool-1-thread-6] ERROR Exception thrown

java.lang.ArrayStoreException: null
        at java.lang.System.arraycopy(Native Method)
        at java.util.ArrayList.toArray(Unknown Source)
        at com.github.dreamhead.moco.extractor.JsonPathRequestExtractor.toStringArray(JsonPathRequestExtractor.java:51)
        at com.github.dreamhead.moco.extractor.JsonPathRequestExtractor.doExtract(JsonPathRequestExtractor.java:41)
        at com.github.dreamhead.moco.HttpRequestExtractor.extract(HttpRequestExtractor.java:10)
        at com.github.dreamhead.moco.matcher.AbstractOperatorMatcher.match(AbstractOperatorMatcher.java:33)
        at com.github.dreamhead.moco.matcher.AndRequestMatcher.doMatch(AndRequestMatcher.java:14)
        at com.github.dreamhead.moco.matcher.CompositeRequestMatcher.match(CompositeRequestMatcher.java:51)
        at com.github.dreamhead.moco.setting.BaseSetting.match(BaseSetting.java:30)
        at com.github.dreamhead.moco.internal.MocoHandler.doGetHttpResponse(MocoHandler.java:76)
        at com.github.dreamhead.moco.internal.MocoHandler.getHttpResponse(MocoHandler.java:61)
        at com.github.dreamhead.moco.internal.MocoHandler.handleRequest(MocoHandler.java:51)
        at com.github.dreamhead.moco.internal.MocoHandler.channelRead0(MocoHandler.java:40)
        at com.github.dreamhead.moco.internal.MocoHandler.channelRead0(MocoHandler.java:25)
        at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:352)
        at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:352)
        at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:438)
        at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:328)
        at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:302)
        at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:253)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:352)
        at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1421)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360)
        at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:930)
        at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163)
        at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:697)
        at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:632)
        at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:549)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:511)
        at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:918)
        at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
28 十月 2019 11:03:46 [pool-1-thread-6] INFO  Response return:

HTTP/1.1 400
dreamhead commented 4 years ago

It's a BUG. Thank your for your issue.

It's already fixed at https://github.com/dreamhead/moco/commit/e30773443a018e710559d9b7aac6856c65901fe3

You can build your own Moco for the fix. https://github.com/dreamhead/moco#build

lidd1986 commented 4 years ago

very thanks