0

I am submitting a file to a third party api. I can make the request using postman, and the third party accepts the response: example postman request 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:

redacted flow screenshot

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?

Nathan Tregillus
  • 6,006
  • 3
  • 52
  • 91

1 Answers1

1

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"  />
Nathan Tregillus
  • 6,006
  • 3
  • 52
  • 91
afelisatti
  • 2,770
  • 1
  • 13
  • 21
  • what is the content type I should set the Attachment's Content Type? I set it to multipart/form-data, but it failed – Nathan Tregillus May 03 '16 at 17:40
  • I have tried "binary/octet-stream" but I receive the following error: org.mule.api.MessagingException: no object DCH for MIME type binary/octet-stream (javax.activation.UnsupportedDataTypeException). Message payload is of type: NullPayload – Nathan Tregillus May 03 '16 at 17:45
  • I have adjusted my update to use the getInputStream method, thinking this would fix the problem, but now I am just getting a remotely closed. – Nathan Tregillus May 03 '16 at 18:30
  • posted the question in mulesofts forum as well here https://forums.mulesoft.com/questions/41975/pass-file-attachment-from-http-listener-to-http-co.html – Nathan Tregillus May 03 '16 at 20:57
  • Well the attachment already has a Content-Type so you should use that. But in fact, you only want to move it from inbound to outbound, so you should use a ```copy-attachments``` component. You won't need to worry about the Content-Type then. – afelisatti May 04 '16 at 17:15
  • thanks afelisatii. That was what I tried this morning and it worked – Nathan Tregillus May 04 '16 at 17:28