1
votes

In flow-1 i.e. in sender, I have two set attachment transformer of type json and text file. I am invoking another application ( receiver) with http requests component. In receiver i am getting this attachment as Inbound attachment payload and not as outbound attachment payload. While sending smtp/email, this attachments gets added and not able to remove it.

I tried by using copy-attachment with wild card name as * and also tried with remove attachment by giving value as message.inboundAttachments['test.json']. I have observed that, all type attachments( set/copy/remove) works for outbound attachment and not for inbound attachments.

1) How do I remove file from inbound attachments? 2) How do get the value of payload in receiver which I have set in sender as 'some data'

code:

sender:

<set-attachment attachmentName="test.json" value="{'Hi':'Hello'}" contentType="text/plain" doc:name="Attachment-JSON"/>
<set-attachment attachmentName="inputdata.json" value="{'k1':'v1','k2':'v2'}" contentType="text/plain" doc:name="Attachment"/>
<set-payload value="#['some data']" doc:name="Set Payload"/>
<http:request config-ref="HTTP_Request_Configuration" path="path2" method="POST" doc:name="HTTP"/>

receiver:

<http:listener config-ref="HTTP_Listener_Configuration" path="path2" allowedMethods="POST" doc:name="HTTP"/>
<foreach collection="#[message.inboundAttachments]" doc:name="For Each">
    <logger message="FileName with key: #[key] ==Initial Payload: ====#[message.payloadAs(java.lang.String)]" level="INFO" doc:name="Logger"/>
</foreach>
<remove-attachment attachmentName="#[message.inboundAttachments'test.json']" doc:name="Attachment"/>
<set-attachment attachmentName="myfile.json" value="#[{'t':'v'}]" contentType="text/plain" doc:name="Attachment-outbound"/>

In the email, i am getting 3 attachments. debug-values

Mule version: 3.8

1

1 Answers

0
votes

Inbound properties in Mule cannot be removed because they are immutable. Inbound attachments are probably no exception to this rule. As per Mule doc on message structure:

Inbound properties are immutable, are automatically generated by the message source and cannot be set or manipulated by the user.

For your second point, it strange that your payload does not get carried through the HTTP Endpoint. The payload on receiver seems to be NullPayload where you explicitely set "some data" before calling. Try to set <set-payload value="some data" doc:name="Set Payload"/> instead, without using MEL expression, and add a logger showing #[payload] right before your HTTP call on sender side make sure the payload is properly set. I'll edit my answer accordingly.