timjohnarm
8 years agoOccasional Contributor
How to use Groovy to set Status, Content-Length, Content-Type in the HTTP Response for a MockService
I promise I have genuinely tried and failed to find an answer both here and over on StackOverflow. I've seen a number of variants on my question but nothing where the answer is as simple as mockRespo...
- 8 years ago
You can set an HTTP header by the code:
mockRequest.httpResponse.setHeader('MyHeader', "HiThere;")
Similarly you can set the Content-Length:
mockRequest.httpResponse.setContentLength(456)
BUT: further processing overrides your settings, e.g. the Content-Length with be the actual length of the response content.
I assume you need to break standard mock processing and return the response by your own, e.g. as with this code in the OnRequest script:
mockRequest.httpResponse.sendError(404)
There is a conflict between our code and the standard mock processing (which normally has to do the settings). I am not aware yet, hot to tell SoapUI that it shall not override my values.