cancel
Showing results for 
Search instead for 
Did you mean: 

How to return binary data from a mock?

Highlighted
Frequent Contributor

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?)...

2 REPLIES 2
Highlighted
Community Hero

Re: Where are the javadocs for mockRequest, mockResponse, etc.?

Hey @mmoser18,


Does the final bit of the following page give you what you need?

https://www.soapui.org/docs/soap-mocking/mockoperations-and-responses/

Ta

Rich
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
Highlighted
Frequent Contributor

How to return binary data from a mock?

OK - I changed the title off my thread to better mirror my actual issue.

 

Your response *would* have answered my immediate question (how to put some data into the mock response payload), if that data were pure text.

 

However, in our case that content needs to be in a special character set (UTF-16LE) and thus the embedding of ${content} into the response converts the data wrongly, as these are then obviously converted into UTF-8 during the send-process. But our client doesn't understand UTF-8, only said UTF16LE.

 

So, my actual question is: given that I have the binary data (here an example response read from a file, but it could in principle be *any* binary data) in my hands - how do I get these exact bytes into the mock-response's payload unchanged? Is that at all possible with SOAP-UI?

New Here?
Join us and watch the welcome video:
Top Kudoed Authors