https://linen.dev logo
#help
Title
# help
m

Muhammed Moussa

09/26/2023, 8:36 AM
hi, I'm trying to return a dynamic response (
{{now}}
) using
docker
image not
jar
https://wiremock-community.slack.com/archives/C053Y3N34C8/p1695649886746049
o

Oleg Nenashev

09/26/2023, 9:04 AM
Hello. WireMock Standalone and WireMock Java have the same behavior for configuration files
So it should not matter what you use
m

Muhammed Moussa

09/26/2023, 9:28 AM
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

Oleg Nenashev

09/26/2023, 9:32 AM
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

Muhammed Moussa

09/26/2023, 9:36 AM
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

Oleg Nenashev

09/26/2023, 9:39 AM
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

Muhammed Moussa

09/26/2023, 9:43 AM
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

Lee Turner

09/26/2023, 9:52 AM
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

Muhammed Moussa

09/26/2023, 9:56 AM
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

Lee Turner

09/26/2023, 9:57 AM
No extensions ?
m

Muhammed Moussa

09/26/2023, 9:57 AM
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

Lee Turner

09/26/2023, 10:01 AM
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

Muhammed Moussa

09/26/2023, 10:18 AM
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

Lee Turner

09/26/2023, 10:26 AM
I think that should be OK. Glad it works