web stats
How to make channel to run jar files - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 08-18-2010, 09:28 AM
Dr. L Dr. L is offline
OBX.1 Kenobi
 
Join Date: Aug 2010
Posts: 38
Dr. L is on a distinguished road
Default How to make channel to run jar files

HI there,


I'm consumed with this part of mirth.

Althout I've been researching on how to make a channel to run a jar file executing embebed a batchfile inside of them.



Is it possible to find any how to ?


Thanks in advanced.
Reply With Quote
  #2  
Old 08-18-2010, 09:44 AM
bradd bradd is offline
Mirth Employee
 
Join Date: May 2009
Location: Irvine, CA
Posts: 133
bradd is on a distinguished road
Default

1. put jar into Mirth 1.8.2\lib\custom directory
2. restart Mirth Service
3. use this code:

var object = new Packages.[fully-qualified name]();

example if we had a class dicom in the com.mirth.connectors package of a project:

var object = new Packages.com.mirth.connectors.dicom();
//Then you can call methods from the object
object.doStuff()

-Brad

Last edited by bradd; 08-18-2010 at 09:47 AM.
Reply With Quote
  #3  
Old 08-18-2010, 10:21 AM
Dr. L Dr. L is offline
OBX.1 Kenobi
 
Join Date: Aug 2010
Posts: 38
Dr. L is on a distinguished road
Default Thanks

Hi there,

I've got some doubts where the fully qualified enters ?

And then when you do object.doStuff(); I'm assuming that do stuff could be doteste.


So if the code is :

package QR;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;

public class qr {


public qr(){
final Runtime r = Runtime.getRuntime();
Process p;
try {
p = r.exec(new String[] {"cmd.exe", "/c", "start", "teste.bat"},
null, new File("C:\\teste.bat"));
final PrintWriter writer = new PrintWriter(p.getOutputStream());
writer.println("help");
writer.close();
} catch (final IOException e) {
e.printStackTrace();
}
}
}


Then it would be something like this:

var object = new Packages.QR();
object.doStuff() or object.doQR()


Any help ?

Thanks once again
Reply With Quote
  #4  
Old 08-18-2010, 11:33 AM
bradd bradd is offline
Mirth Employee
 
Join Date: May 2009
Location: Irvine, CA
Posts: 133
bradd is on a distinguished road
Default

since your class is called qr do this:

var object = new Packages.qr();

rather than having all your logic in the constructor of the object why don't you put it in a public method called execute. So it would look like this:

Code:
public qr(){ 
}

public void execute(){
final Runtime r = Runtime.getRuntime(); Process p; try { p = r.exec(new String[] {"cmd.exe", "/c", "start", "teste.bat"}, null, new File("C:\\teste.bat")); final PrintWriter writer = new PrintWriter(p.getOutputStream()); writer.println("help"); writer.close(); } catch (final IOException e) { e.printStackTrace(); } }
}
since your class is called qr do this:

var object = new Packages.qr();
object.execute();

Generally you don't want to have too much logic in your constructor. The code may be poorly formatted, but I'm sure you can fix that up
Reply With Quote
  #5  
Old 08-18-2010, 12:21 PM
Dr. L Dr. L is offline
OBX.1 Kenobi
 
Join Date: Aug 2010
Posts: 38
Dr. L is on a distinguished road
Default Thanks

Thanks once again


I've tried the code that you post but when I try to run with eclipse is says IWAV0048I Java Bean qr.QR started with null constructor.

I think it could be

public qr (){
}

Any help ?
Reply With Quote
  #6  
Old 08-18-2010, 03:09 PM
bradd bradd is offline
Mirth Employee
 
Join Date: May 2009
Location: Irvine, CA
Posts: 133
bradd is on a distinguished road
Default

This should work. If you are having a lot of issues with Mirth and creating custom libraries consider purchasing support and we will walk you through the process.


Code:
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;


public class qr {

	public qr(){
		
	}
	
	public void execute(){
		final Runtime r = Runtime.getRuntime(); 
		Process p; 
		try {
		p = r.exec(new String[] {"cmd.exe", "/c", "start", "teste.bat"}, 
		null, new File("C:\\teste.bat")); 
		final PrintWriter writer = new PrintWriter(p.getOutputStream()); 
		writer.println("help"); 
		writer.close(); 
		} catch (final IOException e) {
		e.printStackTrace();
		}
	}
}
Reply With Quote
  #7  
Old 08-19-2010, 11:56 AM
Dr. L Dr. L is offline
OBX.1 Kenobi
 
Join Date: Aug 2010
Posts: 38
Dr. L is on a distinguished road
Smile Thanks Bradd

Hi there

With the code that you have posted we have an error on mirth.

On eclipse we have a slightly problem saying that

started with null constructor

Posted on eclipse post images (image1.jpg at bottom).

I think we solved that, then we exported like you said.

And then the problem remains on mirth. (posted screenshots on lastpost of the first page).

Did I understood well your question or isn't done anything like this ?

Thanks once agian.
Reply With Quote
  #8  
Old 08-19-2010, 12:58 PM
bradd bradd is offline
Mirth Employee
 
Join Date: May 2009
Location: Irvine, CA
Posts: 133
bradd is on a distinguished road
Default

your problem with Mirth is that the javascript reader needs to return the message. So if the input is xml you need to do a

return "<xml>data</xml>";

I'm not sure what you will need to do if the input is DICOM, it gets a bit tricky. I'm not sure what you are trying to do with DICOM messages so I can't advise you on what to do next.
Reply With Quote
  #9  
Old 08-19-2010, 12:59 PM
Mireth Mireth is offline
OBX.1 Kenobi
 
Join Date: Aug 2010
Posts: 27
Mireth is on a distinguished road
Default jar problem

Hi there,

As for your null constructor problem, hopefully you solved it, but if not you should just get rid of it. I'm 99% sure classes don't always have to have constructors.

As to your channel problem, in my channel which references a java program I used the class name as well in the object declaration. Try this:

var object = new Packages.qr.qr();
object.execute;


Hope that works. Also just so we are clear, does your program run as expected if you run it in eclipse? Thanks for the info.

-Mireth
Reply With Quote
  #10  
Old 08-20-2010, 02:04 AM
Dr. L Dr. L is offline
OBX.1 Kenobi
 
Join Date: Aug 2010
Posts: 38
Dr. L is on a distinguished road
Default Thanks Mireth

Hi Thanks for the help


But I have made that expirience on mrth channel.


var object = new Packages.qr.qr();
object.execute;



Althout and in the response of your last line .

On eclipse the program is runnable and executing like is programmed, althout it does not work on mirth.

Errors


[2010-08-18 13:11:03,890] FATAL (org.mule.impl.DefaultComponentExceptionStrategy:8 4): The error is: null
java.lang.NullPointerException
at com.webreach.mirth.connectors.js.JavaScriptMessage Receiver.poll(JavaScriptMessageReceiver.java:88)
at org.mule.providers.PollingMessageReceiver.run(Poll ingMessageReceiver.java:90)
at org.mule.impl.work.WorkerContext.run(WorkerContext .java:290)
at edu.emory.mathcs.backport.java.util.concurrent.Thr eadPoolExecutor$Worker.runTask(ThreadPoolExecutor. java:650)
at edu.emory.mathcs.backport.java.util.concurrent.Thr eadPoolExecutor$Worker.run(ThreadPoolExecutor.java :675)
at java.lang.Thread.run(Unknown Source)

[2010-08-18 13:09:08,875] FATAL (org.mule.impl.DefaultComponentExceptionStrategy:8 3): The Default Component Exception Strategy has been invoked but there is no current event on the context


[2010-08-18 13:11:23,906] ERROR (com.webreach.mirth.connectors.js.JavaScriptMessag eReceiver:152): org.mozilla.javascript.EcmaError: TypeError: [JavaPackage testefinal] is not a function, it is object. (cd8d54a5-375b-4f02-9951-88025c3fd4d2#3)
Edit/Delete Message


Could it be something wrong with configuration on channel ?
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 11:37 AM.


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