Reputation: 699
The Http Client
step of pentaho only allows download of text files.
How can I download binary files with Pentaho?
Upvotes: 0
Views: 2005
Reputation: 699
Add a Modified Java Script Value with the following code
var fileURL = "https://hp.imguol.com.br/c/home/b1/2018/05/26/mohamed-salah-chora-apos-se-machucar-em-lance-com-sergio-ramos-1527363329053_300x300.jpg";
var url = java.net.URL(fileURL);
var httpConn = url.openConnection();
// opens input stream from the HTTP connection
var inputStream = httpConn.getInputStream();
var saveFilePath = "d:/myfile10.jpg";
var bis = java.io.BufferedInputStream(inputStream);
var bos = java.io.BufferedOutputStream(java.io.FileOutputStream(java.io.File(saveFilePath)));
var inByte;
while((inByte = bis.read()) != -1) {
bos.write(inByte);
}
bis.close();
bos.close();
Upvotes: 1
Reputation: 699
If you need query a server [e.g. ElasticSearch] with json using JS in Pentaho:
var client = org.apache.http.impl.client.DefaultHttpClient();
var httpPost = org.apache.http.client.methods.HttpPost(url);
//sending a json
var entity = org.apache.http.entity.StringEntity(JSON.stringify(query));
httpPost.setEntity(entity);
//providing a user and password, basic http authentication
client.getCredentialsProvider().setCredentials(org.apache.http.auth.AuthScope.ANY, new org.apache.http.auth.UsernamePasswordCredentials(user, password));
var response = client.execute(httpPost);
if(response.getStatusLine().getStatusCode() < 200 || response.getStatusLine().getStatusCode() >= 400){
throw new ('FALHA NA AUTENTICAÇÃO - VERIFIQUE OS PARAMETROS DE USUÁRIO/SENHA');
}
//if you need write bytes instead of a string go to httpclient documentation
var response = org.apache.http.util.EntityUtils.toString(response.getEntity());
Upvotes: 0