As part of a migration project from a bunch of java classes to IRIS, we need to maintain a few jar files due to some external dependencies.
The problem I am seeing is that I cannot pass a byte array ( byte[] ) from ObjectScript to the Java Class. I have tried a number of different ways
I have reproduced in a java class and Objectscript class:
Java Class:
package wrc;
public class TestJava {
public static void testByteArr(byte[] keyBytes) {
System.out.println("keyBytes getClass() = " + keyBytes.getClass() );
System.out.println("keyBytes toString() = " + keyBytes.toString() );
}
public static void testByte(byte obj) {
System.out.println("byte getClass() = " + ((Object)obj).getClass().getName() );
System.out.println("byte toString() = " + ((Object)obj).toString() );
}
public static void testStr(String obj) {
System.out.println("obj getClass() = " + ((Object)obj).getClass().getName() );
System.out.println("obj toString() = " + obj );
}
public static void testObj(Object obj) {
System.out.println("obj getClass() = " + ((Object)obj).getClass().getName() );
System.out.println("obj toString() = " + obj.toString() );
}
}
ObjectScript Class
Class POH.wrc Extends %RegisteredObject
{
ClassMethod testMe()
{
#DIM javaGate As %External.JavaGateway = $SYSTEM.external.getJavaGateway()
do javaGate.addToPath("C:\temp\wrc.jar")
set test = javaGate.new("wrc.TestJava")
do test.testStr("test string")
do test.testByte($C(40))
try {
w !,"TRY #"_$I(TEST)
do test.testByteArr($C(40) _ $C(41))
} catch (e)
{
w " *** FAILED: " _ e.DisplayString()
}
try {
w !,"TRY #"_$I(TEST)
set bArr = ##class(%ListOfDataTypes).%New()
do bArr.Insert($C(40))
do bArr.Insert($C(41))
do test.testByteArr(bArr)
} catch (e)
{
w " *** FAILED: " _ e.DisplayString()
}
try {
w !,"TRY #"_$I(TEST)
#Dim arg As %Stream.GlobalBinary = ##Class(%Stream.GlobalBinary).%New()
do arg.Write($C(40))
do arg.Write($C(41))
do test.testByteArr(arg)
} catch (e)
{
w " *** FAILED: " _ e.DisplayString()
}
try {
w !,"TRY #"_$I(TEST)
#Dim argc As %Stream.GlobalCharacter = ##Class(%Stream.GlobalCharacter).%New()
do argc.Write($C(40))
do argc.Write($C(41))
do test.testByteArr(argc)
} catch (e)
{
w " *** FAILED: " _ e.DisplayString()
}
}
}
Each fail with:
TRY #x *** FAILED: <GATEWAY> java.lang.IllegalArgumentException sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) argument type mismatch
The String and Byte tests above work fine...