wiremock / wiremock/wiremock.org

Issue on Response Templating

Open
#142 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
HTML
Stars
12
Forks
71
PR merge metrics
No merged PRs in 30d

Description

Page

/docs/response-templating/

Details

I am using gradle dependency: implementation 'com.github.tomakehurst:wiremock:2.27.2'

My JSON stub mapping is calling a POST URL using proxyBaseUrl and sending the response to transformers (I am writing my own transformer class by extending ResponseTransformer to dynamically change the response based on the response from proxy URL).
JSON Stub:
image

Issue:

  1. I can see the response from proxyBaseUrl as HTTP 200, but when I try printing the body using response.getBodyAsString(), it returns a string in unreadable format.
    200 response: image

response.getBodyAsString():

image

How can I read this response in readable format (preferably json), to change the response dynamically using transformer functionality.

  1. response.getBody() method returns a byte array.

response.getBody():
image

Tried decoding the byte array returned using all StandardCharsets and
new String(response.getBody(), response.getHeaders().getContentTypeHeader().charset());

image

How can I convert this byte array in a readable format. Thank you in anticipation of a solution.

Suggested Edits

No response

References

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at /docs/response-templating/ and review the ResponseTransformer guidance alongside the WireMock 2.27.2 behavior described. Clarify the documented handling of proxied response bytes, charset, and JSON conversion, then verify the page answers both getBodyAsString() and getBody() questions.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.