1

In postprocesor script I need call API. I am using this code:

var xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", "http://www.example.com/something", false ); 
xmlHttp.send( null );

I got this error:

ReferenceError: "XMLHttpRequest" is not defined. at 8bb4dae5-0615-4f0c-8e60-26c8614a6bcc_Postprocessor:65 (doScript) at 8bb4dae5-0615-4f0c-8e60-26c8614a6bcc_Postprocessor:71 at com.mirth.connect.server.util.javascript.JavaScriptUtil.executeScript(JavaScriptUtil.java:547) at com.mirth.connect.server.util.javascript.JavaScriptUtil.executePostprocessorScripts(JavaScriptUtil.java:275) at com.mirth.connect.server.transformers.JavaScriptPostprocessor$JavaScriptPostProcessorTask.doCall(JavaScriptPostprocessor.java:104) at com.mirth.connect.server.util.javascript.JavaScriptTask.call(JavaScriptTask.java:113) at java.util.concurrent.FutureTask.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source)


How can I import XMLHttpRequest and using it in postprocesor javascript?

Davidm176
  • 163
  • 1
  • 12

1 Answers1

2

XMLHttpRequest is something specific to web browsers. Mirth Connect uses a JavaScript engine called Mozilla Rhino, which is not a web browser oriented engine (because MC isn't a web browser obviously).

Rhino does however seamlessly integrate with the underlying JVM. Basically anything you can do in Java, you can also do within JavaScript. Use URLConnection instead for example:

var url = new java.net.URL('http://www.google.com');
var conn = url.openConnection();
var is = conn.getInputStream();
try {
    var result = org.apache.commons.io.IOUtils.toString(is, 'UTF-8');
} finally {
    is.close();
}
Nick Rupley
  • 1,028
  • 7
  • 8
  • Nick how do you use the same(mozilla rhino) to export, import or deploy a channel group while using the mirth connect rest api? Is there any good documentation on consuming the mirth connect rest api in the transformers or filters? I have tried to do a lot of research on this but I havent gotten clear documentation, infact this answer is the closest thing I have seen to my quest... @Nick Rupley – Mike Aono Oct 30 '17 at 21:29
  • How to pass POST parameters though before conn.getInputStream()? Thanks – Khodr May 07 '20 at 03:27