0
votes

I have to make a call to a method of a web service via SSJS. One of the input parameters of the method is a structure array. The web service consumer is implemented in java. I would like to know how to declare and instantiate the java strucuture array in SSJS.

The signature of the method is:

(short , short , java.lang.String , java.lang.String , java.lang.String , java.lang.String , java.lang.String , java.lang.String , java.lang.String , short , java.lang.String , java.lang.String , ESTRUTURACHECKLIST[] )

I am creating the array as per your suggestion:

lst=new ArrayList();

var chk:xx.xxx.xxxx.xxxx.ESTRUTURACHECKLIST=new 
xx.xxx.xxxx.xxxx.ESTRUTURACHECKLIST();
chk.setCONTEUDOCHECKLIST("XXXX");
chk.setDESCRICAOCHECKLIST("CÓDIGO USUÁRIO");
lst.add(chk);

var chk1:xx.xxx.xxxx.xxxx..ESTRUTURACHECKLIST=new 
xx.xxx.xxxx.xxxx..ESTRUTURACHECKLIST();
chk1.setCONTEUDOCHECKLIST("TESTE");
chk1.setDESCRICAOCHECKLIST("NOME USUARIO");
lst.add(chk1);
var chk2:xx.xxx.xxxx.xxxx..ESTRUTURACHECKLIST=new 
xx.xxx.xxxx.xxxx..ESTRUTURACHECKLIST();
chk2.setCONTEUDOCHECKLIST("TESTE NOTES");
chk2.setDESCRICAOCHECKLIST("NOME NOTES");
lst.add(chk2);
arr=lst.toArray(); 

When I created the structure array following its suggestion, the java method gives the error and does not recognize the last array. To be sure, I changed the signature of the class that instantiates the web service client by removing the array, there was no error. What I think is occurring is that the java class is not recognizing the array passed by the SSJS with an array of the specified structure.

The error calling the method is:

Error while executing Javascript action expression Script interpreter error, line=75, col=13: Java method 'xxxxx(number, number, string, string, string, string,string, string,string, string,string, [Ljava.lang.Object;)'on java class xx.xxxx.xxxx.xxx not found

2
What do you mean by "structure array"? Is it an array of a certain class? Is it a ListArray? How is the exact signature of your method you want to call? - Knut Herrmann
This is an array of a Java class defined by the developer. - Marcus Loza
If I did not make a mistake while counting then the input for your method should contain 2x number + 7x string + 1x number + 2x string + 1x array but the error indicates that you are trying to execute with 2x number + 9x string + 1x array. It seems like 1 argument (number) is missing... - xpages-noob
Actually I have an intermediate class that receives the signature of 2x number + 9x string + 1x array, and calls the signature method mentioned in the problem statement, also passing the 1x number. - Marcus Loza

2 Answers

1
votes

If you need a Java array of the given objects, you can first put them in a List-like structure, like ArrayList or Vector, and afterwards retrieve the Java array by calling the toArray method.

Here is a SSJS code snippet that should help you:

importPackage(java.util);
importPackage(br.com.mercantil.dmdws);

var lst,chk,arr;

lst=new ArrayList();

chk=new ESTRUTURACHECKLIST();
// ... do whatever you need to do to the object
lst.add(chk);

// ... repeat previous step if needed

arr=lst.toArray(); // this is the Java array

Update

If the method you use cannot handle the Object array because it demands the array to be of a certain class you can provide an array with the needed runtime type as first argument to the toArray method. As I do not know how to create or cast such an array in SSJS I would add a "helper" method to the br.com.mercantil.dmdws.ESTRUTURACHECKLIST class which looks like this

public static ESTRUTURACHECKLIST[] getJavaArray(int n) {
    return new ESTRUTURACHECKLIST[n];
}

and create the array in the example above in the following way:

arr=lst.toArray(ESTRUTURACHECKLIST.getJavaArray(lst.size()));
0
votes

Using the full name of the relevant class, including package name, will work. For example, if it was needing to pass a Java HashMap, you could use:

var myMap:java.util.HashMap = new java.util.HashMap();

This assumes the relevant class is accessible to the code, for example the HashMap class here is accessible because it's part of the Java core, which XPages has access to.