Question
Nicky Zhu · Mar 16

Difference in JavaGateway handling of byte[] between static and dynamic proxy objects?

Hi guys, I'm calling a java method as below:

 

public static byte[] SM4EncryptJson(byte[] arg0) throws Throwable {

String inJson = "";

try {

//logger.info("Payload :" + arg0);

inJson = new String(arg0);

//logger.info("As String :" + inJson);

EncTarget payload = JSON.parseObject(inJson, EncTarget.class);

return SM4Encrypt(payload.getContent().getBytes(),payload.getSecretKey());

}catch (Exception e){

logger.error("Error encrypting : ", e);

logger.error("Content : " + arg0);

logger.error("As String : " + new String(arg0));

//logger.log(Level.SEVERE, e.toString(),e);

return null;

}

}

 

Actually the behavior below is the same with a simple method just take a byte array as the augument.

 

I tried call this java method with static proxy object. That is, I imported the java class in iris then call it:

 

    /

/Actually this import only need be called once unless the jar is updated
    //The jar was loaded by gateway definition, not by this piece of codes
    s sc = ##class(%Net.Remote.Service).OpenGateway("AnotherJava", .gatewayConfig) 
    s sc = ##class(%Net.Remote.Service).ConnectGateway(gatewayConfig, .gateway, , 1) 

    s sc = gateway.%Import("com.intersystems.demo.javademo.SM4WrapperWithJson")

     w "--Running proxy java call-- ",!
     #Dim arg As %Stream.GlobalBinary = ##Class(%Stream.GlobalBinary).%New()
     s payload = ##Class(Demo.Entity.EncPayload).%New()
     s payload.secretKey = "C2FEEEAC-CFCD-11D1-8B05-00600806D9B6"
     d payload.content.CopyFrom(fileScr)
     d payload.%JSONExportToStream(arg)

     s rtnStream = ##class(com.intersystems.demo.javademo.SM4WrapperWithJson).SM4EncryptJson(gateway,arg)
     w "The type of result is "_$classname(rtnStream),!
     w !,"--Proxy java call finished successfully-- ",!

    

This works fine and I got what I expected:

DEMOSPACE>d ##Class(Test.JavaInvokingTest).TestStcProxyWithJson("c:\sec\source.txt","c:\sec\x.txt")                                                            

--Calling Java method with Static proxy class--
--Running proxy java call--
The type of result is %Library.GlobalBinaryStream
 
--Proxy java call finished successfully--
 

Then I also tried using dynamic proxy:

    
    

//Generate the proxy
    //Actually this import only need be called once unless the jar is updated
    //The jar was loaded by gateway definition, not by this piece of codes
    s sc = ##class(%Net.Remote.Service).OpenGateway("AnotherJava", .gatewayConfig) 
    s sc = ##class(%Net.Remote.Service).ConnectGateway(gatewayConfig, .gateway, , 1) 

    w "--Generating Dynamic Proxy-- ",!
     s proxy = ##class(%Net.Remote.Object).%New(gateway,"com.intersystems.demo.javademo.SM4WrapperWithJson")
     w "--Running proxy java call-- ",!
     #Dim arg As %Stream.GlobalBinary = ##Class(%Stream.GlobalBinary).%New()
     s payload = ##Class(Demo.Entity.EncPayload).%New()
     s payload.secretKey = "C2FEEEAC-CFCD-11D1-8B05-00600806D9B6"
     d payload.content.CopyFrom(fileScr)
     d payload.%JSONExportToStream(arg)

     s rtnStream = proxy.SM4EncryptJson(arg)
     w "The type of result is "_$classname(rtnStream),!
     w !,"--Proxy java call finished successfully-- ",!

 

But it didn't work 

DEMOSPACE>d ##Class(Test.JavaInvokingTest).TestDynProxyWithJson("c:\sec\source.txt","c:\sec\x.txt")                                                             --Calling Java method with Dynamic proxy class and JSON--
--Generating Dynamic Proxy--
--Running proxy java call--
Error calling proxy class
 
 
错误 #8104: Gateway Exception: <GATEWAY> java.lang.IllegalArgumentException sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) argument type mismatch1

I wonder why this happens and how to make a call with byte[] argument method using dynamic proxy? 

 

Thanks.

 

 

 

 

Product version: IRIS 2020.1
$ZV: IRIS for Windows (x86-64) 2020.1.1 (Build 408U) Sun Mar 21 2021 22:04:09 EDT
0
0 126
Discussion (3)1
Log in or sign up to continue

Do you still expect some echo?
Or is the question meanwhile just out of date?

Hi Robert - this was an old question. It can be closed. We contacted ISC and got some pointers