Ask a Question

Prefix a property transfer in header

SOLVED
maxrussell
Contributor

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?

1 ACCEPTED SOLUTION

Accepted Solutions
maxrussell
Contributor

Re: Prefix a property transfer in header

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.

 

View solution in original post

10 REPLIES 10
kondasamy
Regular Contributor

Re: Prefix a property transfer in header

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
Contributor

Re: Prefix a property transfer in header

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

kondasamy
Regular Contributor

Re: Prefix a property transfer in header

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

maxrussell
Contributor

Re: Prefix a property transfer in header


I have a property transfer that contains the term access_token.
In the second request (Get All Project Details) I have the header Bearer ${Source ObtainAuthTok1#ResponseAsXML#//access_token} in the request.

When this runs, the desired token is placed into the Authorization field, but it is not prefixed with Bearer.

 

I am a bit confused by this process.

kondasamy
Regular Contributor

Re: Prefix a property transfer in header

To clearly make a note, Propety transfer step is not at all needed as you are directly referencing it through Property expansion feature. I will just reiterate in the required format needed for this operation,

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

 

I suspect that you might have to correct the XPath expression; please check! This should work; as I see desired result from my end!

 

Thanks,

Samy

 

maxrussell
Contributor

Re: Prefix a property transfer in header

Bearer ${ObtainAuthTok1#ResponseAsXML#//access_token} - is my exact syntax. The response only has a single access_token. However, this doesn't return the token.

 

Interestingly, just using "access_token" - in the property transfer, did do the selection....

 

I've double checked by proxying out through Fiddler and can see Bearer, but not the token...

HeikoStudt
Occasional Contributor

Re: Prefix a property transfer in header

Hi,

I am rather not a professional SoapUI user yet... however, for me it is less complex in understanding the solution in two steps:

Use a property transfer to extract the value into some TestCase property (or somewhere else) and then in the following TestStep some Property Expansion to prefix the "Bearer" string.

 

 

MFG (Best regards)

Heiko Studt

maxrussell
Contributor

Re: Prefix a property transfer in header


@kondasamy wrote:

To clearly make a note, Propety transfer step is not at all needed as you are directly referencing it through Property expansion feature. I will just reiterate in the required format needed for this operation,

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

 

I suspect that you might have to correct the XPath expression; please check! This should work; as I see desired result from my end!

 

Thanks,

Samy

 

Are you running the same against an oAuth response? Are you actually extracting the token for replay with the prefix?

 

maxrussell
Contributor

Re: Prefix a property transfer in header

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.

 

View solution in original post

cancel
Showing results for 
Search instead for 
Did you mean: