Hi <@U0592TMJU4V> <@U04NTGJ6Z1D> - Thank you for y...
# help
j
Hi @Lee Turner @Oleg Nenashev - Thank you for your help so far. I am able to achieve a response (as a XML file) from the request (based on BodyPattern). Next, I want to have a delay for a few seconds and want to send the new response (XML file) to another different URL. Need help with this, please?
l
Hi, I think you need to look at setting up callbacks - https://wiremock.org/docs/webhooks-and-callbacks/
j
Thank you so much. I will give it a try
{ "request": { "method": "GET", "url": "/send-file", "bodyPatterns": [ { "matchesXPath": "//SearchCriteria[City/text() = \"Boston\" or Countrycode/text() =\"US\"]" } ] }, "response": { "status": 200, "headers": { "Content-Type": "text/xml;charset=UTF-8" }, "body": "<Abody>" } }, "serveEventListeners": [ { "name": "webhook", "parameters": { "method": "POST", "url": "http://my-target-host/callback", "headers": { "Content-Type": "application/json" }, "bodyPattern": "{ \"result\": \"SUCCESS\" }", "delay": { "type": "fixed", "milliseconds": 1000 } } } ] } In the above code for "request" I have a body for the GET Method in Postman. Now to implement serveEventListeners, I want to send xml file to "http://my-target-host/callback". Question: since postman already have body for the GET Request. Where will I keep the body for "serveEventListeners"? and can I use bodypattern instead of body (i changed in the above code) for serveEventListeners.
l
Hi, I don’t think the webhooks extension supports
bodyPattern
. I think you have to use the
body
element and include all your xml in there.
j
Thanks for the reply Lee. Do you have a sample for my case when I have a BodyPattern for the GET request and Body for serveEventListeners. What I mean is how to keep 2 body (one for Request and the other for serveEventListeners) in the postman and how to use Body (sample format) for serveEventListeners.
l
The below mapping works for me. You will need to replace the webhook url with the url of your callback service.
Copy code
{
  "request": {
    "method": "GET",
    "url": "/send-file",
    "bodyPatterns": [
      {
        "matchesXPath": "//SearchCriteria[City/text() = \"Boston\" or Countrycode/text() =\"US\"]"
      }
    ]
  },
  "response": {
    "status": 200,
    "headers": {
      "Content-Type": "text/xml;charset=UTF-8"
    },
    "body": "<Abody>"
  },
  "serveEventListeners": [
    {
      "name": "webhook",
      "parameters": {
        "method": "POST",
        "url": "<http://host.docker.internal:7070/callback-logger/api/callback>",
        "headers": {
          "Content-Type": "application/xml"
        },
        "body": "<callback><payload>Foo</payload></callback>",
        "delay": {
          "type": "fixed",
          "milliseconds": 1000
        }
      }
    }
  ]
}
You won’t see the callback payload in postman because that payload will be sent to the url you specify in the webhooks config
j
Thanks for the help Lee. I will try this option.