hi guyss, how to print log on the `webhook` I alre...
# help
g
hi guyss, how to print log on the
webhook
I already put the
--verbose
on the docker run so it supposed to print all logs
Copy code
{
  "name": "webhook",
  "parameters": {
    "method": "POST",
    "url": "<https://censored.com/callback/eagle>",
    "headers": {
      "Content-Type": "application/json"
    },
    "body": "{ \"status_id\": 2, \"query_id\": {{state context='queryIdFdcC123834' property='queryIdFdc'}}, \"user_id\": {{jsonPath originalRequest.body '$.user_id'}}, \"bureau_type\": 2, \"data\": { \"name\": \"ORACLE TAX\"} }"
  }
}
but the log only the response of the request I want to print the
request body
and
headers
also how to achieve that? thankyuu guyss!
l
I am not sure there is a way to get extra logging from the webhook request. However, as of WireMock
3.7.0
, successful webhook requests and responses are logged as Sub Events in the request log. You get two events -
"type": "WEBHOOK_REQUEST"
and
"type": "WEBHOOK_RESPONSE"
https://wiremock.org/docs/webhooks-and-callbacks/#observing-webhook-events All you need to do is call the admin endpoint to retrieve the requests from the request log https://wiremock.org/docs/standalone/admin-api-reference/#tag/Requests/operation/getAllRequestsInJournal
g
i just updated the version into
3.7.0
but somehow it return error like this
Copy code
<html>

<head>
    <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1" />
    <title>Error 500 java.lang.NoSuchMethodError:
        &apos;com.github.tomakehurst.wiremock.extension.responsetemplating.RequestTemplateModel
        com.github.tomakehurst.wiremock.extension.responsetemplating.RequestTemplateModel.from(com.github.tomakehurst.wiremock.http.Request)&apos;
    </title>
</head>

<body>
    <h2>HTTP ERROR 500 java.lang.NoSuchMethodError:
        &apos;com.github.tomakehurst.wiremock.extension.responsetemplating.RequestTemplateModel
        com.github.tomakehurst.wiremock.extension.responsetemplating.RequestTemplateModel.from(com.github.tomakehurst.wiremock.http.Request)&apos;
    </h2>
    <table>
        <tr>
            <th>URI:</th>
            <td>/v1/reports/clik</td>
        </tr>
        <tr>
            <th>STATUS:</th>
            <td>500</td>
        </tr>
        <tr>
            <th>MESSAGE:</th>
            <td>java.lang.NoSuchMethodError:
                &apos;com.github.tomakehurst.wiremock.extension.responsetemplating.RequestTemplateModel
                com.github.tomakehurst.wiremock.extension.responsetemplating.RequestTemplateModel.from(com.github.tomakehurst.wiremock.http.Request)&apos;
            </td>
        </tr>
        <tr>
            <th>SERVLET:</th>
            <td>com.github.tomakehurst.wiremock.servlet.WireMockHandlerDispatchingServlet-62d0ac62</td>
        </tr>
        <tr>
            <th>CAUSED BY:</th>
            <td>java.lang.NoSuchMethodError:
                &apos;com.github.tomakehurst.wiremock.extension.responsetemplating.RequestTemplateModel
                com.github.tomakehurst.wiremock.extension.responsetemplating.RequestTemplateModel.from(com.github.tomakehurst.wiremock.http.Request)&apos;
            </td>
        </tr>
    </table>
    <h3>Caused by:</h3>
    <pre>java.lang.NoSuchMethodError: &apos;com.github.tomakehurst.wiremock.extension.responsetemplating.RequestTemplateModel com.github.tomakehurst.wiremock.extension.responsetemplating.RequestTemplateModel.from(com.github.tomakehurst.wiremock.http.Request)&apos;
	at org.wiremock.extensions.state.extensions.RecordStateEventListener.beforeResponseSent(RecordStateEventListener.java:56)
	at com.github.tomakehurst.wiremock.extension.ServeEventListener.onEvent(ServeEventListener.java:38)
	at com.github.tomakehurst.wiremock.extension.ServeEventListenerUtils.triggerListeners(ServeEventListenerUtils.java:42)
	at com.github.tomakehurst.wiremock.http.StubRequestHandler.beforeResponseSent(StubRequestHandler.java:89)
	at com.github.tomakehurst.wiremock.http.AbstractRequestHandler.handle(AbstractRequestHandler.java:97)
	at com.github.tomakehurst.wiremock.servlet.WireMockHandlerDispatchingServlet.service(WireMockHandlerDispatchingServlet.java:165)
	at wiremock.jakarta.servlet.http.HttpServlet.service(HttpServlet.java:587)
	at wiremock.org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:764)
	at wiremock.org.eclipse.jetty.servlet.ServletHandler$ChainEnd.doFilter(ServletHandler.java:1665)
	at wiremock.org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:527)
	at wiremock.org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:221)
	at wiremock.org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1381)
	at wiremock.org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:176)
	at wiremock.org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:484)
	at wiremock.org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:174)
	at wiremock.org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1303)
	at wiremock.org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:129)
	at wiremock.org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:122)
	at wiremock.org.eclipse.jetty.server.handler.gzip.GzipHandler.handle(GzipHandler.java:822)
	at wiremock.org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:141)
	at wiremock.org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:122)
	at wiremock.org.eclipse.jetty.server.Server.handle(Server.java:563)
	at wiremock.org.eclipse.jetty.server.HttpChannel$RequestDispatchable.dispatch(HttpChannel.java:1598)
	at wiremock.org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:753)
	at wiremock.org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:501)
	at wiremock.org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:287)
	at wiremock.org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:314)
	at wiremock.org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:100)
	at wiremock.org.eclipse.jetty.io.SelectableChannelEndPoint$1.run(SelectableChannelEndPoint.java:53)
	at wiremock.org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.runTask(AdaptiveExecutionStrategy.java:421)
	at wiremock.org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.consumeTask(AdaptiveExecutionStrategy.java:390)
	at wiremock.org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.tryProduce(AdaptiveExecutionStrategy.java:277)
	at wiremock.org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.produce(AdaptiveExecutionStrategy.java:193)
	at wiremock.org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:969)
	at wiremock.org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.doRunJob(QueuedThreadPool.java:1194)
	at wiremock.org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1149)
	at java.base/java.lang.Thread.run(Unknown Source)
</pre>

</body>

</html>
do you have any idea @Lee Turner? i tried to use
3.6.0
and it working fine
l
Sorry, when did you see that error? Were you calling the admin api or calling your stub?
g
calling my stub~
like this
but the log from wiremock itself is no issue
Copy code
mockingbird  | 2024-08-07 11:05:37.179 Request received:
mockingbird  | 192.168.65.1 - POST /v1/reports/clik
mockingbird  | 
mockingbird  | Content-Type: [application/json]
mockingbird  | User-Agent: [PostmanRuntime/7.40.0]
mockingbird  | Accept: [*/*]
mockingbird  | Postman-Token: [f8162510-c4c1-4af2-9ce6-1e5972ed42ca]
mockingbird  | Host: [localhost:4301]
mockingbird  | Accept-Encoding: [gzip, deflate, br]
mockingbird  | Connection: [keep-alive]
mockingbird  | Content-Length: [398]
mockingbird  | {
mockingbird  |     "user_id": 12345,
mockingbird  |     "name": "ORACLE TAX REXI VAGITA",
mockingbird  |     "gender": "L",
mockingbird  |     "address": " CEMPAKA PERMAI,  DEKAT MASJID",
mockingbird  |     "sub_district": "CEMPAKA PERMAI",
mockingbird  |     "district": "GADING CEMPAKA",
mockingbird  |     "city": "0191",
mockingbird  |     "postal_code": "38221",
mockingbird  |     "country": "ID",
mockingbird  |     "birth_date": "2001-01-16",
mockingbird  |     "identity_id": "1705141601010002",
mockingbird  |     "cellphone_number": "082175548936",
mockingbird  |     "retry": 1
mockingbird  | }
mockingbird  | 
mockingbird  | 
mockingbird  | Matched response definition:
mockingbird  | {
mockingbird  |   "status" : 200,
mockingbird  |   "body" : "{\n    \"data\": {\n        \"query_id\": 1234534596\n    },\n    \"success\": \"true\"\n}\n",
mockingbird  |   "bodyFileName" : "b2b/user/eagle/clik/response-clik.json",
mockingbird  |   "headers" : {
mockingbird  |     "Content-Type" : "application/json"
mockingbird  |   },
mockingbird  |   "transformers" : [ "response-template" ]
mockingbird  | }
mockingbird  | 
mockingbird  | Response:
mockingbird  | HTTP/1.1 200
mockingbird  | Content-Type: [application/json]
mockingbird  | Matched-Stub-Id: [7987a243-906e-455b-becc-fd000f029203]
l
Can you post your whole stub definition ?
Also, are those actually WireMock logs?
mockingbird
is a different http mocking solution ?
g
mockingbird is the name of the wiremock hahahaha
🤣 1
our team named it mockingbird~
here’s the mockingbird as a wiremock
here’s my full stub
Copy code
{
  "mappings": [
    {
      "scenarioName": "C123834 Clik Template",
      "request": {
        "method": "POST",
        "url": "/v1/reports/clik",
        "headers": {},
        "bodyPatterns": [
          {
            "matchesJsonPath": "$[?(@.name =~ /ORACLE TAX.*/)]"
          }
        ]
      },
      "response": {
        "status": 200,
        "bodyFileName": "b2b/user/eagle/clik/response-clik.json",
        "transformers": [
          "response-template"
        ],
        "headers": {
          "Content-Type": "application/json"
        }
      },
      "serveEventListeners": [
        {
          "name": "recordState",
          "parameters": {
            "context": "queryIdClikC123834",
            "state": {
              "queryId": "{{jsonPath response.body '$.data.query_id'}}"
            }
          }
        },
        {
          "name": "webhook",
          "parameters": {
            "method": "POST",
            "url": "<https://b2b.requestcatcher.com/callback/eagle>",
            "headers": {
              "Content-Type": "application/json"
            },
            "body": "{ \"user_id\": {{jsonPath originalRequest.body '$.user_id' }}, \"query_id\": {{ state context='queryIdClikC123834' property='queryId' }}, \"status_id\": 2, \"bureau_type\": 5, \"data\": { \"bad_credit_status\": 4, \"mothermaidenname\": \"{{ random 'id-ID.Name.firstName' }}\", \"placeofbirth\": \"{{ random 'id-ID.Address.cityName' }}\", \"postalcode\": \"40191\", \"basic_postalcode\": \"40191\", \"employername\": \"PT FINACCEL TEKNOLOGI INDONESIA\", \"employment\": \"004900\", \"fullname\": \"JOHANNES ADRIEL GUSINDRAPUTRA\", \"name\": \"JOHANNES ADRIEL GUSINDRAPUTRA\", \"addressline\": \"JL.SOSIOLOGI 15, 001/007, CIGADUNG, CIBEUNYING KALER, BANDUNG, JAWA BARAT\", \"address\": \"JL.SOSIOLOGI 15, 001/007, CIGADUNG, CIBEUNYING KALER, BANDUNG, JAWA BARAT\", \"contract_valid\": 1, \"bureau_max_pastduedays\": 0, \"bureau_count_late_active_loan\": 0, \"bureau_ever_written_off\": 0, \"bureau_ever_restructured\": 0, \"income_prediction\": 10000000 } }"
          }
        }
      ]
    }
  ]
}
l
Actually, looking at the stack trace it looks like the error is coming from the state extension:
Copy code
org.wiremock.extensions.state.extensions.RecordStateEventListener.beforeResponseSent
g
Copy code
{
    "data": {
        "query_id": {{jsonPath request.body '$.user_id'}}{{randomValue length=5 type='NUMERIC'}}
    },
    "success": "true"
}
here’s the response
l
Can you upgrade to the latests version of the extension and the latest version of WireMock ?
g
this is the latest one yes?
Copy code
3.9.1
l
Yes, that is the latest wiremock version. Not sure what the latest extension version is
g
oh it works after i upgrade the state extension
to 1.8.0
l
Good stuff
g
but the admin journal is empty how to enable it bro?
it was only received the log like this
Copy code
mockingbird  | 2024-08-07 11:27:58.335 Admin request received:
mockingbird  | 192.168.65.1 - GET /requests?limit=100&since=2016-10-05T12:33:01Z
mockingbird  | 
mockingbird  | User-Agent: [PostmanRuntime/7.40.0]
mockingbird  | Accept: [*/*]
mockingbird  | Postman-Token: [390a1764-404d-481c-bc32-211fc910993f]
mockingbird  | Host: [localhost:4301]
mockingbird  | Accept-Encoding: [gzip, deflate, br]
mockingbird  | Connection: [keep-alive]
mockingbird  |
l
From the screenshots you have posted it doesn't look like it is disabled. Unless you have specified the
--no-request-journal
startup parameter it should be enabled
g
yap i didnt provide
--no-request-journal
in startup parameter but somehow it’s empty….
l
And
localhost:4301
is definitely the server you sent the original request to?
g
yap in the docker I open the port 4301 for it
like this
l
Let me quickly try
g
oh brooo
i found something
got it
it solved
the request on the postman is having a
pre-request script
Copy code
var urlMock = pm.environment.get("url-mock-local")

pm.sendRequest({
    // url: urlMock+ '/__admin/mappings/reset', // Update URL if needed
    url: '<http://localhost:4301/__admin/mappings/reset>', // Update URL if needed
    method: 'POST'
})
so the logs is wiped out
thankyouu @Lee Turner!!
l
Excellent. Nice find!! Glad it is working
g
🙇