Using Apache HttpClient to HTTP GET a resource and stream it directly to a file - rbeckman-nextgen/test-mc GitHub Wiki
Created by Roy Feague, last modified on Mar 19, 2010
Here's a javascript transformer step I created to get a file via HTTP
GET using Apache HttpClient v4.0.1.
It shows how to:
- make calls to Java using importPackage instead of using the fully-qualified name on every object reference
- take advantage of the Entity functions HttpClient 4.0 to stream directly to your target file
In order for this to work, you must first download the HttpClient jar files WITH DEPENDENCIES and put them into the your C:\Program Files\Mirth\lib\custom folder. (See http://hc.apache.org/downloads.cgi)
importPackage(Packages.org.apache.http.client);
importPackage(Packages.org.apache.http.client.methods);
importPackage(Packages.org.apache.http.impl.client);
var httpclient = new DefaultHttpClient();
var httpget = new HttpGet('http://myserver/mypath');
var response = httpclient.execute(httpget);
var entity = response.getEntity();
if (entity != null) {
var fos = new java.io.FileOutputStream('c:\\temp\\myfile.ext');
entity.writeTo(fos);
fos.close();
}
Can this method be used to connect to a secure URL requiring a username and password? ![]() |
Document generated by Confluence on Nov 11, 2019 08:40