简体   繁体   中英

Multipart form-data file upload with Camel

I'm trying to setup an Apache Camel route in a Java application where the consumer endpoint is a restlet component that handles an HTTP file upload as a POST of multipart form data and then the producer endpoint forwards the request to a rest service that also accepts multipart form data. I'm new to Camel and can't quite figure out how to wire it up properly. Below is how my route looks so far. Do I need to do any conversion on the body or will the multipart form data be forwarded as is? Can someone provide me some guidance on the proper way to do this or point me to the correct documentation?

    <route id="createentityattachment">
        <from uri="restlet:/EntityAttachments?restletMethod=POST&amp;restletBinding=#queryStringToHeadersRestletBinding"/>

        <camel:recipientList>
            <camel:simple>
                ${header.apigateway}/entityattachments/1.0.0.0/api/v1/EntityAttachments
            </camel:simple>
        </camel:recipientList>
    </route>

I was able to get this working with the below route definition. Note the streamCache="true" attribute on the route. This setting is required for the InputStream to be properly handled in the Exchange. See the Camel docs for more information.

<route id="createentityattachment" streamCache="true">
        <from uri="restlet:/EntityAttachments?restletMethod=POST&amp;restletBinding=#queryStringToHeadersRestletBinding"/>
        <removeHeaders excludePattern="X-eviCore-EntityAttachments*" pattern="^(Camel|Backbase|User-|Accept|Cache|Cookie|breadcrumbId|Host|Connection|DNT|Upgrade-Insecure-Requests|org.restlet.startTime).*$"/>
        <setHeader headerName="CamelHttpMethod">
            <constant>POST</constant>
        </setHeader>
        <to uri="http4://api.innovate.lan:8280/entityattachments/1.0.0.0/api/v1/EntityAttachments"/>
</route>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM