[英]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.