简体   繁体   English

使用Pentaho PDI(水壶)将报告上传到BA服务器

[英]Upload report to BA server with Pentaho PDI (Kettle)

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). 我目前在Pentaho PDI项目上工作,需要将报告上载到BA / BI服务器存储库(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. 我想通过使用HTTP Post步骤和生成请求实体字段的User Defined Java Class步骤来实现这一点。 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. 由于老板不希望我使用外部库,因此我坚持使用与水壶一起部署的org.apache.commons.httpclient类。 My approach is to create a Part[] array containing the FilePart and StringParts. 我的方法是创建一个包含FilePart和StringParts的Part []数组。 The next step is to create a MultipartRequestEntity which is then writen to a ByteArrayOutputStream. 下一步是创建一个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;

In the next step the data is sent with the HTTP Post Step. 在下一步中,将通过HTTP Post步骤发送数据。 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 . 从5.4开始,有一个用于与BA服务器交互的特殊插件: 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 至于您自己实现上传,您可以查看插件源,也可以例如从Pentaho Report Designer查看此实用程序: https : //github.com/pentaho/pentaho-reporting/blob/master/libraries/libpensol/来源/org/pentaho/reporting/libraries/pensol/PublishRestUtil.java

Hope this will help. 希望这会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM