How to set a custom HTTP header property to TestObjectProperty

I have two web service request - POST request which is returning a custom attribute and this custom attribute (SessionToken - X) needs to be set as a HTTP Header in my GET request.

Code Snippet:-

RequestObject persondetails_API = findTestObject(‘CBA_Person_API_PostMan/PersonDetails_API’)

ArrayList HTTPHeader_personAPI_authToken = new ArrayList()

// This seems to be working fine since Authorization is a defined HTTP header.

HTTPHeader_personAPI_authToken.add(new TestObjectProperty(‘Authorization’, ConditionType.EQUALS,GlobalVariable.finalAuthToken ))


ArrayList HTTPHeader_personAPI_sessionToken = new ArrayList()

// This is not getting added

HTTPHeader_personAPI_sessionToken.add(new TestObjectProperty(‘SessionToken - X’,ConditionType.EQUALS,GlobalVariable.sessionToken ))


def personAPI_response = WS.sendRequest(persondetails_API)


WS.verifyResponseStatusCode(personAPI_response, 200)

Result :- Getting 401. I executed the same code in POSTMAN and there it was returning 200. Can you please suggest if we need to set this Custom property which is not defined for the HTTP header for GET request.

Thanks !

One correction in Result section : I’m getting 500 error now

How long should lase that SessionToken - X ?
if it’s at least few minutes can you try manually setup definition in OR and run it to see if it works?

Hi Andrej ,

It works while I’m doing it manually. The session lasts for 1 minute. Looks like a code issue. Any suggestions ?

One more thing to add here I printed the HeaderFields() and there asg-sessiontoken is not getting picked. Please find the Headers of the response when executed via code

Access-Control-Expose-Headers:[ASG-SessionToken, X-UMV],
Server:[Apache PivotalWebServer],
Access-Control-Allow-Methods:[POST, GET, OPTIONS, DELETE, PUT],
Access-Control-Allow-Headers:[x-requested-with, Content-Type, origin, authorization, accept, client-security-token, ASG-SessionToken, X-FORWARDED-FOR, Device-UUID, Device-Model, SIM-Info, X-UMV],
Date:[Wed, 10 Oct 2018 05:09:47 GMT],

While running from OR manually I’m getting following headers

Keep-Alive: timeout=5, max=1000
HTTP/1.1 200 OK
Server: Apache PivotalWebServer
Access-Control-Allow-Origin: *
ASG-SessionToken: Yg/twRlHyFWhuc8ojeW90C+NvFlhEsAz4mv/ibYljvP1W0umWq6PpM6F31jL8/sFbw5jTRcNctPgMK0kBSTpMdmqdlcVA9t7XG3lOjfpByk0sNanprGXZmXvZMLFrW7iC8eFVSnSimD46Ul6W43rwTYUk6WSI/s00zNTc0GUX1y9fOWnvo8cKIAXYETUDKfYmiWgb5AolzrDCQw/KVa6Ep+KrtUk9Gcjskhff28HUL5hrkHGA+Cu19kaNLq6C/9HRbd/UitlohKxM4xLFHWi1tzcFVOBFJczBcQusVPdYfQisPtHGAq7Ip
Access-Control-Allow-Methods: POST, GET, OPTIONS, DELETE, PUT
Connection: Keep-Alive
Access-Control-Allow-Headers: x-requested-with, Content-Type, origin, authorization, accept, client-security-token, ASG-SessionToken, X-FORWARDED-FOR, Device-UUID, Device-Model, SIM-Info, X-UMV
Date: Wed, 10 Oct 2018 09:51:21 GMT
Access-Control-Expose-Headers: ASG-SessionToken, X-UMV
Access-Control-Max-Age: -1
Content-Length: 15
Content-Language: en-US
Content-Type: application/json
X-Powered-By: Servlet/3.0

Sorry for the long format

honestly, i’m running out of ideas…

Closing this as I found the issue in code.

Andrej Podhajský said:

honestly, i’m running out of ideas…

Thanks Andrej for your efforts.

please post your findings so other can find solution in case of similar problem

accepts list type of TestObjectProperty and I was creating two list for to add two header property ,instead of using only one list to enter both the property. A very basic mistake :s

Corrected code:-

ArrayList HTTPHeader_personAPI = new ArrayList()
HTTPHeader_personAPI.add(new TestObjectProperty(‘Authorization’, ConditionType.EQUALS,GlobalVariable.finalAuthToken ))
HTTPHeader_personAPI.add(new TestObjectProperty(‘ASG-SessionToken’,ConditionType.EQUALS,GlobalVariable.sessionToken))

1 Like

Check this code:

‘Create new array for headers’
ArrayList HTTPHeader = new ArrayList()

‘Add Content-Type header details’
HTTPHeader.add(new TestObjectProperty(‘Content-Type’, ConditionType.EQUALS, ‘application/json’))

‘Add Authorization:type header details’
HTTPHeader.add(new TestObjectProperty(‘Authorization:type’, ConditionType.EQUALS, ‘OAuth 1.0’))

‘Add Authorization header details using access token previous obtained’
HTTPHeader.add(new TestObjectProperty(‘Authorization’, ConditionType.EQUALS, 'bearer ’ + authToken))

‘Set new headers’