Tuesday, July 12, 2016

Testing Javascript Code Outside Mirth Connect

Mirth Connect is the Swiss Army knife of open source integration engines with specific Healthcare support for HL7 message integration. Internally, it uses Rhino as its JavaScript engine. Having the power of both native JavaScript AND the additional power of calling Java from script is extremely powerful but the lack of debugger function in Mirth Connect can make it painful too.

However, Rhino does have a built-in shell and with a simple command line we can invoke the Rhino shell.

From Windows, the easiest way to do this is to create a shortcut with the following parameters (you may need to change the path to Java depending on the version you are running):

Target: "C:\Program Files\Java\jre1.8.0_65\bin\java.exe" -cp "*;../custom-lib/*" org.mozilla.javascript.tools.shell.Main -strict
Start in: "C:\Program Files\Mirth Connect\client-lib"

The parameters passed are "-cp" which sets the class path. In this case, we want all the Mirth Connect JAR files in the main lib folder and anything in the custom-lib folder too. The "-strict" option turns on Strict Mode.

Now, when you launch the shortcut you will find yourself looking at a "js>" command prompt as follows:
js> print('hi')
hi
js> 6*7
42
js> function f() {
  return a;
}
js> var a = 34;
js> f()
34
js> quit()
Some useful commands to know:

help() -- Displays a list of commands
quit() -- Closes the JavaScript shell
Don't forget to check out the Rhino Documentation too!

2 comments:

  1. Does this still pickup on mirth variables such as channelId, channelName, etc?

    ReplyDelete
  2. No, unfortunately it does not. It just allows you to troubleshoot through some of the eccentricities of the Rhino javascript engine.

    ReplyDelete