Skip to content

Error: [...HelloWorld] is not a function, it is object #51

@anoopvarma-2000-p

Description

@anoopvarma-2000-p

In Mirth connect 4.5.0 in docker, when I invoke a class from my jar file (from custom-lib folder), getting the following error:

ERROR  (com.mirth.connect.connectors.js.JavaScriptReceiver:195): Error executing JavaScript Reader script 5cd61f28-81d3-4a33-a060-2970b27739f9_JavaScript_Reader.
com.mirth.connect.server.util.javascript.JavaScriptExecutorException: com.mirth.connect.server.MirthJavascriptTransformerException: CHANNEL:
	HelloWorldCONNECTOR:
	SourceSOURCE CODE:
	105: //var hw = new hwClass(); // This will fail if class is not found106: //logger.info(hw.sayHello());107: 108: //logger.info("Engine: " + engine.getFactory().getEngineName());109: 110: var hw = new Packages.com.example.helloworld.HelloWorld();111: logger.info(hw.sayHello());112: 113: 114: //var hwClass1 = Java.type("com.example.helloworld.HelloWorld");LINE NUMBER:
	110DETAILS:
	TypeError: [JavaPackage com.example.helloworld.HelloWorld] is not a function, it is object.
	at 5cd61f28-81d3-4a33-a060-2970b27739f9_JavaScript_Reader:110 (doScript)
	at 5cd61f28-81d3-4a33-a060-2970b27739f9_JavaScript_Reader:126
	at com.mirth.connect.server.util.javascript.JavaScriptUtil.execute(JavaScriptUtil.java:79)
	at com.mirth.connect.connectors.js.JavaScriptReceiver.poll(JavaScriptReceiver.java:161)
	at com.mirth.connect.donkey.server.channel.PollConnectorJob.execute(PollConnectorJob.java:49)
	at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
	at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)Caused by: com.mirth.connect.server.MirthJavascriptTransformerException: CHANNEL:
	HelloWorldCONNECTOR:
	SourceSOURCE CODE:
	105: //var hw = new hwClass(); // This will fail if class is not found106: //logger.info(hw.sayHello());107: 108: //logger.info("Engine: " + engine.getFactory().getEngineName());109: 110: var hw = new Packages.com.example.helloworld.HelloWorld();111: logger.info(hw.sayHello());112: 113: 114: //var hwClass1 = Java.type("com.example.helloworld.HelloWorld");LINE NUMBER:
	110DETAILS:
	TypeError: [JavaPackage com.example.helloworld.HelloWorld] is not a function, it is object.
	at 5cd61f28-81d3-4a33-a060-2970b27739f9_JavaScript_Reader:110 (doScript)
	at 5cd61f28-81d3-4a33-a060-2970b27739f9_JavaScript_Reader:126
	at com.mirth.connect.server.util.javascript.JavaScriptUtil.executeScript(JavaScriptUtil.java:620)
	at com.mirth.connect.connectors.js.JavaScriptReceiver$JavaScriptReceiverTask.doCall(JavaScriptReceiver.java:235)
	at com.mirth.connect.server.util.javascript.JavaScriptTask.call(JavaScriptTask.java:114)
	at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.base/java.lang.Thread.run(Unknown Source)

Additional details:

  • Mirth Connect is running in a Docker container. The Image: nextgenhealthcare/connect:4.5.0
  • OpenJDK 21
  • Mirth Connect v4.5.0

The same setup works fine in a non-docker environment.

The code used in the channel (Source: JavaScript Reader):

var hw = new Packages.com.example.helloworld.HelloWorld();
logger.info(hw.sayHello());

The source code of the jar file:

package com.example.helloworld;

public class HelloWorld {
    public HelloWorld() {
    }

    public String sayHello() {
        return "Hello, World!";
    }

    public String sayHello(String name) {
        return "Hello, " + name + "!";
    }

    public String sayHello(String name, String greeting) {
        return greeting + ", " + name + "!";
    }
}

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example</groupId>
    <artifactId>helloworld</artifactId>
    <version>1.0.4</version>
    <properties>
        <java.version>21</java.version>
        <maven.compiler.source>21</maven.compiler.source>
        <maven.compiler.target>21</maven.compiler.target>
    </properties>
</project>

Please help to load the class properly, and print Hello World.
Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions