How to output the HTTP response to a log file
This is another API I am working with.
I use the following to output the results to a log file.
def header = tStep.getTestRequest().response.responseHeaders
log.info " Seq="+i+" "+"="+data[1]+"|Result:"+header
report << "\n"+ sdf.format(log_date) + " Seq=" + i + " "+data[1]+" Result:"+header
The API response does not provide too much information. I can tell if it is working based on the HTTP status. How do I output only HTTP/1.1 XXX to the report file (XXX is the result of the API)?
Also, I noticed that every time I run the Groovy after certain time of inactivity, I would get the Set-Cookie portion as well in the response (not sure why).
Thanks.
HTTP/1.1 204
Set-Cookie: JSESSIONID=26EEF6753526AAD776AB09823B11598B; Path=/rem; Secure; HttpOnly
Date: Wed, 15 Sep 2021 14:56:35 GMT
Header= [Set-Cookie:[JSESSIONID=34C6105FD8CB3879790C36F253C70B45; Path=/rem; Secure; HttpOnly], #status#:[HTTP/1.1 204 ], Date:[Wed, 15 Sep 2021 14:59:27 GMT]]
HTTP/1.1 204
Date: Wed, 15 Sep 2021 14:54:55 GMT
Header= [#status#:[HTTP/1.1 204 ], Date:[Wed, 15 Sep 2021 15:00:47 GMT]]
HTTP/1.1 404
Set-Cookie: JSESSIONID=BBA3931D0CEA90EA0EBDCE444AF878FE; Path=/rem; Secure; HttpOnly
Content-Type: application/xml
Content-Length: 280
Date: Wed, 15 Sep 2021 14:31:00 GMT
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><error><type>EntityNotFound</type><message>Subscriber data could not be found for IMS user identity "sip:+14313140097@ims.mnc130.mcc302.3gppnetwork.org" and selection key "Metaswitch::::"</message></error>
Headerr= [#status#:[HTTP/1.1 404 ], Content-Length:[280], Date:[Wed, 15 Sep 2021 15:02:55 GMT], Content-Type:[application/xml]]
It is working now after some trial-and-errors.
I replaced the def statement by String statement and the lines below did remove the square brackets.
String MESSAGE_TAS = tStep.getTestRequest().response.responseHeaders.'#status#'
MESSAGE_TAS = MESSAGE_TAS.replaceAll("[\\[\\](){}]","") // remove square brackets
log.info " Seq="+i+" "+data[1]+",TAS-Put Result: "+MESSAGE_TASLog info= Fri Sep 17 11:10:18 EDT 2021:INFO: Seq=5 14313140097,TAS-Put Result: HTTP/1.1 204