[英]Upload report to BA server with Pentaho PDI (Kettle)
我目前在Pentaho PDI項目上工作,需要將報告上載到BA / BI服務器存儲庫(URL:*** / api / repo / publish / file)。 我想通過使用HTTP Post步驟和生成請求實體字段的User Defined Java Class步驟來實現這一點。 但是,我沒有想出一個有效的代碼。 由於老板不希望我使用外部庫,因此我堅持使用與水壺一起部署的org.apache.commons.httpclient類。 我的方法是創建一個包含FilePart和StringParts的Part []數組。 下一步是創建一個MultipartRequestEntity,然后將其寫入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;
在下一步中,將通過HTTP Post步驟發送數據。 但是服務器對這種方法不滿意。
你們知道我在做什么錯嗎?
謝謝你的幫助!
從5.4開始,有一個用於與BA服務器交互的特殊插件: https : //github.com/pentaho/pdi-platform-utils-plugin 。 我強烈建議您看一下。
至於您自己實現上傳,您可以查看插件源,也可以例如從Pentaho Report Designer查看此實用程序: https : //github.com/pentaho/pentaho-reporting/blob/master/libraries/libpensol/來源/org/pentaho/reporting/libraries/pensol/PublishRestUtil.java
希望這會有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.