Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot CamelHttp多部分/表单数据上载。camel-http4和camel http启动器之间的更改_Spring Boot_Apache Camel_Multipartform Data_Spring Camel_Camel Http - Fatal编程技术网

Spring boot CamelHttp多部分/表单数据上载。camel-http4和camel http启动器之间的更改

Spring boot CamelHttp多部分/表单数据上载。camel-http4和camel http启动器之间的更改,spring-boot,apache-camel,multipartform-data,spring-camel,camel-http,Spring Boot,Apache Camel,Multipartform Data,Spring Camel,Camel Http,我有一个SpringBoot应用程序,它使用Camel将多部分/表单数据请求发布到REST端点。请求包括文本部分和文件部分。生成请求的代码如下所示: @Override public void process(Exchange exchange) throws Exception { @SuppressWarnings("unchecked") Map<String, String> body = exchange.getIn().getBody(Map.class)

我有一个SpringBoot应用程序,它使用Camel将多部分/表单数据请求发布到REST端点。请求包括文本部分和文件部分。生成请求的代码如下所示:

@Override
public void process(Exchange exchange) throws Exception {
    @SuppressWarnings("unchecked")
    Map<String, String> body = exchange.getIn().getBody(Map.class);
    String fileName = body.get("FILE_NAME");
    String filePath = body.get("FILE_PATH");
    MultipartEntityBuilder entity = MultipartEntityBuilder.create();
    entity.addTextBody("name", fileName, ContentType.DEFAULT_TEXT);
    entity.addBinaryBody("file", new File(filePath), 
    ContentType.APPLICATION_OCTET_STREAM, fileName);
    exchange.getIn().setBody(entity.build());
}
.to("https4://<endpoint>")
@覆盖
公共作废进程(Exchange)引发异常{
@抑制警告(“未选中”)
Map body=exchange.getIn().getBody(Map.class);
字符串文件名=body.get(“文件名”);
字符串filePath=body.get(“文件路径”);
MultipartEntityBuilder实体=MultipartEntityBuilder.create();
entity.addTextBody(“名称”,文件名,ContentType.DEFAULT_TEXT);
entity.addBinaryBody(“文件”,新文件(文件路径),
ContentType.APPLICATION_八位组_流,文件名);
exchange.getIn().setBody(entity.build());
}
。至(“https4://”)
这段代码工作得很好。 在pom.xml文件中,我正在导入camel-http4组件:

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-http4</artifactId>
    <version>${camel.version}</version>
</dependency>

org.apache.camel


org.apache.camel
骆驼http启动器
${camel.version}
并用http替换所有http4端点,但是上面的代码现在失败了,因为在camel http组件中,HttpEntity和InputStream之间没有可用的类型转换器

我尝试过使用Camel的MIME多部分数据格式:

.setHeader("name", simple("${body[FILE_NAME]}"))
.process(new Processor() {
    @Override
    public void process(Exchange exchange) throws Exception { 
        @SuppressWarnings("unchecked")
        Map<String, String> body = exchange.getIn().getBody(Map.class);
        String filePath = body.get("FILE_PATH");
        exchange.getIn().setBody(new File(filePath));
    }
})
// Add only "name" header in multipart request
.marshal().mimeMultipart("form-data", true, true, "(name)", true)
.to("https://<endpoint>")
.setHeader(“name”,简单(${body[FILE\u name]}”))
.进程(新处理器(){
@凌驾
公共无效进程(Exchange)引发异常{
@抑制警告(“未选中”)
Map body=exchange.getIn().getBody(Map.class);
字符串filePath=body.get(“文件路径”);
exchange.getIn().setBody(新文件(filePath));
}
})
//在多部分请求中仅添加“name”头
.marshal().mimeMultipart(“表单数据”,true,true,”(名称)”,true)
。至(“https://”)
但我不断从服务器收到HTTP 400错误,这意味着它无法理解请求。 所以我的问题是:
如何使用MIME多部分数据格式(或任何其他方式)获得与以前工作代码相同的多部分请求?

您是否也升级到了Camel 3.x?如果您使用的是Camel 2.x,那么您仍然需要
http4
依赖项,我们还没有发布旧版本的网站。有关
2.x
的文档,请参阅github相关分支中的adoc文件。例如,这里是
2.24.x
的文档。Camel 2中的TLDR使用了
Camel-http4-starter
而不是
Camel-httpstarter
您是否也升级到了Camel 3.x?如果您使用的是Camel 2.x,那么您仍然需要
http4
依赖项,我们还没有发布旧版本的网站。有关
2.x
的文档,请参阅github相关分支中的adoc文件。例如,这里是
2.24.x
的文档。Camel 2中的TLDR使用
Camel-http4-starter
代替
Camel-http-starter
.setHeader("name", simple("${body[FILE_NAME]}"))
.process(new Processor() {
    @Override
    public void process(Exchange exchange) throws Exception { 
        @SuppressWarnings("unchecked")
        Map<String, String> body = exchange.getIn().getBody(Map.class);
        String filePath = body.get("FILE_PATH");
        exchange.getIn().setBody(new File(filePath));
    }
})
// Add only "name" header in multipart request
.marshal().mimeMultipart("form-data", true, true, "(name)", true)
.to("https://<endpoint>")