web stats
Using Correct Java Sytax in Mirth via Javascript - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 05-05-2015, 09:34 PM
dre4967 dre4967 is offline
OBX.2 Kenobi
 
Join Date: Mar 2011
Posts: 64
dre4967 is on a distinguished road
Default Using Correct Java Sytax in Mirth via Javascript

I'm using a custom library called aspose.words and I running into some trouble making sure I user the correct java classes and javascript syntax in Mirth to properly using Library via Mirth.

I need to know how to translate byte[] buffer and ByteArrayInputStream in Mirth, see snippet of code in Java below.

Mirth Version 3.2


Code:
// The document is stored in byte form in the FileContent column.
    // Retrieve these bytes of the first matching record to a new buffer.
    byte[] buffer = resultSet.getBytes("FileContent");

    // Wrap the bytes from the buffer into a new ByteArrayInputStream object.
    ByteArrayInputStream newStream = new ByteArrayInputStream(buffer);
__________________
Webservice to the end, Mirth
Reply With Quote
  #2  
Old 05-06-2015, 01:57 AM
arpitgoel arpitgoel is offline
Mirth Newb
 
Join Date: Apr 2015
Posts: 8
arpitgoel is on a distinguished road
Default

Please follow the below link for using java code in mirth
http://www.mirthcorp.com/community/w...ode+from+Mirth

You need to copy your custom library jar file in mirthconnect/custom-lib folder and then you can create an object of a class :

Code:
var object = new Packages.org.example.Class1();
var object2 = new Packages.org.example.Class1(<param>);
Reply With Quote
  #3  
Old 05-06-2015, 04:29 AM
dre4967 dre4967 is offline
OBX.2 Kenobi
 
Join Date: Mar 2011
Posts: 64
dre4967 is on a distinguished road
Default

Thanks, I do know how to add the jar in the custom lib and access the java package but I wanted to know for these particular java methods below does anyone know how these would look using them in Mirth. These below are part of the default java library.

// The document is stored in byte form in the FileContent column.
// Retrieve these bytes of the first matching record to a new buffer.
byte[] buffer = resultSet.getBytes("FileContent");

// Wrap the bytes from the buffer into a new ByteArrayInputStream object.
ByteArrayInputStream newStream = new ByteArrayInputStream(buffer);
__________________
Webservice to the end, Mirth
Reply With Quote
  #4  
Old 05-06-2015, 07:30 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,119
narupley is on a distinguished road
Default

The code is almost the same in JavaScript. Except, you should be using "var", because it's JavaScript. Also you need to invoke Java classes using fully-qualified class names, or import the package first.

Code:
    // The document is stored in byte form in the FileContent column.
    // Retrieve these bytes of the first matching record to a new buffer.
    var buffer = resultSet.getBytes("FileContent");

    // Wrap the bytes from the buffer into a new ByteArrayInputStream object.
    var newStream = new java.io.ByteArrayInputStream(buffer);
__________________
Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

Nicholas Rupley
Work: 949-237-6069
Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


- How do I foo?
- You just bar.
Reply With Quote
  #5  
Old 05-06-2015, 08:58 AM
dre4967 dre4967 is offline
OBX.2 Kenobi
 
Join Date: Mar 2011
Posts: 64
dre4967 is on a distinguished road
Default

Thanks narupley, here is my code, I just got this error because I'm working with a Blob data type in SQL. I'm using aspose words library to convert word document from database to a readable format. Looks like when I call getBytes on a blob datatype it is not liking it. I have more code to write but I'm just testing query column that has the binary version of the word document and then using the aspose words library to convert it to readable text.

LINE NUMBER: 162
DETAILS: Can't find method javax.sql.rowset.serial.SerialBlob.getBytes().

importPackage(Packages.com.aspose.words);
importPackage(java.io);


Code:
	var dbConn = DatabaseConnectionFactory.createDatabaseConnection('net.sourceforge.jtds.jdbc.Driver','jdbc:jtds:sqlserver://10.5.18.87:1433/train','sa','amicas2');
	dbSQL =	"SELECT DOC_TEXT from W_PATIENT_DOC_TEXT "
	
	logger.debug ("SQL: " + dbSQL);
	
	var dbResult = dbConn.executeCachedQuery(dbSQL);
	

	while (dbResult.next()) 
	{
		var buffer = dbResult.getBlob("DOC_TEXT").getBytes();
		var newStream = new java.io.ByteArrayInputStream(buffer);
		var doc = new Document(newStream);
		logger.debug(doc.toString(SaveFormat.TEXT));
	}
	
	dbResult.close();
	dbConn.close();
__________________
Webservice to the end, Mirth
Reply With Quote
  #6  
Old 05-11-2015, 11:37 AM
dre4967 dre4967 is offline
OBX.2 Kenobi
 
Join Date: Mar 2011
Posts: 64
dre4967 is on a distinguished road
Default

I don't have this error anymore, after using the primary database source here is the final code. If using Blob type see commented code.


while (dbResult.next())
{
bFound = 1;
mrisReportFound = 1;
//var blob = dbResult.getBlob(4);
//var buffer = blob.getBytes(1,blob.length());
var buffer = dbResult.getBytes(4);
var newStream = new java.io.ByteArrayInputStream(buffer);
var doc = new Document(newStream);
var wordConverted = doc.toString(SaveFormat.TEXT);
//var wordConverted = doc.toString(SaveFormat.HTML);

//BUILD REPORT
fullReport += wordConverted;
}
__________________
Webservice to the end, Mirth
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:32 AM.


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