Reply
Highlighted
Community Expert
Posts: 540
Registered: ‎12-10-2010

REST call with variable name parameters

I have a case where I need to call a REST service that uses parameters such as:
http://host/wapi1.php?action=bet_place_bet&multi[X][Y]=Z
where X, Y, and Z are all variables. How can I accomplish this in SoapUI?

I suspect there is no out of the box solution. Could you please suggest an approach to modify the parameter name of a REST call, even using Groovy, to accomplish this?

Thank You.
Staff
Posts: 8,810
Registered: ‎02-16-2009

Re: REST call with variable name parameters

Hi,

Can X, Y, and Z be represented as a property expansion i.e http://host/wapi1.php?action=bet_place_bet&multi[${variable_x}][${variable_y}]=${variable_z} or do they have to be literals X, Y, and Z?


Regards,
Marcus
SmartBear Support
Community Expert
Posts: 540
Registered: ‎12-10-2010

Re: REST call with variable name parameters

X, Y, and Z are only placeholders for the purposes of this discussion.

I tried this:

  1. add a new parameter to my REST request, with parameter name: multiple[${#TestCase#variable_x}][${#TestCase#variable_y}]

  2. create two properties in my testcase: variable_x and variable_x, and set the values to "abc" and "DEF" respectively

  3. in the test step, set the value of the new parameter to "123" and run the test

  4. In the Raw tab, the parameter in the URL looks like
    multiple%5B%24%7B%23TestCase%23variable_x%7D%5D%5B%24%7B%23TestCase%23variable_y%7D%5D=123
    changing Disable URL-Encoding has no effect.
Staff
Posts: 8,810
Registered: ‎02-16-2009

Re: REST call with variable name parameters

Hi,

Create some properties at the test case, testsuite, or project level and try below code in event handler RequestFilter.filterRequest.

Test case properties:
variable_x
variable_y
variable_z


log.info request.getPath()
def x = context.expand("\${#TestCase#variable_x}")
def y = context.expand("\${#TestCase#variable_y}")
def z = context.expand("\${#TestCase#variable_z}")

request.setPath("wapi1.php?action=bet_place_bet&multi[${x}][${y}]=${z}")
log.info request.getPath()




Regards,
Marcus
SmartBear Support
Community Expert
Posts: 540
Registered: ‎12-10-2010

Re: REST call with variable name parameters

Getting closer!
The log shows the correct path, however the Request Raw tab does not.

On a related note: Did SOAP-677 (discussed here: viewtopic.php?t=21346) get resolved yet? This deals with event filtering, which would be really useful to get this to work fully.
Staff
Posts: 8,810
Registered: ‎02-16-2009

Re: REST call with variable name parameters

Hi,

The defect SOAP-677 as refereed to in the link viewtopic.php?t=21346 is fixed since version 4.6.2, what version of SoapUI Pro are you using? Using the event handler RequestFilter.filterRequest worked for me. Another event handler you could try is SubmitListener.beforeSubmit.



Regards,
Marcus
SmartBear Support
Community Expert
Posts: 540
Registered: ‎12-10-2010

Re: REST call with variable name parameters

Tried it with SoapUI 4.6.0.
The SubmitListener.beforeSubmit does not even fire the log.info statements, because:
ERROR:groovy.lang.MissingPropertyException: No such property: request for class: Script1


Also tried it with SoapUI 5.1.0.
I cannot get either of the event listeners to fire even the log statements.
Community Expert
Posts: 540
Registered: ‎12-10-2010

Re: REST call with variable name parameters

I was just thinking: if we can get this to work, this could be a cleaner workaround for another one of your bugs SOAPUI-4646 "array query parameters", referenced here: viewtopic.php?t=23808
Staff
Posts: 8,810
Registered: ‎02-16-2009

Re: REST call with variable name parameters

Hi,

For the SubmitListener.beforeSubmit event handler you need to do:

submit.request.getPath() and submit.request.setPath("wapi1.php?action=bet_place_bet&multi[${x}][${y}]=${z}"). Also, I tested this using the 5.1.1 maintenance build.


Regards,
Marcus
SmartBear Support
Community Expert
Posts: 540
Registered: ‎12-10-2010

Re: REST call with variable name parameters

With the SubmitListener.beforeSubmit event, here is what I get:
script log:

INFO:wapi1.php?action=bet_place_bet&multi[abc][DEF]=123
INFO:wapi1.php?action=bet_place_bet&multi[abc][DEF]=123

Yes, the same thing twice!
soapUI log:

DEBUG:Sending request: POST /wapi1.php HTTP/1.1


With the RequestFilter.filterRequest event, I get:
script log:

INFO:/wapi1.php
INFO:wapi1.php?action=bet_place_bet&multi[abc][DEF]=123

soapUI log:

DEBUG:Sending request: POST /wapi1.php HTTP/1.1


Again, the Raw Request tab would confirm that the request URL is not getting updated. Something is not right?