Forum Discussion

MartinSpamer's avatar
MartinSpamer
Frequent Contributor
12 years ago
Solved

Response Headers error

If you retrieve HTTP response headers by name they are incorrectly enclosed in square brackets even though they are strings not lists/arrays.

e.g.


log.info messageExchange.responseHeaders["Server"]
log.info messageExchange.getResponseHeaders().get( "Server" )


Produces
[Apache-Coyote/1.1]
When it should produce
Apache-Coyote/1.1
  • That is because, type is ArrayList ([] denotes a list), not String.

     

    Since it has one element in the list, 0th one should match.

     

    Below should work:

    assert messageExchange.responseHeaders["Content-Type"][0] == 'image/jpeg'

     

4 Replies

  • wjb's avatar
    wjb
    New Contributor

    I am seeing this too and can't get SoapUI to pass a test for given header for a given string value:

     

    Script Input:

    log.info "messageExchange.responseHeaders(Content-Type)="
    log.info messageExchange.responseHeaders["Content-Type"]


    log.info "messageExchange.getResponseHeaders().get(Content-Type)="
    log.info messageExchange.getResponseHeaders().get("Content-Type")


    assert messageExchange.responseHeaders["Content-Type"].equals("[image/jpeg]")

     

    Output shows the brackets using either method:

    • Mon Dec 21 14:22:16 MST 2015:INFO:messageExchange.responseHeaders(Content-Type)=
    • Mon Dec 21 14:22:16 MST 2015:INFO:[image/jpeg]
    • Mon Dec 21 14:22:16 MST 2015:INFO:messageExchange.getResponseHeaders().get(Content-Type)=
    • Mon Dec 21 14:22:16 MST 2015:INFO:[image/jpeg]

    The assert fails with this message:

     

    assert messageExchange.responseHeaders["Content-Type"].equals("[image/jpeg]") | | | | | | [image/jpeg] false | [X-ORCHESTRATE-REQ-ID:[f9a4ddb0-a811-11e5-b81b-000c29cce2b5], Orchestrate-Destination-Host:[api.ctl-uc1-a.orchestrate.io], ETag:["2219eba0b33107f398c81e8808e2f5a2e6212a4e-gzip"], Vary:[Accept-Encoding], Transfer-Encoding:[chunked], Date:[Mon, 21 Dec 2015 18:38:06 GMT], #status#:[HTTP/1.1 200 OK], Last-Modified:[Mon, 21 Dec 2015 18:36:48 GMT], Content-Encoding:[gzip], Content-Location:[/v0/media/keyHagar/refs/2219eba0b33107f398c81e8808e2f5a2e6212a4e], Orchestrate-Source-Host:[api.ctl-va1-a.orchestrate.io], Connection:[keep-alive], Content-Type:[image/jpeg], Server:[nginx]] com.eviware.soapui.impl.wsdl.teststeps.RestResponseMessageExchange@75b8d2ca

     

    I also tried these asserts

    assert messageExchange.responseHeaders["Content-Type"].equals("image/jpeg")

    assert messageExchange.responseHeaders["Content-Type"].equals("/[image/jpeg/]")

    assert messageExchange.responseHeaders["Content-Type"].equals("/[image//jpeg/]")

    assert messageExchange.responseHeaders["Content-Type"].equals("\[image/jpeg\]")

    All give a similar error messages.

     

    How do I test a specific header for a specific value?

     

    Testing for != null passes:

    assert messageExchange.responseHeaders["Content-Type"] != null

    but not testing for a specific string.

     

    Thanks in advance!

     

     

    • nmrao's avatar
      nmrao
      Champion Level 3

      That is because, type is ArrayList ([] denotes a list), not String.

       

      Since it has one element in the list, 0th one should match.

       

      Below should work:

      assert messageExchange.responseHeaders["Content-Type"][0] == 'image/jpeg'

       

  • nmrao's avatar
    nmrao
    Champion Level 3
    Your case:
    assert messageExchange.responseHeaders["Server"][0] == 'Apache-Coyote/1.1'
    • wjb's avatar
      wjb
      New Contributor

      Yes that works!

      Thanks for the prompt response!