I am currently working on a Pentaho PDI project where I need to upload a report to the BA/BI server repository (URL: ***/api/repo/publish/file). I would like to achieve this by using the HTTP Post step and an User Defined Java Class step that produces the request entity field. However I didn't manage to come up with a working code. Since my boss does not want me to use external libraries, I am sticking to the org.apache.commons.httpclient classes which are deployed with kettle. My approach is to create a Part[] array containing the FilePart and StringParts. The next step is to create a MultipartRequestEntity which is then writen to a ByteArrayOutputStream.
File filePart = new File(fileReport);FilePart fileUpload = new FilePart("fileUpload", filePart);
StringPart applyAclPermissions = new StringPart("applyAclPermissions","true");
StringPart overwriteAclPermissions = new StringPart("overwriteAclPermissions","true");
StringPart overwriteFile = new StringPart("overwriteFile", "true");
StringPart logLevel = new StringPart("logLevel","TRACE");
StringPart retainOwnership = new StringPart("retainOwnership", "false");
StringPart fileNameOverride = new StringPart("fileNameOverride","blablub.prpt");
StringPart importDir = new StringPart("importDir", "/public");
Part[] parts = {
fileUpload,
overwriteFile,
logLevel,
retainOwnership,
fileNameOverride,
importDir
};
HttpMethodParams params = new HttpMethodParams();
MultipartRequestEntity requestEntity = new MultipartRequestEntity(
parts, params
);
ByteArrayOutputStream bOutput = new ByteArrayOutputStream();
requestEntity.writeRequest(bOutput);
String requestEntityValue = new String(bOutput.toByteArray());
String contentType = requestEntity.getContentType();
String contentLength = String.valueOf(requestEntity.getContentLength());
Object[] outputRow = createOutputRow(r, data.outputRowMeta.size());
get(Fields.Out, "requestEntityValue").setValue(outputRow, requestEntityValue);
get(Fields.Out, "contentType").setValue(outputRow, contentType);
get(Fields.Out, "contentLength").setValue(outputRow, contentLength);
putRow(data.outputRowMeta, outputRow);
return true;
In the next step the data is sent with the HTTP Post Step. However the server is not satisfied with this approach.
Do you guys have any idea what I am doing wrong?
Thanks for your help!
Since 5.4, there is a special plugin for interacting with BA server: https://github.com/pentaho/pdi-platform-utils-plugin . I highly recommend you to look at it.
As for implementing the upload by yourself, you can either look at the plugin sources or, for instance, this utility from Pentaho Report Designer: https://github.com/pentaho/pentaho-reporting/blob/master/libraries/libpensol/source/org/pentaho/reporting/libraries/pensol/PublishRestUtil.java
Hope this will help.