Hi Sameer,
Your Java method signature expects 4 parameters, but your are passing 5 in your JavaScript action. There is an extra parameter (contextId) I think, which cause timestamp
to be mapped to layer2FirewallRules
. That's why it says that it cannot convert a number to an array.
Hi!
I guess the reason for this is that the Arrays you create in JavaScript are not equal to Arrays in Java. The Rhinoengine is used in background, so for further research you can start with:
http://www.mozilla.org/rhino/ScriptingJava.html (The "Creating Java Arrays" Chapter) and http://stackoverflow.com/questions/1433382/how-to-convert-rhino-javascript-arrays-to-java-arrays
Regards,
Joerg
BTW: this might also be interesting...: http://communities.vmware.com/thread/324338?tstart=0
Hi.
1)java.lang.reflect.Array.newInstance is not working as it wont understand "newInstance" method.
I am getting error "newInstance is not function.It is org.mozilla.javascript.NativeJavaPackage".
2)As per your second reply, I am already using JS Array type. But I am getting error when RhinoEngine is trying to convert JS array to Java array(to call Java method wuth Array param).
Hi Sameer,
I think the error during the conversion is related to the way you instantiate the array of elements that you want to pass. How do you create the array inside your scripting code?
I'm writing you an example that should work, since we are using the same approach within different plug-ins and they all work fine.
Define the method inside the vso.xml like that:
<object script-name="MyObject"...
...
<method java-name="myMethod" return-type="void" script-name="myMethod">
<parameters>
<parameter name="items" type="[MyObjectItem" />
</parameters>
</method>
...
</object>
Define the method inside the Java class like that:
public class MyObject {
...
public void myMethod(MyObjectItem[] items) {
...
}
...
}
Create the array inside the scripting code and invoke the method like that:
var items = new Array(3);
items[0] = new MyObjectItem();
items[1] = new MyObjectItem();
items[2] = new MyObjectItem();
var myObject = new MyObject();
myObject.myMethod(items);
I hope it helps!
Regards,
Sergio
Hi Sergio,
I have already implemented same thing as follows.
I am getting error
vso.xml
App.java
public ArrayList<FailedPublishInfoDto> publishConfig(
Boolean provisioned,
Long timestamp,
Layer2FirewallRuleDto[] layer2FirewallRules,
Layer3FirewallRuleDto[] layer3FirewallRules) {
...
}
JS Action:
var layer2FirewallRule = app.composeLayer2FirewallRule(id, "ALLOW"/*actionE.name*/, "HIGH"/*precedence.name*/, disabled, logged, notes, srcExclude, srcId, destProtocol, destProtocolNumber, destExclude, destIpId);
var l2Arr = new Array(1);
l2Arr[0] = layer2FirewallRule; // Even tried "new Layer2FirewallRuleDto()"
var l3Arr = new Array(0);
app.publishConfig(contextId , provisioned, timestamp , l2Arr , l3Arr);
***************************************************************************************************************************
I am getting error
Cannot convert 576557.0 to Layer2FirewallRuleDto[]
I have also included Layer2FirewallRuleDto in both Finder and Object in vso.xml.
Hi Sameer,
Your Java method signature expects 4 parameters, but your are passing 5 in your JavaScript action. There is an extra parameter (contextId) I think, which cause timestamp
to be mapped to layer2FirewallRules
. That's why it says that it cannot convert a number to an array.
Hi dnachev,
Thanks.
That is good catch.
It was my bad. I forgot to delete one of the method param and I was thinking of possible error of mapping between JS array and Java arrray.
Regards
Sameer