gpt4 book ai didi

java - Camel Exchange 为多部分请求提供空附件

转载 作者:太空宇宙 更新时间:2023-11-04 09:37:12 27 4
gpt4 key购买 nike

我正在通过 postman 向 Camel 休息端点发送多部分/表单数据请求(txt 文件)。在检查交换对象时,attachmenstMap 为 null

Camel 上下文:

<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");

请建议我们如何从交换对象中提取附件。谢谢。

最佳答案

为了将来引用,如果有人遇到这个问题并正在寻找下面的详细信息,请参阅代码片段。

exchange.getIn().getAttachments().forEach((id, dh) -> {
try {
InputStream is = dh.getInputStream();
} catch (IOException e) {
e.printStackTrace();
}

关于java - Camel Exchange 为多部分请求提供空附件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56360464/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com