How can I get values from REST path and return it as a string in the response?
For example, I have somehost.com/restapi/v1/value1 and I want it to return value1.
I set up REST URL Data Bank and set "Path - 0" to value1.
In one of the attribute in the response, I use this Groovy script...
import com.parasoft.api.*;
boolean customAssertion(Object input, ScriptingContext context) {
String value = context.getValue("Generated Data Source", "value1");
Application.showMessage("Value from data source is " + value)
Application.showMessage("Value from SOAP response is " + input.toString())
return input.toString().contains(value);
}
But I am getting this error..
Unable to invoke user method customAssertion(java.lang.Object, com.parasoft.api.ScriptingContext). Argument count should be 0 or 1 instead of 2.
Would anyone be able point me on how to resolve this issue?
Comments
-
Hi,
Can you share more information about where this script is? Depending on the location scripting methods are passed different numbers of arguments. In this case it is saying it expecting to find a method that only takes a single input or none.
Have you tried changing you method to take a single input? The scripting context to set if that works?
0 -
The script locates in an attribute in the response. I tried
import com.parasoft.api.*;
import soaptest.api.*;String doofus(ExtensionToolContext context) {
String value = context.getValue("value1");
Application.showMessage("Value from data source is " + value)
Application.showMessage("Value from SOAP response is " + input.toString())
return input.toString().contains(value);
}I don't see any errors, but I am not seeing the value in the attribute in the response.
0 -
Hi,
I think the cause is the "getValue" was suppose to still the method with the data source name.
getValue("Generated Data Source", "value1")
Is there a reason you changed that in the second script?
Here is link to the scripting reference
https://docs.parasoft.com/display/SOAVIRT9103CTP310/Extensibility+and+Scripting+Basics0 -
I was just trying all the different options. I also tried this
import com.parasoft.api.*;
import soaptest.api.*;String doofus(ExtensionToolContext context) {
String value = context.getValue("Generated Data Source", "value1");
Application.showMessage("Value from data source is " + value)
Application.showMessage("Value from SOAP response is " + input.toString())
return input.toString().contains(value);
}I still don't see any value coming back.
0 -
I was able to use ${value1} and set that in fixed and it works.
0 -
Hi,
Is your use case that you want to validate that "value1" from the path is present in the request message that was received and use that as part of the response payload?
I have attached an example that does that by chaining an extension tool to the incoming request payload after the data bank. I then output the result into another data bank to create an "assertion" column that I use to parameterize the value of an attribute in the response payload.
0 -
I didn't need validation, I just want value1 from the path is present in the request message that received and use that as part of the response payload. Thank you for the example. It seems that It's missing ${BASE_URL}. Would you be able to provide StubService service?
0 -
Hi,
You can just remove that setting. That is for if you have a WSDL and want the response to be based on the definition. I didn't actually use it the example. I think I probably copied something from some where else and forgot that setting was in there.
In the "Definition" tab just delete all the text in the "WSDL URL" text box.
0 -
Got it. Thank you so much for your help.
0 -
Happy to help!
0