Oliver Jankowski
04/14/2025, 7:28 AM"serveEventListeners": [
{
"name": "recordState",
"parameters": {
"context": "{{response.headers.DocumentId}}",
"state": {
"blob": "{{{request.bodyAsBase64}}}"
}
}
}
]
Now I want to download the same data, but I can't use base64Body (see below), because base64Body doesn't support templating and I only can enter real base64 data there.
"response": {
"status": 200,
"base64Body": "{{state context=(state context=request.path.documentId property='contentLocationUri') property='blob'}}",
"headers": {
"Content-Type": "application/octet-stream",
"D3-Filename": "{{state context=request.path.documentId property='filename'}}"
}
}
Neither Base64 decoding works, because it produces illegal chars.
"response": {
"status": 200,
"body": "{{#base64 decode=true}}{{state context=(state context=request.path.documentId property='contentLocationUri') property='blob'}}{{/base64}}",
"headers": {
"Content-Type": "application/pdf",
"D3-Filename": "{{state context=request.path.documentId property='filename'}}"
}
}
Can someone please help me?
Thanks in advance
OliverDirk Bolte
04/14/2025, 4:42 PMDirk Bolte
04/14/2025, 5:25 PM"serveEventListeners": [
{
"name": "recordState",
"parameters": {
"context": "{{response.headers.DocumentId}}",
"state": {
"blob": "{{request.body}}"
}
}
}
]
"response": {
"status": 200,
"body": "{{state context=(state context=request.path.documentId property='contentLocationUri') property='blob'}}",
"headers": {
"Content-Type": "application/octet-stream",
"D3-Filename": "{{state context=request.path.documentId property='filename'}}"
}
}
Oliver Jankowski
04/15/2025, 7:54 AMDirk Bolte
04/15/2025, 8:01 AMbodyAsBase64
to body
as well? (that resulted in a growth in my case) . Otherwise if you have a chance to push a small repro somewhere in github? Would help me to find differences to my setup.Oliver Jankowski
04/15/2025, 10:04 AMDirk Bolte
04/15/2025, 10:53 AMOliver Jankowski
04/15/2025, 12:23 PMDirk Bolte
04/16/2025, 9:13 AMDirk Bolte
04/16/2025, 10:08 AM{
"request": {
"method": "GET",
"urlPathTemplate": "/download"
},
"response": {
"status": 200,
"body": "{{# base64 decode=true}}JVBERi0xLjMKJcTl8uXrp/Og0MTGCjMg{{/ base64}}",
"headers": {
"Content-Type": "application/pdf"
}
}
}
When encoding the reponse to base64 again, I get: JVBERi0xLjMKJe+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/vQozIA==
.
A rough guess would be that com.github.tomakehurst.wiremock.extension.responsetemplating.helpers.Base64Helper
converts the result to String
which results in the conversion issues for non-printable characters.
Can you check whether my assessment is somewhat sensible? I wonder whether a fix would be remove the String creation and simply returning the byte array but I'm not sure about the full impact of it.Lee Turner
04/16/2025, 11:45 AMLee Turner
04/17/2025, 2:58 PMpublic class Base64Helper implements Helper<Object> {
@Override
public Object apply(Object context, Options options) throws IOException {
String value =
options.tagType == TagType.SECTION ? options.fn(context).toString() : context.toString();
if (Boolean.TRUE.equals(options.hash.get("decode"))) {
return new String(decodeBase64(value));
}
Object paddingOption = options.hash.get("padding");
boolean padding = paddingOption == null || Boolean.TRUE.equals(paddingOption);
return encodeBase64(value.getBytes(), padding);
}
}
Lee Turner
04/17/2025, 3:28 PMOliver Jankowski
05/05/2025, 8:50 PMOliver Jankowski
05/05/2025, 8:50 PM