Capture response time in wiremock recordings

  1. Capture timestamp when the response has been received by wiremock, from the backend system.
  2. Register the difference as delay in wiremock stubs.

1. Capture timestamp when the request has been received by wiremock. Wiremock provides a RequestFilter to intercept incoming requests.

The CustomRequestFilter below intercepts the request and records the timestamp as a request header. This header will be used in further steps.

2. Capture timestamp when the response has been received by wiremock from the backend system.

After the response is received, wiremock runs ResponseTransformers on it. This CustomResponseTransformer below determines when the response was received. It then retrieves the start timestamp from the header added in Step 1. Then the transformer calculates the response time or delay and adds it as a header in the response.

3. Record the difference as delay in wiremock stubs.

Wiremock invokes StubMappingTransformer extensions, to modify StubMappings before they are saved. The CustomStubMappingTransformer below retrieves the delay from the response header added in Step 2. It then modifies the StubMapping to add the delay. The new StubMapping now has our desired request, response and also response time as a delay.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Anurag Ashok

Anurag Ashok

building software @ Singapore Airlines | making code work for 8+ years | passionate about automation and “everything as code”.