Intersystems HealthShare Java Gateway - How to update an imported java class that contains new methods?

Primary tabs

Hello community,

I'm new to Objectscript and Intersystems development. I've read documentation and some examples and succeded to import my Java class  file into HealthShare using the Java Gateway Service. To import my class i tryed both methods (Wizard, or scripting) with success.

Everything works great, i see my imported class inside the namespace, and i can call the methods.

The problem begin when i try to update my .JAR file with new methods. I've insert new methods inside my Java Class (Public methods), and build a new Jar file to import into HealthShare. Then i've deleted the old package with old class from the namespace and use the wizard (or script) to import my new JAR file. The import works fine, but when i check the class imported, it's the old one with old methods, and i don't understand why it upload my old Class.

To make it works, i have to start a completely new Java project with different name and paste my updated script, then build the jar, and import it into HealthShare, that's will give me the updated class with new methods inside. 

Here's a list of  what i've tryed to resolve my issue:

- Restarting the Java Gateway service from the production before importing the JAR (Fail)

- Rename the JAR file (Fail)

- Rename the package of Java Class (Error, the script can't find the new name, even if state inside the classpath object)

- Changing the Manifest version inide the JAR (Fail)

What else can i try? Somebody please, can help me? Sorry for my english.sad

  • 0
  • 0
  • 41
  • 0
  • 1

Answers

I use this or similar methods to load Java code.

Hi, thanks for sharing your code, anyway i still get the same problem. That's what i did :

1. Create a Gateway with your method "CreateGateway" 

2. Then i call the UploadJar method and i get my class import into namespace, i see it with all methods inside (till here it's Ok)

3. I edit my Java app (just removing 1 method) and build a new Jar.

4. Repeat Step 1 and 2 and i get my java class imported into namespace but with all the methods (included the one i've deleted)

a. Check that the JAR you import has the new code. If you build in a separate directory and then copy the JAR into a final directory it can fail as java locks loaded JAR files on OS level.

b. Try stopping all running Java Gateways before copying the JAR and running UploadJar. Do not create new gateway for every import.

c. What does

zw %objlasterror

report after (4)?

Ok i will try that, but there's a way to check how many Java Gateways are running? 

On the production i only see the EnsLib.JavaGateway.Service, don't know where to find the ones that i state with your code

Edit:

this is the error on step 4:

%objlasterror="0 "_$lb($lb("<%ObjectErrors>OK",,,,,,,,,$lb(,"CORSOESL",$lb("e^GetOneErrorText+1^%apiOBJ^1","e^zGetOneErrorText+1^%SYSTEM.Status.1^1","e^zLogStatus+1^%Net.Remote.Service.1^1","d^zShutdownGateway+10^%Net.Remote.Service.1^1","e^zStopGatewayObject+22^%Net.Remote.Service.1^1","e^zStopGateway+4^%Net.Remote.Service.1^2","e^zUpdateJar+19^luigi.JavaGatewayTest.TestGW.1^1","d^^^0"))))


Ok i will try that, but there's a way to check how many Java Gateways are running?   

There are either production gateways and system gateways, they are listed in SMP - System Administration - Configuration - Connectivity - Object Gateways.

Thanks again, i've tried this:

1. There were 2 Gateways listed on SMP, so i deleted both of them

2. Created a new Gateway using your code, named GW1 and port 7777 (that port was set on a third gateway as service, that  i deleted too, inside the production)

3. All settings on the new GW are correct, it result inactive at first.

4. I've created a completely new java app (with new names on package and class also), to test and copy/past my script class with edited methods

5. Build up the Jar with different name and put it into the folder ready to get uploaded on HS

6. When i call your "UploadJar" i get the following error when it try to connect:

%objlasterror="0 "_$lb($lb(5001,"Can't find the job that is monitoring Gateway 'GW1'",,,,,,,,$lb(,"CORSOESL",$lb("e^zCheckMonitor+20^%                        Net.Remote.Service.1^1","e^zStopMonitor+1^%Net.Remote.Service.1^1","e^zStartGatewayObject+18^%Net.Remote.Service.1^1","e^zConnectGateway+34^%Net                        .Remote.Service.1^1","e^zConnect+4^luigi.JavaGatewayTest.TestGW.1^1","e^zUpdateJar+7^luigi.JavaGatewayTest.TestGW.1^1","d^^^0"))))/* ERRORE #500                        1: Can't find the job that is monitoring Gateway 'GW1' */

7. So i decided to manually activate the GW, and redo your UploadJar and i get this when the code try to stopGateway:

%objlasterror="0 "_$lb($lb("<%ObjectErrors>OK",,,,,,,,,$lb(,"CORSOESL",$lb("e^GetOneErrorText+1^%apiOBJ^1","e^zGetOneErrorText+1^%                        SYSTEM.Status.1^1","e^zLogStatus+1^%Net.Remote.Service.1^1","d^zShutdownGateway+10^%Net.Remote.Service.1^1","e^zStopGatewayObject+22^%Net.Remote                        .Service.1^1","e^zStopGateway+4^%Net.Remote.Service.1^2","e^zUpdateJar+19^luigi.JavaGatewayTest.TestGW.1^1","d^^^0"))))

8. I go to check the namespace, and i see the new package name, with new class name, but inside i still see all the deleted methods.

Here's my current java class with only 2 methods "setAge"  and "getName"

package persona; /**

public class testPersona {     public int age;
    public String name;
    public String sex;     //constructor
    public testPersona (int startAge, String Name, String Sesso) {         this.age = startAge;
        this.name = Name;
        this.sex = Sesso;     }
    
    public void setAge(int newAge) {         age = newAge;
    }     public String getName() {         return name;
    }    /* public static void main(String []args) {         JavaPerson myPerson = new JavaPerson (5, "Tom","M");
        System.out.println(myPerson.getName());
        System.out.println(myPerson.getAge());
        System.out.println(myPerson.getSex());     }*/
}

and this is the HS imported class with all the older methods inside.

Class persona.testPersona Extends java.lang.Object [ ProcedureBlock ]
{ Parameter IMPORTTIMESTAMP As STRING = "2020-01-16 16:04:52.0"; Method %OnNew(ByRef p0 As %ObjectHandle, ByRef p1 As %ObjectHandle, ByRef p2 As %ObjectHandle, ByRef p3 As %ObjectHandle) As %Status
{
Quit:'$D(p0) $$$OK
Quit:$D(p3) ..%Constructor(p0,"persona.testPersona",3,p1,p2,p3)
Quit:$D(p2) ..%Constructor(p0,"persona.testPersona",2,p1,p2)
Quit:$D(p1) ..%Constructor(p0,"persona.testPersona",1,p1)
Quit ..%Constructor(p0,"persona.testPersona",0)
} Method getName() As %ObjectHandle
{
Quit ..%IR("getName")
} Method setAge(ByRef p0 As %ObjectHandle)
{
Do ..%I("setAge",.p0)
} Method getage() As %Integer
{
Quit ..%Get("getage")
} Method setname(p1 As %ObjectHandle)
{
Do ..%Set("setname",p1)
} Method setsex(p1 As %ObjectHandle)
{
Do ..%Set("setsex",p1)
} Method getsex() As %String
{
Quit ..%Get("getsex")
} }