简体   繁体   English

stubby4node 逗号分隔的查询字符串实现问题

[英]stubby4node comma separated query string implementation issue

I have a URL (GET REQUEST) of the following pattern我有以下模式的 URL (GET REQUEST)

  • ^/testpath/1/test?pathid=1 ^/testpath/1/test?pathid=1
  • ^/testpath/1/test?pathid=1,2 ^/testpath/1/test?pathid=1,2
  • ^/testpath/1/test?pathid=1,2,5 ^/testpath/1/test?pathid=1,2,5

where pathid query string parameters are comma separated其中 pathid 查询字符串参数以逗号分隔

I have the following stubby mappings to match these url patterns我有以下粗短的映射来匹配这些 url 模式

- request:
    url: ^/testpath/(.*)/test
    query:
      pathid: '1'
    method: GET
  response:
    headers:
      Content-Type: application/json
    status: 200
    file: response/path-1.json

- request:
    url: ^/testpath/(.*)/test
    query:
      pathid: '1,2'
    method: GET
  response:
    headers:
      Content-Type: application/json
    status: 200
    file: response/path-2.json

- request:
    url: ^/testpath/(.*)/test
    query:
      pathid: '1,2,5'
    method: GET
  response:
    headers:
      Content-Type: application/json
    status: 200
    file: response/path-3.json

but I can't get this URL mapping to properly deliver different payloads based on different parameter combinations.但我无法得到这个 URL 映射来根据不同的参数组合正确传递不同的有效载荷。

  • 1 -> payload1 1 -> 有效载荷1
  • 1,2 -> payload2 1,2 -> 有效载荷2
  • 1,2,5 -> payload3 1,2,5 -> 有效载荷3

how can this be done?如何才能做到这一点?

@Sanath, short answer - yes, stubby4j matches on different stubbed query parameters combinations. @Sanath,简短的回答 - 是的,stubby4j 匹配不同的存根查询参数组合。

Few questions:几个问题:

  1. What version of stubby4j are you running?你运行的是什么版本的 stubby4j?
  2. Also, are you running stubby4j as a standalone JAR or as one of the pre-built stubby4j Docker containers ?此外,您是将 stubby4j 作为独立的 JAR 还是作为预构建的 stubby4j Docker 容器之一运行

I wrote a test to validate the YAML configuration you provided in your question: https://github.com/azagniotov/stubby4j/pull/434/files (do note, I did change the url a little, but it is still a regex similar to your posted YAML). I wrote a test to validate the YAML configuration you provided in your question: https://github.com/azagniotov/stubby4j/pull/434/files (do note, I did change the url a little, but it is still a regex类似于您发布的 YAML)。

The requests that test makes do match the stubs.测试发出的请求与存根匹配。 (I did try without $ and with a $ , like @code suggested). (我确实尝试过没有$$ ,就像@code建议的那样)。 In addition, I also tested with cURL against a running standalone JAR:此外,我还针对正在运行的独立 JAR 使用 cURL 进行了测试:

curl -X GET  http://localhost:8882/stackoverflow/70417269/1/test?pathid=1,2,5

and

curl -X GET  http://localhost:8882/stackoverflow/70417269/1/test?pathid=1,2

Again, I got the expected responses from the server.同样,我从服务器得到了预期的响应。

If the above does not help you, please feel free to raise a bug report https://github.com/azagniotov/stubby4j/issues/new/choose如果以上内容对您没有帮助,请随时提出错误报告https://github.com/azagniotov/stubby4j/issues/new/choose

The trick here is to change the order of request/response mappings in the yaml file.这里的技巧是更改 yaml 文件中请求/响应映射的顺序。

- request:
    url: ^/testpath/(.*)/test
    query:
      **pathid: '1,2,5'**
    method: GET
  response:
    headers:
      Content-Type: application/json
    status: 200
    file: response/path-3.json

- request:
    url: ^/testpath/(.*)/test
    query:
      **pathid: '1,2'**
    method: GET
  response:
    headers:
      Content-Type: application/json
    status: 200
    file: response/path-2.json

- request:
    url: ^/testpath/(.*)/test
    query:
      **pathid: '1'**
    method: GET
  response:
    headers:
      Content-Type: application/json
    status: 200
    file: response/path-1.json

note the path ids added in the descending order, so that more deeper matches will be executed first.请注意按降序添加的路径 ID,以便首先执行更深入的匹配。

This way I was able to achieve this following requirement, of passing different path ids separated by a comma通过这种方式,我能够实现以下要求,即传递用逗号分隔的不同路径 ID

  • 1 -> payload1 1 -> 有效载荷1
  • 1,2 -> payload2 1,2 -> 有效载荷2
  • 1,2,5 -> payload3 1,2,5 -> 有效载荷3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM