user3447
user3447

Reputation: 478

Groovy to capture response headers in Structure other than Map

I am trying to capture web service response via Groovy client, I have to check for duplicate header keys in response. I am capturing response headers using messageExchage.responseHeaders(), but since it returns map, It gives me each key only once, even though it is present twice in a response. is there a way to get this in Array or some other data structure ?

Upvotes: 0

Views: 2857

Answers (2)

Martin Spamer
Martin Spamer

Reputation: 5585

rawResponseAsString = new String( messageExchange.getRawResponseData())
log.info rawResponseAsString

Upvotes: 1

ataylor
ataylor

Reputation: 66109

How are you accessing the web service? If you use the groovy HttpBuilder, you can iterate through the headers, duplicates keys included:

new HTTPBuilder('http://webservice/').with {
    request(Method.GET) {
        uri.path = '/'
        response.success = { resp ->
            assert resp.status == 200
            resp.headers.each {
                println "${it.name}: ${it.value}"
            }
        }
    }
}

Upvotes: 3

Related Questions