java - 使用 Pentaho PDI (Kettle) 将报告上传到 BA 服务器

标签 java pentaho kettle pentaho-spoon

我目前正在开发一个 Pentaho PDI 项目,我需要将报告上传到 BA/BI 服务器存储库(URL:***/api/repo/publish/file)。我想通过使用 HTTP Post 步骤和生成请求实体字段的用户定义的 Java 类步骤来实现此目的。 但是我没能想出一个有效的代码。由于我的老板不希望我使用外部库,因此我坚持使用使用 Kettle 部署的 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/source/org/pentaho/reporting/libraries/pensol/PublishRestUtil.java

希望这会有所帮助。

关于java - 使用 Pentaho PDI (Kettle) 将报告上传到 BA 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33940607/

相关文章:

java - 等待\n 而不是 EOF C# SslStream

ssl - 如何配置 Pentaho Carte 接受 HTTPS 请求而不是 HTTP

pentaho - 通过 Pentaho 仪表板编辑数据

java - 如何使用java代码访问报表中的元素

Java Servlet 过滤器以及其他对象和实体管理器的范围

java - 如何检测某个 Sprite 是否在特定时间间隔内未被触摸

java - 在大多数情况下我们应该定义 getter setter 吗?

pentaho水壶: get row count from stream

javascript - 使用 Spoon 从数据网格连接

java - Kettle/Pentaho 数据集成 - 无法创建数据库连接(XulException : java. lang.reflect.InvocationTargetException)