web stats
TypeError: is not a function, it is object - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 12-01-2010, 06:43 AM
lgoran lgoran is offline
Mirth Newb
 
Join Date: Sep 2010
Posts: 14
lgoran is on a distinguished road
Default TypeError: is not a function, it is object

I upgraded to Mirth Connect 2.0.1 from 1.8.2 and now Mirth seems to be unable to call an external Java class. Everything worked in 1.8.2 and I have not modified any code. The jar-file is in "custom-lib" directory and it is the same file as in 1.8.2.
The error message is:
TypeError: [JavaPackage se.nll.PnrFraga.CallVASPnr] is not a function, it is object
Reply With Quote
  #2  
Old 12-17-2010, 11:37 AM
rutledj rutledj is offline
Mirth Guru
 
Join Date: Nov 2010
Location: North Carolina
Posts: 385
rutledj is on a distinguished road
Default

Did you figure this out? I get the same error message when calling a function in a java file.
Reply With Quote
  #3  
Old 12-20-2010, 10:50 PM
lgoran lgoran is offline
Mirth Newb
 
Join Date: Sep 2010
Posts: 14
lgoran is on a distinguished road
Default

No, I have no solution yet. I had hoped to get some clue in this forum ....
To me it seems like a bug i Mirth 2.0.
I wonder if anyone actually has been able to call a custom Java method
in Mirth 2.0
Reply With Quote
  #4  
Old 08-11-2011, 07:05 AM
Mr.T Mr.T is offline
OBX.1 Kenobi
 
Join Date: Aug 2011
Posts: 39
Mr.T is on a distinguished road
Default

what did you do if i may ask...thx!
Reply With Quote
  #5  
Old 08-11-2011, 09:36 AM
tickletoe tickletoe is offline
What's HL7?
 
Join Date: Nov 2010
Posts: 4
tickletoe is on a distinguished road
Default

I am using Mirth Connect 2.1.0 and can access classes in a custom jar file. The jar file is in "custom-lib".
In my javascript I have an importPackage statement.
I had to restart the Mirth Server service for it to pick up the new jar.
Hope this helps,
Cheers
Scott
Reply With Quote
  #6  
Old 08-11-2011, 09:43 AM
AlexToft AlexToft is offline
OBX.3 Kenobi
 
Join Date: Sep 2010
Location: Leeds, UK
Posts: 160
AlexToft is on a distinguished road
Default

Posting your Java source might help...

There is no problem calling external classes in Mirth, here's a simple example:

Code:
In Mirth transformer:
var myVar = new Packages.com.alex.test();
logger.info(myVar.execute('Hello'));

In Java:
package com.alex;
public class test {
    
    public String execute(String something) {
        return "You said... " + something;
    }
    
}

In logger:
"You said... Hello"
Reply With Quote
  #7  
Old 08-12-2011, 12:47 AM
Mr.T Mr.T is offline
OBX.1 Kenobi
 
Join Date: Aug 2011
Posts: 39
Mr.T is on a distinguished road
Default

hey guys, first of all thanks for your reply!
just tried it again and it just wont work, but maybe it is my lack of java skills :P

her is what i did:
Main.java
Code:
import blaPack.Test;

public class Main {
	
	public static void main (String args[])
	{
		System.out.println("Main, before Class");
		Test tst = new Test();
		System.out.println(tst.execute("Main calls Test"));
		System.out.println("Main, after Class");		
	}
}
Test.java
Code:
package blaPack;

public class Test {

	public String execute(String something) {
        return "You said... " + something;
    }
}
In Eclipse everything works fine, here is the output:
Quote:
Main, before Class
You said... Main calls Test
Main, after Class
So i exported is as a jar, having checked "Export generated class files and resources" and copied it in custom-lib folder from mirth.

Last but not least what i did in mirth.
New channel -> Source: Channel Reader -> Destination: Channel Writer -> in Source i added a new Transformer (JS):
Code:
var myVar = new Packages.blaPackkkk.Test();
logger.info(myVar.execute('Hello'));
-> saved -> deployed -> right cklicked the channel and typed in a sample msg

Here the error:
Quote:
ERROR-300: Transformer error
ERROR MESSAGE: Error evaluating transformer
com.mirth.connect.server.MirthJavascriptTransforme rException:
CHANNEL: Java Final
CONNECTOR: sourceConnector
SCRIPT SOURCE:
SOURCE CODE:
5: msg = new XML(newMessage);
6: if (msg.namespace("") != undefined) { default xml namespace = msg.namespace(""); } else { default xml namespace = ''; }
7: function doFilter() { phase = 'filter'; return true; }function doTransform() { phase = 'transformer'; logger = Packages.org.apache.log4j.Logger.getLogger(phase);
8:
9:
10: var myVar = new Packages.blaPackkkk.Test();
11: logger.info(myVar.execute('Hello'));
12:
13: }
LINE NUMBER: 10
DETAILS: TypeError: [JavaPackage blaPackkkk.Test] is not a function, it is object.
at com.mirth.connect.server.mule.transformers.JavaScr iptTransformer.evaluateScript(JavaScriptTransforme r.java:398)
at com.mirth.connect.server.mule.transformers.JavaScr iptTransformer.transform(JavaScriptTransformer.jav a:296)
at org.mule.transformers.AbstractEventAwareTransforme r.doTransform(AbstractEventAwareTransformer.java:4 8)
at org.mule.transformers.AbstractTransformer.transfor m(AbstractTransformer.java:197)
at org.mule.transformers.AbstractTransformer.transfor m(AbstractTransformer.java:200)
at org.mule.impl.MuleEvent.getTransformedMessage(Mule Event.java:251)
at org.mule.routing.inbound.SelectiveConsumer.isMatch (SelectiveConsumer.java:61)
at org.mule.routing.inbound.InboundMessageRouter.rout e(InboundMessageRouter.java:79)
at org.mule.providers.AbstractMessageReceiver$Default InternalMessageListener.onMessage(AbstractMessageR eceiver.java:487)
at org.mule.providers.AbstractMessageReceiver.routeMe ssage(AbstractMessageReceiver.java:266)
at org.mule.providers.AbstractMessageReceiver.routeMe ssage(AbstractMessageReceiver.java:225)
at com.mirth.connect.connectors.vm.VMMessageReceiver. getMessages(VMMessageReceiver.java:221)
at org.mule.providers.TransactedPollingMessageReceive r.poll(TransactedPollingMessageReceiver.java:108)
at org.mule.providers.PollingMessageReceiver.run(Poll ingMessageReceiver.java:97)
at org.mule.impl.work.WorkerContext.run(WorkerContext .java:290)
at edu.emory.mathcs.backport.java.util.concurrent.Thr eadPoolExecutor.runWorker(ThreadPoolExecutor.java: 1061)
at edu.emory.mathcs.backport.java.util.concurrent.Thr eadPoolExecutor$Worker.run(ThreadPoolExecutor.java :575)
at java.lang.Thread.run(Unknown Source)
But even when i rename the JS code to a package not even existing i get the same error.

Does the jar file need a specific name? i used as input and output types delimited text - except that i dont know what else could be wrong :/

i really appreciate your help, thanks!
Reply With Quote
  #8  
Old 08-12-2011, 12:40 PM
AlexToft AlexToft is offline
OBX.3 Kenobi
 
Join Date: Sep 2010
Location: Leeds, UK
Posts: 160
AlexToft is on a distinguished road
Default

Firstly, I'm a bit of a cut/paste coder when it comes to Java. Ok, I'll be totally honest, I'm pretty crap with Java. I have no problem with the syntax, but I've never learnt the bones of it.

There was a thread some time back on the forum where a chap said "compile a simple class, no main", so I thought I'd give it a try. I gave up on Eclipse (in the Mirth context) in about 10 minutes as it complained like hell about compiling source with no Main. It was probably a config thing but I didn't really investigate it.

I downloaded NetBeans and it built it my simple Java code above without even a whimper. Mirth then ran it no problem.

If you know your way around Java maybe that gives you a clue, but since the only real need I have for Java at present is building odd bits for Mirth I just use NetBeans as it works for me.
Reply With Quote
  #9  
Old 08-16-2011, 11:14 PM
Mr.T Mr.T is offline
OBX.1 Kenobi
 
Join Date: Aug 2011
Posts: 39
Mr.T is on a distinguished road
Default

thanks for your support, but it still wont work :/
would you be so kind and upload your jar file?

with this and the exact code you used it should be possible to work if not i know that i have some other problem.
i was already trying to compile and pack it by command prompt but no success either...

really appreciate your help!
Reply With Quote
  #10  
Old 08-17-2011, 01:58 AM
Mr.T Mr.T is offline
OBX.1 Kenobi
 
Join Date: Aug 2011
Posts: 39
Mr.T is on a distinguished road
Default

would be great if you could also test it the other way around.
i used exactly the same code as you and createt the jar file with netbeans - but still the same problem :/

does the name of the jar file matter? or any other small thing i may miss?
big thx!

here is my jar file:
Attached Files
File Type: jar kA.jar (1.3 KB, 11 views)
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 06:03 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Mirth Corporation