Announcement

Collapse
No announcement yet.

Call a java class with native methods

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Call a java class with native methods

    I'm new of Mirth.
    I would call a java class with native methods from a javascript (for example).
    I have build a test channel:
    source --> llplistener
    destination --> file writer

    I have create a javascript transformer on source in which I would to call
    a native method.
    Code:
    /* dummy code */
    var o1 = new Packages.java.lang.Integer(100);
    globalMap.put('myInt', o1);
    
    /* instance my class with native methods */
    var object = new Packages.my.myclass("myString"«»);
    
    /* call native method */
    ....
    Code:
    public class myclass(){
      public native int nativeMethod1();
      public native int nativeMethod2();
      public native int nativeMethod3(String properties);
    }
    The channel doesn't send any message. It seem to do nothing (Is it blocked on instantiation of myclass?)

    If I remove the code that instance my class, than the channel write correctly
    on my file.txt the variable "myInt" (trivial channel for my test).

    If I remove native methods from myclass and create myclass, than the channel write correctly again.

    There is a problem with native libraries and methods?

    I hope to be clear.

    thanks for help

    andrea

  • #2
    Re:Call a java class with native methods

    Add some information:
    SO: windows
    Code of myclass:

    Code:
    public class myclass(){
    
      public native int nativeMethod1();
    
      public native int nativeMethod2();
    
      public native int nativeMethod3(String properties);
    
      static {
        System.loadLibrary("native_dll"«»);
      }
    }
    If I remove System.loadLibrary("mylib.dll") (not native methods) from myclass and create myclass within transformer, than the channel write correctly again.

    The environment variable PATH contains the path of mylib.dll

    Comment


    • #3
      Re:Call a java class with native methods

      I found it.

      With a example global script:
      Code:
      // This script executes once when the mule engine is started
      // You only have access to the globalMap here to persist data
      
      java.lang.System.out.println("inizio"«»);
      java.lang.System.out.println("java.library.path:" + " " 
         + java.lang.System.getProperty("java.library.path"«»));
      
      java.lang.System.loadLibrary("J2Acu"«»);
      java.lang.System.out.println("fine"«»);
      
      return;
      When I start the server mirth logs standard out and stacktrace in ./logs/wrapper.conf
      (in javascript mirth doesn't log anything, it only block the channel). With stacktrace I could see the problem (Exception in thread "Thread-0" java.lang.UnsatisfiedLinkError: no J2Acu in java.library.path
      ....
      ....)!!!
      I found that Mirth set java.library.path at value "./lib"
      I put my library in ./lib and all run.
      I hope to have been useful.
      Regards

      Comment


      • #4
        Re:Call a java class with native methods

        Cool!

        Thanks for posting your code, I'm sure it will help someone else.
        Jon Bartels

        Zen is hiring!!!!
        http://consultzen.com/careers/
        Talented healthcare IT professionals wanted. Engineers to sales to management.
        Good benefits, great working environment, genuinely interesting work.

        Comment

        Working...
        X