Forum Discussion

lionelblak's avatar
lionelblak
Visitor
3 years ago

How to create REST headers in Groovy Script with the same name

Hi,

I have a Test suite which makes a Logon call to a web service via a load-balancer, followed by a series of subsequent calls. The web service response header to the Logon call contains three cookies, all of which must be included in the request headers of subsequent calls so that the load-balancer can direct the requests to the correct node.

 

The web service itself provides one response cookie and the load-balancer provides two response cookies. All cookies have the same header name: Set-Cookie.

I'm trying to set these in Groovy Script for subsequent calls but I'm finding that rather than create three headers, each entitled "Set-Cookie", my script is creating the first one and overwriting it with the subsequent ones. I'm ending up with just one header named Set-Cookie which contains the third cookie that is set, rather than three headers all named Set-Cookie with three different values in them.

 

Here is my Groovy script:

import com.eviware.soapui.support.types.StringToStringMap
def headers = new StringToStringMap()
def cookie_name0 = testRunner.testCase.testSteps["SessionLogon"].testRequest.response.responseHeaders["Set-Cookie"][0]
def cookie_name1 = testRunner.testCase.testSteps["SessionLogon"].testRequest.response.responseHeaders["Set-Cookie"][1]
def cookie_name2 = testRunner.testCase.testSteps["SessionLogon"].testRequest.response.responseHeaders["Set-Cookie"][2]
headers.put("Set-Cookie",cookie_name0)
headers.put("Set-Cookie",cookie_name1)
headers.put("Set-Cookie",cookie_name2)
testRunner.testCase.getTestStepByName("TransactionStart").testRequest.setRequestHeaders(headers)

 

Please could someone suggest what I'm doing wrong / how to overcome it?

 

Many thanks,

Lionel

No RepliesBe the first to reply