web stats
Channel classloader isolation - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 02-27-2020, 02:21 AM
fabreomipih fabreomipih is offline
What's HL7?
 
Join Date: Feb 2020
Posts: 2
fabreomipih is on a distinguished road
Default Channel classloader isolation

Hello,
we are using Mirth 3.5.1
We have developped a corporate Java library library which is packaged as a fatjar and use apache httpclient-4.5.11. This library is located in Mirth custom-lib directory and is used by many channels as a Channel Dependencies / Library resources.
At runtime, it seems that Mirth classloading chooses classes from apache httpclient-4.5.1 from Mirth server-lib directory rather than classes from httpclient-4.5.11 located inside our fatjar.
How can we use httpclient-4.5.11 classes in our custom library ?
Reply With Quote
  #2  
Old 02-28-2020, 08:13 AM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 1,159
agermano is on a distinguished road
Default

Starting with Mirth 3.4 there is a User API class, ContextFactory, which allows you to get an isolatedClassLoader of only the resource libraries assigned to your channel. There is an instance already created for you in javascript as contextFactory. By accessing your library through the isolatedClassLoader, it will use the same ClassLoader to instantiate instances of HttpClient (and it won't be able to see the version already loaded by the application ClassLoader.)

Rhino has a helper for this so that you don't need to mess with reflection.

Code:
var iso = Packages(contextFactory.getIsolatedClassLoader());
// access library using alternate ClassLoader
var myLib = new iso.com.whatever.MyLib();
iso.com.whatever.MyLib.staticMethod();
Reply With Quote
  #3  
Old 03-10-2020, 01:07 AM
fabreomipih fabreomipih is offline
What's HL7?
 
Join Date: Feb 2020
Posts: 2
fabreomipih is on a distinguished road
Default

Many thanks for this quick answer. We will try it asap.
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:41 AM.


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