我使用 Spring boot 和 apache Camel 创建了一个应用程序。当我使用 Camel 3.x 时,我使用 this answer 来发布文件 multipart/form-data 文件。 然而,自从我升级到 Camel 4.0.0 后,它不再起作用,当我现在尝试使用此 HttpEntity 作为正文进行 POST 时,我收到此错误:
No body available of type: java.io.InputStream but has type: org.apache.http.entity.mime.MultipartFormEntity on: Message[xxx]. Caused by: No type converter available to convert from type: org.apache.http.entity.mime.MultipartFormEntity to the required type: java.io.InputStream. Exchange[xxx]. Caused by: [org.apache.camel.NoTypeConversionAvailableException - No type converter available to convert from type: org.apache.http.entity.mime.MultipartFormEntity to the required type: java.io.InputStream]
据我所知,所需的转换器是已弃用的 http4 Camel 2 组件的一部分。我还相信camel-http(取代了http4)版本3.x和4.x之间的主要区别是它们从HttpClient 4移动到HttpClient 5。我一直在尝试各种组件(如httpmime和camel-mail)但是无济于事。 是否存在允许将多部分 http 实体转换为输入流的现有组件?
好吧,典型的例子是不要与 Camel 混合版本。 在 Camel 3 构建中,我有以下依赖项:
<!--https://mvnrepository.com/artifact/org.apache.httpcomponents/httpmime -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.5.14.redhat-00002</version>
</dependency>
这是针对 v4 HttpClient 的,它具有“org.apache.http.entity.mime.MultipartFormEntity”对象。但是Camel 4的camel-http组件有HttpClinet v5并且有一个org.apache.hc.client5.http.entity.mime.MultipartFormEntity对象。猜猜有什么转换器可以将其转换为输入流。