Riham,
I was anxiously awaiting a response from someone, because I thought this would be cool. But, I'd be surprised if DataPower supports this.
Did you see somewhere that it can?
------------------------------
Joseph Morgan
------------------------------
Original Message:
Sent: Thu June 01, 2023 08:47 AM
From: Riham Lamei
Subject: JAR Call
Dears have a good day.
I need your support in calling a java function from a JAR file using gateway script.
I uploaded the jar file in local directory.
and here is the JavaScript file used.
var myJavaFunction = require('rsaEx.jar','Encryption'); var result = myJavaFunction.encryptRSA('MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxuurtZijGi1E26SXfSLm', 'test'); session.output.write(result.toString());
but error occurred that the jar file is not utf-8 encoded
GatewayScript processing Error 'Error: The 'local:///rsaEx.jar' script file is not encoded in UTF-8. Invalid character at line 1, position 3. In file 'gatewayscript:///datapower.js' line:348, stack:Error
Using another approach including the java module is not supported.
Here is the JavaScript using the java module.
var java = require('java'); java.classpath.push('local://rsaEx.jar'); // Use classes and methods from the JAR file var myClass = java.import('rsaEx.Encryption'); var result = myClass.encryptRSA('MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxuurtZijGi1E26SXfSLmEXInJ7On', 'test'); session.output.write(result);
and here is the error occurred
GatewayScript processing Error 'Error: Unable to open the script module file 'java' In file 'gatewayscript:///datapower.js' line:301
Your fast response is highly appreciated.
Riham Lamei
Banking Automation/Integration Engineer
+201223796831
Smart Village (Building B 115), Giza, Egypt