admin管理员组文章数量:1299985
I have my wiremock service running on a kubernetes pod. One of the mappings is as follows:
{
"request": {
"method": "POST",
"urlPattern": "/v1/queue/*."
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/json"
},
"body": "{\"id\":\"GR3e9g\",\"partition\":4,\"time\":07448}"
}
}
Now whenever the wiremock service receives an API call matching the urlPattern /v1/queue/*.
, I want to add custom logic for the wiremock service to make a call to DynamoDB table. Can I get some pointers on how to implement that. What changes do I make to this Dockerfile to accomodate the custom logic implementation?
FROM wiremock/wiremock:latest
COPY stubs /home/wiremock
EXPOSE 8080
I have my wiremock service running on a kubernetes pod. One of the mappings is as follows:
{
"request": {
"method": "POST",
"urlPattern": "/v1/queue/*."
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/json"
},
"body": "{\"id\":\"GR3e9g\",\"partition\":4,\"time\":07448}"
}
}
Now whenever the wiremock service receives an API call matching the urlPattern /v1/queue/*.
, I want to add custom logic for the wiremock service to make a call to DynamoDB table. Can I get some pointers on how to implement that. What changes do I make to this Dockerfile to accomodate the custom logic implementation?
FROM wiremock/wiremock:latest
COPY stubs /home/wiremock
EXPOSE 8080
Share
asked Feb 12 at 9:03
Sai KrishnaSai Krishna
6211 gold badge12 silver badges34 bronze badges
2
|
1 Answer
Reset to default 0Given you don't need the data from the DB query in the response for the stub I would probably look at building a ServeEventListener
. These listeners allow you to take an action at a specific point in the request processing flow, without affecting processing in any way. More information can be found here - https://wiremock./docs/extensibility/listening-for-serve-events/
You would then need to bundle the listener into a WireMock extension. To help with that we have a number of extensions you could copy from on the WireMock github anisation along with the WireMock extension template.
Once you have built your extension you can include it in your WireMock instance by copying it to the extensions
directory. I have a similar example in this repository - https://github/leeturner/wiremock-standalone-docker-example
The extension jar is placed in the extensions
directory here and the extensions directory is mapped to the same directory inside the container here.
Once all of that is in place, you add the ServeEventListener
to your stub. When you make a request that matches your stub, the ServeEventListener
is executed. An example of this is the webhook functionality in WireMock. This is implemented as a ServeEventListener
. The stub json looks something like this:
{
"request": {
"urlPath": "/something-async",
"method": "POST"
},
"response": {
"status": 200
},
"serveEventListeners": [
{
"name": "webhook",
"parameters": {
"method": "POST",
"url": "http://my-target-host/callback",
"headers": {
"Content-Type": "application/json"
},
"body": "{ \"result\": \"SUCCESS\" }"
}
}
]
}
Obviously you would replace the webhook
ServeEventListener
with your own (with its own name and parameters).
本文标签: dockerCustom Action for a wiremock stubStack Overflow
版权声明:本文标题:docker - Custom Action for a wiremock stub - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741613486a2388392.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
{\"id\":\"GR3e9g\",\"partition\":4,\"time\":07448}
and then make a call to the DB? – Lee Turner Commented Feb 12 at 9:27