0
votes

I am using Mirth Connect Server 3.4.2.8129. I created a test channel, a very simple one which should just select the records from a table (SQL Server) and send them to a destination of type javascript writer.

I defined a database reader source and I am trying to select the records of a table. I will paste the code below.

The Javascript code I use in the Source is this (I replaced sensitive information with ***):


var dbConn;
try 
{
    dbConn = DatabaseConnectionFactory.createDatabaseConnection('net.sourceforge.jtds.jdbc.Driver','jdbc:jtds:sqlserver://***:***;InstanceName=***;DatabaseName=***','***','***');
    var results = executeCachedQuery('select * from [***].[dbo].[***]');        
    return results;
} 
finally 
{
    if (dbConn) 
    { 
        dbConn.close();
    }
}

I get the following error:

ERROR 2019-10-14 12:41:00,164 [Database Reader Polling Thread on TestMedisOrders (fba0f4c7-0a2d-47ec-b638-acb586925c92) < fba0f4c7-0a2d-47ec-b638-acb586925c92_Worker-1] com.mirth.connect.connectors.jdbc.DatabaseReceiver: Failed to poll for messages from the database in channel "TestMedisOrders"
com.mirth.connect.connectors.jdbc.DatabaseReceiverException: Error executing script 4bf7e588-202a-4aea-9d5e-be0155a4fa6a.
    at com.mirth.connect.connectors.jdbc.DatabaseReceiverScript.poll(DatabaseReceiverScript.java:128)
    at com.mirth.connect.connectors.jdbc.DatabaseReceiver.poll(DatabaseReceiver.java:108)
    at com.mirth.connect.donkey.server.channel.PollConnectorJob.execute(PollConnectorJob.java:49)
    at org.quartz.core.JobRunShell.run(JobRunShell.java:213)
    at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:557)
    Caused by: com.mirth.connect.server.MirthJavascriptTransformerException: 
    CHANNEL:    TestMedisOrders
    CONNECTOR:  Source
    SOURCE CODE:    
    125: }
    126: 
    127: function executeOperation(source, operation, expression, parameters) {
    128:    var dbConn = getDBConnection(source);
    129:    var attempts = 0;
    130:    var maxAttempts = java.lang.Integer.parseInt($('DBMaxRetries'));
    131: 
    132:    while (attempts < maxAttempts) {
    133:        attempts++;
    134: 
    LINE NUMBER:    130
    DETAILS:    Wrapped java.lang.NumberFormatException: For input string: ""
        at 4bf7e588-202a-4aea-9d5e-be0155a4fa6a:130 (executeOperation)
        at 4bf7e588-202a-4aea-9d5e-be0155a4fa6a:67 (executeCachedQuery)
        at 4bf7e588-202a-4aea-9d5e-be0155a4fa6a:249 (doScript)
        at 4bf7e588-202a-4aea-9d5e-be0155a4fa6a:259
        at com.mirth.connect.server.util.javascript.JavaScriptUtil.executeScript(JavaScriptUtil.java:527)
        at com.mirth.connect.connectors.jdbc.DatabaseReceiverScript$SelectTask.doCall(DatabaseReceiverScript.java:168)
        at com.mirth.connect.server.util.javascript.JavaScriptTask.call(JavaScriptTask.java:113)
        at java.util.concurrent.FutureTask.run(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
    Caused by: java.lang.NumberFormatException: For input string: ""
        at java.lang.NumberFormatException.forInputString(Unknown Source)
        at java.lang.Integer.parseInt(Unknown Source)
        at java.lang.Integer.parseInt(Unknown Source)
        at sun.reflect.GeneratedMethodAccessor46.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:126)
        at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:225)
        at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:1479)
        at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:815)
        at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:109)
        at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:393)
        at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3280)
        at org.mozilla.javascript.InterpretedFunction.exec(InterpretedFunction.java:120)
        at com.mirth.connect.server.util.javascript.JavaScriptTask.executeScript(JavaScriptTask.java:142)
        at com.mirth.connect.server.util.javascript.JavaScriptUtil.executeScript(JavaScriptUtil.java:522)
        ... 6 more

I tried searching for a setting in all the configuration files in mirth installation folder, but I didn't find any file containing it. I also unarchived the SQL Server driver (jtds 1.3.1.jar) and searched there, too, but no. I did not find anything about a DBMaxRetries.

Has anyone else face this?

Thank you.

1

1 Answers

1
votes

You likely meant to call:

var results = dbConn.executeCachedQuery('select * from [***].[dbo].[***]');

According to the stack trace, you must have javascript functions executeCachedQuery and executeOperation defined, likely through a code template if you check your channel dependencies. You are calling the executeCachedQuery javascript function instead of the DatabaseConnection.executeCachedQuery API method.

$('DBMaxRetries') is attempting to pull the value from one of the mirth maps. globalMap, globalChannelMap, and configurationMap are the only ones available from a Database Reader context. If you haven't defined DBMaxRetries in at least one of these maps, it will return null.