Forum Discussion
>on bottom of response editor expand the headers tab and enter:
I have a similar error and I cannot locate this feature to expand the headers tab.
This mocking feature works simply for my project using old-fashioned SOAP XML web services, but this REST stuff seems more complicated.
==
SoapUI-5.2.1 Community/free edition
Hi,
So you just want to set the content type to application/json for a REST mock response? - Did the drop down not work for you:
If you need to set a REST mock reponse's content type dynamically, then I have done it with script like:
def headers = mockResponse.responseHeaders headers["Content-Type"]=["application/json"] mockResponse.responseHeaders=headers
Where the mockResponse variable is available in the response's script tab.
The last time I did this was with version 5.0, but I think this functionality has been there a while.
Regards,
Rupert
- vikititor5 years agoContributor
When you need create the file on run-time.. using attachement is quite impossible. Then you need script.
I just did this simple response script. It will read your file. Just replace file name with your preference. It works with all file format. (or with formats, which I tested )..
// get the path to the folder where your project resides. def projectPath = new File(context.mockService.project.path).parent // Specify the file path that is relative to the project’s path. def fileName = projectPath + "\\response\\CABIS-MOCK_NIST1.tdf" log.info "CABIS-MOCK send response with file: " + fileName import java.io.FileInputStream import java.io.File File f = new File(fileName) FileInputStream fis = new FileInputStream(f) byte[] b = new byte[f.length()] //log.info javax.xml.bind.DatatypeConverter.printHexBinary(b) //returns a hex string //requestContext.mockResponse.responseContent = javax.xml.bind.DatatypeConverter.printHexBinary(b) //log.info f.text requestContext.mockResponse.responseContent = f.text
Related Content
Recent Discussions
- 22 hours agoruchisingh