简体   繁体   中英

Passing variable arguments to a java function from javascript using GraalVM

I am trying to call a function available in Corda RPC called startTrackedFlowDynamic which accepts 2 arguments: startTrackedFlowDynamic(logicType: Class<out FlowLogic<T>>, vararg args: Any?) which is packaged in a JAR

The call to this function is made from a Javascript context (using GraalVM to achieve that), I want to call this function and pass the arguments to it obtained from a request object (say, coming from a REST API)

Example: if the request contains an array [::InitiatorA, iouValue] , I would want to call startTrackedFlowDynamic like: startTrackedFlowDynamic(::InitiatorA, iouValue)

if the request contains an array [::InitiatorB, abc, xyz] I would want to call startTrackedFlowDynamic like: startTrackedFlowDynamic(::InitiatorB, abc, xyz)

if the request contains an array [::InitiatorC] I would want to call startTrackedFlowDynamic like: startTrackedFlowDynamic(::InitiatorC)

TLDR: I would like to make it as a generic API instead of re-writing for every different Flow call. I want to be able to pass dynamic number of arguments coming from the request object to this function instead of hard coding a fixed number of arguments and having to update it when the number of argument changes

An example of the behaviour I want to replicate:

 var func = function () { console.log(arguments.length); for (var i = 0; i < arguments.length; i++) { console.log(arguments[i]); } }; func.apply(null, ['::InitiatorA', 'abc', 'xyz']) 

Any suggestions?

It seems to work with the following JavaScript syntax

var argsArray = ['::InitiatorA', 'abc', 'xyz']
startTrackedFlowDynamic(...argsArray)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM