我目前正在开展Pentaho PDI项目,我需要将报告上传到BA / BI服务器存储库(URL:*** / api / repo / publish / file)。我想通过使用HTTP Post步骤和生成请求实体字段的用户定义Java类步骤来实现此目的。 但是我没有设法提出一个有效的代码。由于我的老板不想让我使用外部库,我坚持使用随水壶部署的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 Step一起发送。但是服务器对这种方法不满意。
你们有什么想法我做错了吗?
感谢您的帮助!
答案 0 :(得分:2)
从5.4开始,有一个特殊的插件可以与BA服务器进行交互:https://github.com/pentaho/pdi-platform-utils-plugin。我强烈建议你去看看。
至于自己实现上传,您可以查看插件源,或者例如Pentaho报表设计器中的此实用程序:https://github.com/pentaho/pentaho-reporting/blob/master/libraries/libpensol/source/org/pentaho/reporting/libraries/pensol/PublishRestUtil.java
希望这会有所帮助。