我正在通过邮递员将多部分/表单数据请求(txt文件)发送到骆驼休息端点。 检查交换对象时,attachmenstMap显示为空
骆驼语境:
<camelContext id="batch2" xmlns="http://camel.apache.org/schema/spring">
<!-- List of Beans which extend RouteBuilder class-->
<routeBuilder ref="miscRoute"/>
<routeBuilder ref="batchRoute"/>
<!-- REST Configuration -->
<!-- Make sure your contextPath here matches web.xml -->
<restConfiguration component="servlet" bindingMode="json" contextPath="rest" port="8080" enableCORS="true">
<dataFormatProperty key="prettyPrint" value="true"/>
</restConfiguration>
</camelContext>
BatchRoute扩展了AbstractRouteBuilder:
@Override
public void configure() {
super.configure();
rest("/batch")
.id("createBatch").tag("createBatch")
.produces(MediaType.APPLICATION_JSON)
.consumes(MediaType.MULTIPART_FORM_DATA)
.description("Create Batch")
.post()
.bindingMode(RestBindingMode.off)
.param()
.name(ApiParameter.BATCH_FILE.toString())
.type(RestParamType.formData)
.description(ApiParameter.BATCH_FILE.getDescription())
.dataType(ApiParameter.BATCH_FILE.getType())
.endParam()
.outType(CreateBatchResponse.class)
.route().removeHeader(Exchange.HTTP_PATH)
.streamCaching("false")
.process(new CreateBatchRequestProcessor())
.process(exchange -> {
Map<String, DataHandler> attachmentsMap = exchange.getIn().getAttachments();
})
.to(ENDPOINT_REQUEST_BATCH2_CREATE_BATCH)
.endRest();
AbstractRouteBuilder扩展了RouteBuilder:
@Override
public void configure() {
restConfiguration()
.component("servlet")
.port("8080")
.contextPath("rest")
.endpointProperty("attachmentMultipartBinding", "true");
请提出建议,因为我们如何从交换对象中提取附件。 谢谢。
答案 0 :(得分:0)
供以后参考,如果有人遇到此问题并在下面查找详细信息,则为代码段。
exchange.getIn().getAttachments().forEach((id, dh) -> {
try {
InputStream is = dh.getInputStream();
} catch (IOException e) {
e.printStackTrace();
}