hi, I'm trying to return a dynamic response (`{{no...
# help
m
hi, I'm trying to return a dynamic response (
{{now}}
) using
docker
image not
jar
https://wiremock-community.slack.com/archives/C053Y3N34C8/p1695649886746049
o
Hello. WireMock Standalone and WireMock Java have the same behavior for configuration files
So it should not matter what you use
m
I thought there was extra config needed since steep #1 here is defining transformer Java class: https://myagilequality.wordpress.com/2018/01/16/dynamically-change-a-mocked-response-using-wiremock/
o
Didn't see a need in the custom transformer above. If you need it, it would need to be packaged as an extension and added to the standalone instance
But after that it's the same
m
so what is the issue? I also updated the image to use the latest, here is the implementation and response: stub:
Copy code
{
  "name": "dates-demo",
  "request": {
    "url": "/dates-demo",
    "method": "GET"
  },
  "response": {
    "status": 200,
    "transformers": [
      "response-template"
    ],
    "jsonBody": {
      "id": "{{randomInt}}",
      "name": "dates-demo",
      "creationDate": "{{now}}"
    }
  }
}
response:
Copy code
{
  "id": "{{randomInt}}",
  "name": "dates-demo",
  "creationDate": "{{now}}"
}
o
ATM I do not understand the issue. You asked how to do it, but there is no statement that something is broken or logs/versions 🙂
Note that WireMock 3 includes incompatible changes and the extension code might need an update
m
the issue is I expect
id
to be an actual random number e.g.: 1, 2, 3.. and the same for the
creationDate
to be something like:
023-09-26T09:42:44.727Z
not
{{randomInt}} {{now}}
l
It is very strange. This is what I see:
Copy code
{
  "id": "-1752793986",
  "name": "dates-demo",
  "creationDate": "2023-09-26T09:52:22Z"
}
Can you take a look at the logs and see Wiremock starting up? This is what I see:
Copy code
port:                         7777
enable-browser-proxying:      false
disable-banner:               false
no-request-journal:           false
verbose:                      true

extensions:                   response-template,webhook
m
Copy code
port:                         8080
enable-browser-proxying:      false
disable-banner:               false
no-request-journal:           false
verbose:                      false
I see verbose as the only difference and
extensions
as well
l
No extensions ?
m
No
here is the compose file I'm using:
Copy code
services:
  wiremock-server:
    image: wiremock/wiremock:latest
    ports:
      - 3030:8080
    volumes:
      - ./wiremock:/home/wiremock
l
Can you try adding the
--global-response-templating
in the
entrypoint
as shown at the bottom of this page - https://wiremock.org/docs/standalone/docker/
🙏 1
m
It works, without having
docker-entrypoint.sh
is that okay or I need to include?
anyway, thank you all @Lee Turner and @Oleg Nenashev for your time and support
l
I think that should be OK. Glad it works