Forum Discussion

maxrussell's avatar
maxrussell
Contributor
9 years ago

Prefix a property transfer in header

I am using a property transfer to take an oAuth access_token from a response and transfer it to my next GET REST request. The header Name is "Authorization" and the value needs to be in the format "Bearer xxxxxx" ( where xxxxxx is the transferred access_token)

 

How to I add the Bearer prefix into my GET request? Do I need to add something in the property transfer target? Or is this done via test step properties?

  • maxrussell's avatar
    maxrussell
    9 years ago

    I'll write my own response to this:

     

    Bearer ${[Test Step name]#ResponseAsXML#[Xpath xpression]}

     

    Does not work.

     

    Instead, I needed to use a property transfer to Properties, where I stored acctok and then an appropriate header in my request:

    Bearer ${acctok}

     

    I would be interested to see how the ResponseAsXML#XPath Expression method works, but I couldn't get it to do so.

     

  • kondasamy's avatar
    kondasamy
    Regular Contributor

    There are various possibilities to do this ! and I would like you to share an easy approach which I usually follow using SoapUI's property expansion feature. Just assume you need to transfer a spcific value (value of token tag) from response XML of [Source TestStep] to a header parameter of  [Target TestStep], then under the particular parameter pass the value as below,

     

    Bearer ${Source TestStep#ResponseAsXml#//OAuthResponse[1]/token[1]}

     So, the test step would look like as in the below pic.

     

    OAuth.png

     

    The same approach could even be applied for Property Transfer test step as well. Hope this answers your question! Here are few references too,

    http://www.robert-nemet.com/2011/06/soapui-working-with-properties.html

    http://www.soapui.org/scripting---properties/property-expansion.html

     

    Thanks,

    Samy

    • maxrussell's avatar
      maxrussell
      Contributor

      Should specifically have mentioned - I am dealing with a JSON type response.

      • kondasamy's avatar
        kondasamy
        Regular Contributor

        Even if the response is JSON, SoapUI supports XPath for the JSON content trasforming them to XML internally; since we are using ResponseAsXml which does the conversion internally,

        Bearer ${Source TestStep#ResponseAsXml#//OAuthResponse[1]/token[1]}

        So, the above property expansion script will work regardless of being a JSON response.

         

        Thanks,

        Samy