Question

For the project I am working on I have to handle xml messages with attachments, so called multipart messages like these: http://www.w3.org/TR/2000/NOTE-SOAP-attachments-20001211

My goal is to remove the attachments and only leave the xml as the payload.

I have been looking into the attachment-related methods from class MuleMessage and DefaultMuleMessage, but I can't get this to work. I hope someone can give me a hint on how I can get these methods to work.

When I send a message with an attachment from SoapUI, I can log the message with getPayloadForLogging() and see that it is a multipart message with multiple Mime boundaries, like this:

------=_Part_9_4557707.1396945202422
Content-Type: text/xml; charset=UTF-8
Content-Transfer-Encoding: 8bit
Content-ID: <rootpart@soapui.org>

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://microsoft.com/webservices/">
<soapenv:Header/>
<soapenv:Body>
</soapenv:Body>
</soapenv:Envelope>
------=_Part_9_4557707.1396945202422
Content-Type: image/x-png
Content-Transfer-Encoding: binary
Content-ID: <soapui32.png>
Content-Disposition: attachment; name="soapui32.png"

PNG
xxxxxxx
------=_Part_9_4557707.1396945202422-- 

I have created a custom transformer:

@Override
public Object transformMessage(MuleMessage message, String outputEncoding)
        throws TransformerException {

    DefaultMuleMessage newMessage = new DefaultMuleMessage(message);

    logger.info("attachments: " + newMessage.getInboundAttachmentNames().toString());

    return newMessage;
}

When I pass the above multipart message through it, I get an empty Set from getInboundAttachmentNames().

When I try removeOutboundAttachment("*") it doesn't remove the attachment.

When I try to create a message with an attachment using:

String payload = TestUtilities.readFile("testdata/test1.xml");
DefaultMuleMessage msg = new DefaultMuleMessage(payload, muleContext);
msg.addOutboundAttachment("plaatje", new File("testdata/test1.png"), "image/png"); 
MuleMessage reply = client.send("vm://test_01", msg, 5000);

it creates a message, but it doesn't have an attachment. And it isn't a multipart message.

Am I mistaken in using the attachment methods for multipart messages? Am I doing something wrong?

Thanks, Jeroen

Was it helpful?

Solution

When an attachment is received into a flow along with its associated message, it is considered an inbound property

http://www.mulesoft.org/documentation/display/current/Attachment+Transformer+Reference

So, you should use getInboundAttachmentNames to print out the attachment names.

UPDATE:

Found this Jira ticket. It is still unresolved, which would suggest that the attachment methods do not work for Multipart/Related.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top