Contributions
Re: How to use Groovy to set Status, Content-Length, Content-Type in the HTTP Response for a MockService
Ok so with a lot of help fromKarelHusaI now have two solutions to gettinga zero length response with a status code of 202 from a MockService/MockResponse for a SOAP operation using a MEP(MessageExchangePattern) of OneWay. Solution#1 The simpler of the two involves the following, and came for Karel's last answer about Content-Encoding. On the Request add a Header with Accept-Encoding=identity. If you are using a SoapUI Request to do your initial testing then click on the Headers button/tab at the bottom of the window under the Request text and add a customer header Name=Accept-Encoding Value=identity. Then switch to your MockResponse andin the Navigator view on the left of the screen in the MockResponse Properties tab set Property=Response HTTP-Status Value=202 Solution#2 This is my final version of the script which I've been building on with Karel's help. It gives a greater level of flexibility especially if you have a difficult application as the final consumer of your MockService. log.info "Response Status=202 Content-Length=0" // Get a reference to the request headers and log them def rqHeaders = mockRequest.requestHeaders for ( rqEntry in rqHeaders ) { log.info "Request Header ${rqEntry.key} = ${rqEntry.value}" } // Get rid of the Accept-Encoding value as this causes SoapUI to automatically // add a corresponding Content-Encoding entry to the Response rqHeaders.remove("Accept-Encoding"); // Get a reference to the response headers def rsHeaders = mockResponse.responseHeaders // Add the desired header values to the response rsHeaders["Content-Length"] = ["0"] rsHeaders["Content-Type"] = ["text/xml"] // And log them for ( rsEntry in rsHeaders ) { log.info "Response Header ${rsEntry.key} = ${rsEntry.value}" } // And last but not least set the status code to 202 and zero length response mockResponse.setResponseHttpStatus(202) mockResponse.setResponseContent("")2.4KViews2likes0CommentsRe: How to use Groovy to set Status, Content-Length, Content-Type in the HTTP Response for a MockService
Ok so I've using the following DISPATCH script and can't work out why in the Headers I receive in the response have a Content-Length=20 log.info "DISPATCH script" def resp = mockOperation.getMockResponseByName('Wpdreb01Response') resp.setResponseHttpStatus(202) resp.setResponseContent("") return 'Wpdreb01Response' Content-Length 20 #status# HTTP/1.1 202 Accepted Content-Encoding gzip Content-Type text/xml; charset=utf-8 Server Jetty(6.1.26)8KViews0likes2CommentsRe: How to use Groovy to set Status, Content-Length, Content-Type in the HTTP Response for a MockService
Hello Karel thanks for your response. The missing piece was the httpResponse in the middle. The MockResponse class has its own methods mockResponse.responseHttpStatus mockResponse.setResponseHeaders But using httpResponse is easier and at least for me clearer.8.1KViews0likes0CommentsHow 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 mockResponse.setHeader(Content-Length, 0) So I want to set various HTTP Response header fields in the Script of my MockService Response script. The dialog tells me that I've got a number of variables available to me including log, mockRequest, mockResponse. I've worked out the simple HelloWorld equivalent log.info "Hello from my script" I made a guess that for log that the methods would be info, warn etc. But how do I use mockResponse to set some HTTP Header's in particular as mentioned in the question Content-Length and Status. I tried to find a reference for the methods but failed.Solved8.6KViews0likes10Comments