Reputation: 6334
I am submitting a file to a third party api. I can make the request using postman, and the third party accepts the response:
my mule flow starts with a http request, and I am able to send the file in the message.inboundAttachments dictionary, but I am not sure how to build the request to the third party in a mule flow. When I try to set the message.InboundAttachment['Contract'] item into the payload, I just get a generic message:
"Error sending HTTP request. Message payload is of type: DataHandler"
I am not sure what is failing.
update below is a screenshot of the part of the flow I attempted with using the attachment component:
the attachment component looks like the following:
<set-attachment attachmentName="#[message.inboundAttachments.Contract.dataSource.part.fileName]" value="#[message.inboundAttachments['Contract'].getInputStream()]" contentType="multipart/form-data" doc:name="Attaching Contract"/>
I am getting the following error though when I attempt to send this:
> ERROR 2016-05-03 11:26:45,597
> [[pan.internal.api].api-httpListenerConfig.worker.01]
> org.mule.exception.DefaultMessagingExceptionStrategy:
> ******************************************************************************** Message : Error sending HTTP request. Message payload is
> of type: NullPayload Type :
> org.mule.api.MessagingException Code : MULE_ERROR--2
> JavaDoc :
> http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html
> Payload : {NullPayload}
> ******************************************************************************** Exception stack is:
> 1. Remotely closed (java.io.IOException)
> 2. java.io.IOException: Remotely closed (java.util.concurrent.ExecutionException)
> org.glassfish.grizzly.impl.SafeFutureImpl$Sync:349 (null)
> 3. java.util.concurrent.ExecutionException: java.io.IOException: Remotely closed (java.io.IOException)
> org.mule.module.http.internal.request.grizzly.GrizzlyHttpClient:245
> (null)
> 4. Error sending HTTP request. Message payload is of type: NullPayload (org.mule.api.MessagingException)
> org.mule.module.http.internal.request.DefaultHttpRequester:287
> (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html)
> ******************************************************************************** Root Exception stack trace: java.io.IOException: Remotely closed
>
> ********************************************************************************
I have also tried to clear the Attachment Content Type field, but it seems to be required, and raises an error as well. Any ideas?
Upvotes: 0
Views: 908
Reputation: 2835
You don't need to add the attachment as payload for the request, what you need to do is move it from InboundAttachments to OutboundAttachments. The requester component will detect there are OutboundAttachments present and perform a multipart/form-data request with them.
HTH
update the copy-attachments will correctly set the content-length and pass through the contents, rather than setting the attachment:
<copy-attachments attachmentName="Contract" doc:name="Attaching Contract" />
Upvotes: 1