https://linen.dev logo
#general
Title
# general
v

Victor Baulac

12/01/2023, 10:20 AM
For readability I start another thread. Is there incompatibility between
"Content-Type": "image/png"
and
"transformers": ["response-template"]
? I am returning an image, like that
"bodyFileName": "goldens/C0402.png",
and it works well, untill I complexify it a little bit with
"transformers": ["response-template"],
(leaving the bodyFileName hardcoded just to test), I endup with some gibberish..
Exception: <http://wiremock.com|wiremock.com>.github.jknack.handlebars.HandlebarsException: inline@782f54bb:1:3: found: '?' {{{?????I????Q??i???*????k?0??6?Ax3;?$4?^A??3?	?
1
Would it help if I enable templating globaly instead of with the transformers ? I'll try that
FYI using global templating instead of the transformers does the same issue...
Looks like a bug to me. Hopefully I'll find a workaround
@Tom what do you think ? 😕
t

Tom

12/01/2023, 11:28 AM
No idea what’s going on there. Presume you’re on the latest version?
v

Victor Baulac

12/01/2023, 11:29 AM
3.3.1
My whole json :
{
"request": {
"method": "GET",
"urlPathPattern": "/myprolink/adc/golden/.*"
},
"response": {
"status": 200,
"bodyFileName": "goldens/C0402.png",
"transformers": ["response-template"],
"headers": {
"Content-Type": "image/png"
}
}
}
obviously we need the file in the correct place for it to fail like above, otherwise we have a clean
HTTP ERROR 500 java.io.FileNotFoundException: /home/wiremock/./__files/goldens/C0402.png (No such file or directory)
Do you need me to enter an issue on a github or something ?
t

Tom

12/01/2023, 11:32 AM
If you could share full info to reproduce this, that would help
I may not be able to look for a little while as I’m fully tied up today and at a conference all next week, but if I have something I can run and see it fail I might be able to take a look while I’m on the train.
v

Victor Baulac

12/01/2023, 11:34 AM
I'll give you all that soon 😉
👍 1
So basicaly, run WireMock in standalone docker as the documentation state :
docker run -it --rm -p 8080:8080 --name wiremock -v #YOURLOCALFOLDER#:/home/wiremock wiremock/wiremock:3.3.1
In your mapping directory, use this simple JSON (also attached)
{
"request": {
"method": "GET",
"urlPathPattern": "/my/path/ok"
},
"response": {
"status": 200,
"bodyFileName": "C0603.png",
"transformers": ["response-template"],
"headers": {
"Content-Type": "image/png"
}
}
}
And the image must be in your __files folder, but I'm sure you know that. Try to access localhost:8080/my/path/ok --> very weird exception. Remove the transformers from the JSON, try to access the same path (after reload of docker of course) --> image is displayed
C0603.png,get-golden.json
note : it happens with all the png's I tried. But for some, it is a browser error, saying the image has error (which do not happen if I remove the transformers)
Note : I found a workaround by encoding in base64 then decoding from base64. But my consumer have to adapt to the mock and this is very ugly.
t

Tom

12/04/2023, 9:32 AM
I missed the obvious problem here - you’re trying to use templating on binary content, which doesn’t make sense to attempt. You can either disable response templating completely for this stub or set
"disableBodyFileTemplating": true
as a transformer parameter on the stub, which will just prevent templating on the body file itself.
v

Victor Baulac

12/04/2023, 9:39 AM
😍
thx you ! 5-star support again
5 Views