Buschfunk
16 years agoFrequent Contributor
How to use property "Encode Attachments" correctly?
Hello,
I have set up a webservice mock which sends responses with dynamic content read from a database. Some of the response nodes shall contain base64-encoded binary data, e.g. images.
For debugging purposes, I use the following statement which works fine. It shows the base64 representation of the image.
If, however, I use the SQL result as a context property for further usage in the response it is not handled correctly, i.e. instead of its base64 representation only a string like [B@156... is used.
The property "Encode attachments" is set to true.
In the Groovy script:
In the response:
I have set up a webservice mock which sends responses with dynamic content read from a database. Some of the response nodes shall contain base64-encoded binary data, e.g. images.
For debugging purposes, I use the following statement which works fine. It shows the base64 representation of the image.
log.info(sqlResult['IMAGE'].encodeBase64())
If, however, I use the SQL result as a context property for further usage in the response it is not handled correctly, i.e. instead of its base64 representation only a string like [B@156... is used.
The property "Encode attachments" is set to true.
In the Groovy script:
context.image = sqlResult['IMAGE']
In the response:
${image}
But the problem is the following: All node values of the mock response are taken from a database. As this list of parameters is pretty long, I'm using an each-statement to iterate through the parameters. And as this list is dynamical, I can't tell in advance if a parameter is a binary (which needs to be base64 encoded) or if it is just a regular string.