Forum Discussion
However I am not able to edit the response content type as it gets set automatically depending on the file type i am sending. If the file type that i am reading the content happens to be a .txt file, the content type gets set as text/plain, if the file happens to be a .xml, the content type gets set as text/xml.
I want to set a Json object in the response dynamically in the Mock REST response and the content type should be application/json as the client code is expecting this type.
I am not able to locate the header part in response editor of mock service either. Did you refer to response editor inside the Request editor?
- jamescollett9 years agoContributor
>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
- rupert_anderson9 years agoValued Contributor
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
- vikititor6 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
- 6 years ago
Recent Discussions
- 3 days ago