Camel 4 Multipart File upload

52 Views Asked by At

I created an application using Spring boot & apache camel. When I was on Camel 3.x I used this answer to POST a file multipart/form-data file. However since I've upgraded to Camel 4.0.0 it no longer works, when I now try to POST with this HttpEntity as the body I get this error:

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]

From what I've been able to find the required converter was part of the deprecated http4 Camel 2 component. I also believed the main difference between camel-http (which replaced http4) version 3.x and 4.x is that they moved from HttpClient 4 to HttpClient 5. I've been trying various components (like httpmime & camel-mail) but to no avail. Is there an existing component that will allow the conversion of a multipart http entity to an inputstream?

1

There are 1 best solutions below

0
Deddiekoel On

Ok, typical case of don't mix versions with Camel. In the Camel 3 build I had the following dependency:

        <!--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>

This is for the v4 HttpClient and that has the 'org.apache.http.entity.mime.MultipartFormEntity' object. But the Camel 4 camel-http component has the HttpClinet v5 and that has a org.apache.hc.client5.http.entity.mime.MultipartFormEntity object. And guess what there is a converter to get from that to a InputStream.