Most dignified developers,
I'm having trouble invoking a method on my own java class from a lotus script agent.
My Java class simplified looks like this
import lotus.domino.*;
public class MyClass{
/* .. omitted constructor and other methods .. */
public void myMethod(Document doc){
/* ... do things with the document object ...*/
}
}
Now this class is included with the proper use statement, and I can iterate over the classmethods on the class object in lotus script to get the signature of the arguments needed.
But when I try to invoke the method I get a LS2J: Parameter mismatch calling Method myMethod
I've tried both with dot notation on the JavaObject (No I'm not using a Mac ;)) and ADT
Dim doc as NotesDocument
Dim jSession As JavaSession
Dim jClass As JavaClass
Dim jObject As JavaObject
...
Set jSession = New JavaSession()
Set jClass = jSession.Getclass("MyClass")
Set jObject = jClass.Createobject()
Call jObject.myMethod(doc)
and respectively
Dim jMethod as JavaMethod
...
Set jMethod = jClass.Getmethod("myMethod", "(Llotus/domino/Document;)V")
tmp = jMethod.Invoke(jObject,doc)
Also I've added error handling (OnError ..) to print out the results of any JavaError (+ stacktrace) but they end up empty so no further clues there.
I'm using Designer version 9.0
Any ideas/pointers/gotchas? It's driving me bald.
You are using the correct approach to calling your Java method but you can not pass Notes backend objects as parameters.
You can parse a string with the document universal id, for instance, and then in your Java method look up the document using the universal id.
Alternatively, migrate your Lotusscript logic to Java :-)
Maybe you don't need CreateObject..
This is how I do it:
Dim jSession As New JavaSession()
Dim jClass As JavaClass()
Set jClass = jSession.GetClass("MyClass")
If jClass.myMethod(doc) Then
Full example added
Java class:
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
public class GetFileFromUrl {
public static boolean getFileFromUrl(String imageUrl, String filePath) {
try {
URL url = new URL(imageUrl);
InputStream is = url.openStream();
OutputStream os = new FileOutputStream(filePath);
byte[] b = new byte[2048];
int length;
while ((length = is.read(b)) != -1) {
os.write(b, 0, length);
}
is.close();
os.close();
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
}
LotusScript:
UseLSX "*javacon"
Use "GetFileFromUrl"
Private Function GetFileFromUrl(url As String, outputPath As String) As Boolean
Dim jSession As New JavaSession
Dim jClass As JavaClass
Set jClass = jSession.GetClass("GetFileFromUrl")
If jClass.getFileFromUrl(url, outputPath) Then
GetFileFromUrl = True
End If
End Function
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With