Forum Discussion

geoffcamp's avatar
geoffcamp
Contributor
16 years ago

Reading value from HTTP Header

Hi,

Is there a way to save a value that is contained within one of the HTTP Header elements of the Response message?
It is not contained as part of the "standard" XML response, however it is visible in the HTTP Headers Investigator.  It also exists within the Raw XML response.

Alternatively, is it possible to save all / some of the information recorded in the http log?

Thanks,

Geoff

3 Replies

  • rlabs's avatar
    rlabs
    New Contributor
    You should try to use TestRunContext.HTTP_STATE_PROPERTY from Groovy Script Step, example:

    def state = context.getProperty( com.eviware.soapui.model.testsuite.TestRunContext.HTTP_STATE_PROPERTY )

    assert state != null : "Missing HttpState.. Try to set 'Maintain HTTP session' in test case options"

    def cookies = state.cookies

    ...

    (not sure how to get another headers from State)

    Another way is to use messageExchange inside Script Assertion:

    String message_size = messageExchange.responseHeaders["Content-Length"]
  • Konda_R's avatar
    Konda_R
    Occasional Contributor
    Hi
    You could also use script assertion test step to assert HTTP response header values.
    I see this feature is avaiable in soapUI Pro3.0.1 [Don't Know about other soapUI editions]

    The syntax is : messageExchange.responseHeaders["HeaderName"]
    For Example:
    //check that Content-Length http resposne header has appropriate value
    def value = messageExchange.responseHeaders["Content-Length"]
    assert(Integer.parseInt(value)>=3322000)

    Let me know if this resolves.

    Thanks
    Kondareddy
  • Thanks for the replies chaps, greatly appreciated.

    I've gone with the script assertion test step and used this to trim and write the value to a file, which seems to work exactly as I need it to.

    def value = messageExchange.responseHeaders["Set-Cookie"]
    def file = new PrintWriter ("t:/Wibble101.xml")

    sb = new StringBuffer(value)
    sb = value - 'LtpaToken=' - '; Path=/; Domain=.test.com'

    file.println(sb)
    file.flush()


    Thanks again,
    Geoff