我目前在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/source/org/pentaho/reporting/libraries/pensol/PublishRestUtil.java

希望这会有所帮助。

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

10-13 03:19