Vector() in JSON string produced by JSON Feeder in Gatling
Vector() in JSON string produced by JSON Feeder in Gatling
我正在这样构建我的场景:
val scene = scenario("testWebSocket").feed(jsonFileFeeder)
.exec(ws("openSocket").connect("")
.onConnected(exec(ws("sendMessage").sendText(StringBody("""{"jsonrpc": "${jsonrpc}", "method": "${method}", "params": ${params}, "id": ${id}}"""))
.await(20)(ws.checkTextMessage("check1").check(regex(".*4,0,0,0.*")
.saveAs("myMessage"))))))
但是它正在发送 JSON 这样的请求:
{
"jsonrpc": "2.0",
"method": "place_order",
"params": Vector(65, 61, 211, 138, 32, 161, 21, 135, 119, 9, 73, 45, 139, 62, 46, 163, 53, 200, 61, 38, 155, 91, 91, 249, 210, 145, 60, 178, 179, 171, 71, 193, 213, 2, 1, 4, 212, 53, 147, 199, 21, 253, 211, 28, 97, 20, 26, 189, 4, 169, 159, 214, 130, 44, 133, 88, 133, 76, 205, 227, 154, 86, 132, 231, 165, 109, 162, 125, 212, 53, 147, 199, 21, 253, 211, 28, 97, 20, 26, 189, 4, 169, 159, 214, 130, 44, 133, 88, 133, 76, 205, 227, 154, 86, 132, 231, 165, 109, 162, 125, 1, 0, 28, 116, 114, 117, 115, 116, 101, 100, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 122, 4, 79, 138, 32, 252, 120, 79, 100, 117, 247, 183, 205, 3, 67, 88, 172, 14, 16, 29, 81, 162, 198, 134, 99, 201, 64, 176, 7, 172, 38, 104, 106, 129, 107, 99, 253, 123, 151, 11, 5, 166, 131, 118, 87, 9, 212, 200, 61, 19, 190, 125, 143, 81, 72, 215, 99, 242, 189, 122, 245, 131, 34, 140),
"id": 1
}
如您所见,Params
包含 Vector()
... 由于哪个服务器不接受它。
正确的Json
请求应该是这样的:
{
"jsonrpc": "2.0",
"method": "place_order",
"params": [ 65, 61, 211, 138, 32, 161, 21, 135, 119, 9, 73, 45, 139, 62, 46, 163, 53, 200, 61, 38, 155, 91, 91, 249, 210, 145, 60, 178, 179, 171, 71, 193, 213, 2, 1, 4, 212, 53, 147, 199, 21, 253, 211, 28, 97, 20, 26, 189, 4, 169, 159, 214, 130, 44, 133, 88, 133, 76, 205, 227, 154, 86, 132, 231, 165, 109, 162, 125, 212, 53, 147, 199, 21, 253, 211, 28, 97, 20, 26, 189, 4, 169, 159, 214, 130, 44, 133, 88, 133, 76, 205, 227, 154, 86, 132, 231, 165, 109, 162, 125, 1, 0, 28, 116, 114, 117, 115, 116, 101, 100, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 220, 147, 46, 22, 173, 5, 142, 129, 16, 66, 122, 229, 171, 169, 4, 53, 106, 240, 77, 126, 62, 116, 99, 107, 213, 226, 183, 67, 110, 1, 112, 15, 95, 74, 146, 104, 120, 166, 80, 57, 32, 51, 81, 142, 140, 154, 196, 188, 169, 126, 46, 149, 184, 50, 161, 223, 24, 14, 151, 23, 104, 7, 173, 128 ],
"id": 1
}
如果你不告诉 Gatling 你想要什么样的序列化,它无法猜测你想要什么JSON。
使用jsonStringify()
,比照documentation.
StringBody("""{"jsonrpc": "${jsonrpc}", "method": "${method}", "params": ${params.jsonStringify()}, "id": ${id}}""")
我正在这样构建我的场景:
val scene = scenario("testWebSocket").feed(jsonFileFeeder)
.exec(ws("openSocket").connect("")
.onConnected(exec(ws("sendMessage").sendText(StringBody("""{"jsonrpc": "${jsonrpc}", "method": "${method}", "params": ${params}, "id": ${id}}"""))
.await(20)(ws.checkTextMessage("check1").check(regex(".*4,0,0,0.*")
.saveAs("myMessage"))))))
但是它正在发送 JSON 这样的请求:
{
"jsonrpc": "2.0",
"method": "place_order",
"params": Vector(65, 61, 211, 138, 32, 161, 21, 135, 119, 9, 73, 45, 139, 62, 46, 163, 53, 200, 61, 38, 155, 91, 91, 249, 210, 145, 60, 178, 179, 171, 71, 193, 213, 2, 1, 4, 212, 53, 147, 199, 21, 253, 211, 28, 97, 20, 26, 189, 4, 169, 159, 214, 130, 44, 133, 88, 133, 76, 205, 227, 154, 86, 132, 231, 165, 109, 162, 125, 212, 53, 147, 199, 21, 253, 211, 28, 97, 20, 26, 189, 4, 169, 159, 214, 130, 44, 133, 88, 133, 76, 205, 227, 154, 86, 132, 231, 165, 109, 162, 125, 1, 0, 28, 116, 114, 117, 115, 116, 101, 100, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 122, 4, 79, 138, 32, 252, 120, 79, 100, 117, 247, 183, 205, 3, 67, 88, 172, 14, 16, 29, 81, 162, 198, 134, 99, 201, 64, 176, 7, 172, 38, 104, 106, 129, 107, 99, 253, 123, 151, 11, 5, 166, 131, 118, 87, 9, 212, 200, 61, 19, 190, 125, 143, 81, 72, 215, 99, 242, 189, 122, 245, 131, 34, 140),
"id": 1
}
如您所见,Params
包含 Vector()
... 由于哪个服务器不接受它。
正确的Json
请求应该是这样的:
{
"jsonrpc": "2.0",
"method": "place_order",
"params": [ 65, 61, 211, 138, 32, 161, 21, 135, 119, 9, 73, 45, 139, 62, 46, 163, 53, 200, 61, 38, 155, 91, 91, 249, 210, 145, 60, 178, 179, 171, 71, 193, 213, 2, 1, 4, 212, 53, 147, 199, 21, 253, 211, 28, 97, 20, 26, 189, 4, 169, 159, 214, 130, 44, 133, 88, 133, 76, 205, 227, 154, 86, 132, 231, 165, 109, 162, 125, 212, 53, 147, 199, 21, 253, 211, 28, 97, 20, 26, 189, 4, 169, 159, 214, 130, 44, 133, 88, 133, 76, 205, 227, 154, 86, 132, 231, 165, 109, 162, 125, 1, 0, 28, 116, 114, 117, 115, 116, 101, 100, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 220, 147, 46, 22, 173, 5, 142, 129, 16, 66, 122, 229, 171, 169, 4, 53, 106, 240, 77, 126, 62, 116, 99, 107, 213, 226, 183, 67, 110, 1, 112, 15, 95, 74, 146, 104, 120, 166, 80, 57, 32, 51, 81, 142, 140, 154, 196, 188, 169, 126, 46, 149, 184, 50, 161, 223, 24, 14, 151, 23, 104, 7, 173, 128 ],
"id": 1
}
如果你不告诉 Gatling 你想要什么样的序列化,它无法猜测你想要什么JSON。
使用jsonStringify()
,比照documentation.
StringBody("""{"jsonrpc": "${jsonrpc}", "method": "${method}", "params": ${params.jsonStringify()}, "id": ${id}}""")