How to return binary data from a mock?
In a mock service I want to return a REST-response from a binary file. I got as far as reading the file and I have the bytes in my hand now (for brevity I left away the code that comes up with path using a custom property):
...
log.info("reading data from '${path}'")
def file = new File(path)
log.info("read data: " + file.bytes)
But how do I fill these bytes into the mock's response? NOWHERE did I find any info on the how to set the response's content or the methods on a mockResponse! I recall that these used to be online somewhere but I only found dozens of pages that "are taking a REST". 😞
I tried with
return file.bytes
mockResponse = file.bytes
mockResponse.setContent(file.bytes)
mockResponse.setData(file.bytes)
... but now I ran out of ideas. What's the magic incantation to assign the file's content to the mock service's response message body? It's annoying that seemingly so simple tasks can stop you in mid-flight (or should I say mid-flow?)...