How to read multiple attachments with the same file name

I have a Java Maven project and I use org.apache.camel to get information about mail and attachments.

 <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-mail</artifactId> <version>2.17.0</version> </dependency> 

Given the Exchange object, I use this code to get attachments:

 Message message = exchange.getIn().copy(); message.getAttachments() 

Where messageCopy.getAttachments() returns a Map<String, DataHandler> , which maps the attachment-file-Name to a DataHandler .

This code works when mail has one attachment or attachments, whose names are named differently. When I have two attachments with the same name, this means that due to the structure of the map, only one is returned (the other is simply overwritten).

Does anyone have the same problem and / or know a different method of getting two (or more) investments of the same name?

thanks

+7
java apache-camel
source share
1 answer

I remembered having encountered this problem in my previous project. I think a workaround was to split the original message into N separate messages so that you can process each one, even if it has the same name.

Take a look at the Camel SplitAttachmentsExpression . Existing unit test can be found here .

0
source share

All Articles