Error in executing Java code with method arguments Object input & ExtensionToolContext context

NitziNitzi Posts: 19

I have a scenario where the xml file stored in local should be passed in one of the element of the SOAP Request in string format. Steps followed to achieve this task:
1. Added SOAP Request
2. Selected correct Data Source in SOAP Request
3. Written a Java code to read file from local & pass it in request tag
4. Xml file location is stored in excel data source
5. Selected Script option for that element/tag
6. In the Edit Script screen, checked box Use Data Source, Selected Language as Java, Specified the Class name which automatically populated the method name
7. Classpath is already added in System properties

In my Java class method, I'm passing two arguments & used context.getValue parameter to access value from excel data source
1. Object input
2. ExtensionToolContext context

After running the SOAP Test, it is failing with below method error-

  • unable to invoke method Expected number of arguments should be 0 or 1 instead of 2

I tried to remove Object input argument but it failed again with argument mismatch error

Can someone help me with this error? Does these method arguments can only be used with Extension Tool & not with normal Scripting in other tool like in my case SOAP request element/tag?

Note- Other java codes with these arguments are working fine with Extension tool


  • Thomas MooreThomas Moore Posts: 64 admin

    Hi Nitzi,

    When you're working with individual elements, scripts will only accept 0 or 1 arguments. If you have the one argument it should be the type ScriptingContext instead of ExtensionToolContext.

    Hope this helps!

  • benken_parasoftbenken_parasoft Posts: 546 ✭✭✭

    Any scripted fields should have a small link label which explains the expected arguments and the type of each argument. This way you don't have to guess beforehand.

    Scripted fields generally don't have an "Object input" argument unless it is an Extension Tool which has an Input tab or can receive input from a parent tool. Similarly, the Extension Tool is the only thing which accepts ExtensionToolContext. All other scripted fields generally accept ScriptingContext. Regardless, the link label I mentioned should indicate what's required.

    As a disclaimer, I have a vague recollection about there being some old version of SOAtest where one of the link labels in a scripted request field indicated the wrong thing. However, even if this were the case and I had to guess what you need, you do seem to be describing a place where the script only takes a single argument of type ScriptingContext.

  • NitziNitzi Posts: 19

    Thanks @Thomas Moore & @benken_parasoft .... Now I know where I was going wrong. This time I have replaced method argument with (ScriptingContext context) & inside using context.getValue(datasource name, datasource column name) to access the values from datasource.

    Unfortunately it is failing with error "No Data Source column named FilePath(column name used)". I don't see the reason why it can't found that column. Correct Datasource & Use data source are selected.

  • benken_parasoftbenken_parasoft Posts: 546 ✭✭✭

    Did you check the "use data source" box? Did you double check you are passing the data source name first and the column name second, and not in the wrong order? Please also check for typos.

Sign In or Register to comment.