Hi everyone, am trying to create a mock for applic...
# help
h
Hi everyone, am trying to create a mock for application/xml request. I need to initiate callback on request. Also, need to copy the parameters from original request to callback request. what handlers do I need to use?. am using a wiremock-standalone-3.13.1.jar version of wiremock. #C03N1E6HFPY
Have installed it on Linux machine.
t
Response templating is enabled by default for the URL, request headers and request body in webhooks and the original request is provided in the model. Documented here: https://wiremock.org/docs/webhooks-and-callbacks/#using-data-from-the-original-request
h
Thanks for the response, but the examples are for json. what I am looking for is to figure how to echo back a data in callback ath is received in originalrequest using XML.
t
It’s a text template so you can write XML instead of JSON. If you want to pull XML values out of the request you can do e.g.
{{xPath originalRequest.body '//something/text()'}}
h
Hey that was a quick response and thanks.. I am now able to get xPath added to my template. my Request is: <upi:ReqListAccount xmlns:upi="http://npci.org/upi/schema/"> <Head ver="2.0" ts="" orgId="" msgId=""/> <Txn id="1234567" note="" refId="" refUrl="" ts="" type="ListAccount" /> am trying to template it as.. "serveEventListeners": [ { "name": "webhook", "parameters": { "method": "POST", "url": "http://10.140.138.12:8081/upi/RespListAccount/2.0", "body": "<upi:RespListAccount xmlns:upi=\"http://npci.org/upi/schema/\">\n <Head ver=\"*{{xPath originalRequest.body '/upi:ReqListAccount/Head/ver()*'}}\" ts=\"\" orgId=\"\" msgId=\"\"/>\n <Txn id=\"123456\" note=\"\" refId=\"123456\" refUrl=\"\" ts=\"\" type=\"ListAccount\"/>\n <Resp reqMsgId=\"\" result=\"SUCCESS\" errCode=\"\"/>\n <AccountList>\n <Account accType=\"SAVINGS\" mbeba=\"\" accRefNumber=\"\" maskedAccnumber=\"\" ifsc=\"HDFC0000101\" mmid=\"9056014\" name=\"\" aeba=\"Y\" aadhaarNo=\"1234 5678 9012\">\n <CredsAllowed type=\"PIN\" subType=\"ATMPIN\" dType=\"\" dLength=\"\"/>\n </Account>\n <Account accType=\"SAVINGS\" mbeba=\"\" accRefNumber=\"\" maskedAccnumber=\"\" ifsc=\"HDFC0000103\" mmid=\"9056114\" name=\"\" aeba=\"N\">\n <CredsAllowed type=\"PIN\" subType=\"MPIN\" dType=\"\" dLength=\"\"/>\n </Account>\n </AccountList>\n</upi:RespListAccount>", "headers": { "Content-Type": "application/xml" }, "delay": { "type": "fixed", "milliseconds": 3000 }, "transformRequestBody": true, "transformers": ["response-template"] } am getting an error saying <Head ver="[ERROR: /upi:ReqListAccount/Head/ver() is not a valid XPath expression]"
t
Try it without the namespace
h
Am using.. "{{xPath originalRequest.body '/ReqListAccount/Head/ver() Getting this error post removal of namespace.. 2025-07-23 205215.897 [ERROR: /ReqListAccount/Head/ver() is not a valid XPath expression] com.github.tomakehurst.wiremock.common.xml.XPathException: { "errors" : [ { "code" : 51, "title" : "javax.xml.transform.TransformerException: Unknown nodetype: ver" } ] }
t
I’m not familiar with
ver()
- are you sure it’s a valid XPath funciton?
You probably want
/ReqListAccount/Head/ver/text()
h
it worked, thanks for your support.. !! {{xPath originalRequest.body '/ReqListAccount/Head/@ver'}} 🙏
👍 1