【发布时间】:2017-12-18 11:01:32
【问题描述】:
这里我尝试将 Json 数据转换为 CSV 格式,最后将此文件发送到 Ofbiz 服务器 api,但是当我在 URL 中发送参数时,api 端点需要一些身份验证内容,我得到了下面的输出。
{"_ERROR_MESSAGE_":"错误调用事件:org.apache.ofbiz.webapp.event.EventHandlerException: 发现 URL 参数 [configId] 通过 uri [uploadAndImportFileFromCSVFile] 传递给安全 (https) 请求映射调用服务 [uploadAndImportFile] 的事件;出于安全原因,这是不允许的!数据应该通过使其成为请求正文(表单字段)而不是请求 URL 的一部分来加密。此外,如果您可以创建一个https://issues.apache.org/jira/browse/OFBIZ-2330 的 Jira 子任务(之前检查此错误的子任务是否不存在)。如果您不确定如何创建 Jira 问题,请查看 https://cwiki.apache.org/confluence/display/OFBIZ/OFBiz+Contributors+Best+Practices 提前谢谢您的帮助。","sessionId":"someId.jvm1","removePathAlias":false,"loggedIn":true,"USERNAME":"__","_LOGIN_PASSED_":"TRUE"," webSiteId":"API"}
之后我使用 MultipartBuilder 在下面发送请求。
exchange.getIn().setHeader("bearer",token);
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
File file =new File("//home/r2/Desktop/ofBizFile/orderFile.csv");
builder.addPart("configId",new StringBody("CON_ID"));
builder.addPart("fileTypeEnumId",new StringBody("CSV_FILE"));
builder.addPart("_uploadedFile_contentType",new StringBody("text/csv"));
builder.addPart("uploadedFile",new FileBody(file));
exchange.getIn().setBody(builder.build());
我也尝试过类似的方法。
exchange.setProperty(Exchange.CHARSET_NAME, "ISO-8859-1");
exchange.getIn().setHeader(Exchange.HTTP_QUERY,"USERNAME=abc&PASSWORD=bc69");
exchange.getIn().setBody("configId=CON_ID&fileTypeEnumId=CSV_FILE");
这是我的骆驼路线
//Route 1
from("couchdb:http://localhost:5984/order")
.process(new JsonToCsvProcessor())
//Storing file into local directory
.to("file:/home/r2/Desktop/ofBizFile?fileExist=append&fileName=order-${date:now:yyyyMMdd}.csv");
.to("direct:jsonToCsv");
//Route 2
from("direct:jsonToCsv")
.setHeader(Exchange.HTTP_QUERY,constant("USERNAME=__&PASSWORD=__"))
//For get token
.to("https4://SomeAddress.com/centerAPI/getAuthenticationToken")
//Get the token and set required parameter for route 3
.process(new ProcessorGetToken())
.to("direct:hold");
//Route 3
from("direct:hold")
.setHeader(Exchange.HTTP_QUERY,constant("USERNAME=__&PASSWORD=__"))
.to("https4://SomeAddress.com/centerAPI/uploadAndImportFileFromCSVFile?throwExceptionOnFailure=false")
//How I know the file is submited successfuly ?
.to("stream:out").end();
所以问题是我如何在 Route2 ProcessorGetToken 中为下一个 Route3 发送数据?
【问题讨论】:
标签: java https apache-camel