Forum Discussion

nicstrong's avatar
nicstrong
New Contributor
15 years ago

Property Transfer from HTTP Header

Is it possible to property transfer from an HTTP header ?

Quite a common scenerio in REST is to POST to a know resource to create a new resource. This will return 201 HTTP Status with the Location header set to the URI of the new resource. I would like to property transfer from this.

Thanks,
Nic

7 Replies

  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi Nic,


    At the moment, soapUI does not have a feature allowing elegant way to access HTTP status, let alone HTTP status code.
    Fortunately, Groovy and some hacking are your friends here. 

    Here's one way to retrieve HTTP status code:

    def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
    def httpResponseHeaders = context.testCase.testSteps["Google Search request"].testRequest.response.responseHeaders
    def httpStatus = httpResponseHeaders["#status#"]
    def httpStatusCode = (httpStatus =~ "[1-5]\\d\\d")[0]

    log.info("HTTP status code: " + httpStatusCode)

    groovyUtils.setPropertyValue("Properties", "httpStatusCode", httpStatusCode)


    After this you can access this property using property expansion.

    Does this hack fill your need?


    Cheers!
    /Nenad Nikolic a.k.a. Shonzilla
  • elife's avatar
    elife
    Occasional Contributor
    Hi,
    one additional question ,Is it possible to property transfer to  a Mock's  HTTP header  ?
  • Florin_Neamtu's avatar
    Florin_Neamtu
    Occasional Contributor
    Just to add myself to the queue. It would be very helpful indeed ... it's difficult to test REST services without this!!!
  • Florin_Neamtu's avatar
    Florin_Neamtu
    Occasional Contributor
    I'm actually trying to use the groovy hack to read the ETag header from a HTTP response and set it into a HTTP request header of a subsequent request.

    I managed to read the ETag header from a response and save it into a property (as described in the above Groovy script), but from here I can't figure out how to set the HTTP request header of another Test step to this value. I tried using another Groovy script but it doesn't seem to work (raises an exception) ... or I don't know which properties to use on "testRequest" object. Any idea?

    def httpRequestHeaders = context.testCase.testSteps["delete site 1 for customer 1"].testRequest.requestHeaders
    httpRequestHeaders["ETag"] = "282892923"


    Thanks.
  • Florin_Neamtu's avatar
    Florin_Neamtu
    Occasional Contributor
    I wonder how other people are using SOAP UI to test REST services? You must have the same issue if you need a session ID passed always in a HTTP header. Even if you rely on a cookie for sessionID, there are still scenarios where you'd need to be able to cache a value in a property and then add it into HTTP headers - for example ETag, an API key (license key), etc.

    Is the Pro version in any way different in this area? Would it help me to attach HTTP headers?
  • AjaySharma's avatar
    AjaySharma
    New Contributor

    Just want to check if there is an easy UI way of doing this yet?

    Thanks :)