I have created an osgi bundle with a pop3 camel route for reading mails. When deployed in servicemix 5.1, the attachments are getting read properly as expected.
However, the same bundle gives problem in FuseEsb-7.1.0.fuse-047-1_2013.
The contents of message available from within camel exchange(in the code snippet below, the variable contentObject
)
are appearing as of type 'SharedByteArrayInputStream' rather than 'javax.mail.Multipart'.
I Have googled a lot and found posts mentioning a related problem which is caused by javax.activation being loaded by different classloader than javax.mail. Seems like javax.activation needs to read META-INF/mailcap from the javamail artifact but it can't see it. Recent versions of javax.mail seems to have fixed the MAINFEST to include mailcap, but it still seems to occur with FuseESB.
ServiceMix configuration :
- Servicemix version=5.1
- Camel-mail=2.13.2
- Camel-core=2.13.2
- javax.mail=Java7
- Javax.activation=Java7
FuseEsb configuration :
- FuseESB version=7.1.0
- Camel.mail=2.10.0.fuse-71-047
- Camel-core=2.10.0.fuse-71-047
- Javax.mail=Java7
- javax.activation=Java7
Can anyone please help me to resolve this issue ? Below are the code snippet to read the mail and the camel route. Please let me know if any further information is required to debug the problem. Thanks.
Code snippet:
package test.mail.attachment;
import javax.mail.BodyPart;
import javax.mail.Multipart;
import javax.mail.Part;
import javax.mail.internet.MimeMessage;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
public class MyProcessor implements Processor {
public void process(Exchange exchange) throws Exception {
String result = null;
javax.mail.Message message = exchange.getIn().getBody(
javax.mail.Message.class);
if (message instanceof MimeMessage) {
MimeMessage m = (MimeMessage) message;
Object contentObject = m.getContent();
if (contentObject instanceof Multipart) {
Multipart content = (Multipart) contentObject;
int count = content.getCount();
for (int i = 0; i < count; i++) {
BodyPart part = content.getBodyPart(i);
System.out.println(part.getContentType());
if (part.isMimeType("text/plain")) {
result = (String) part.getContent();
break;
}
else
if (part.isMimeType("text/html")) {
result = (String) part.getContent();
}
else
if (part.isMimeType("multipart/alternative")) {
Multipart mp = (Multipart) part.getContent();
String text = null;
for (int i1 = 0; i1 < mp.getCount(); i1++) {
Part bp = mp.getBodyPart(i);
if (bp.isMimeType("text/plain")) {
if (text == null) {
result = (String) bp.getContent();
break;
}
} else if (bp.isMimeType("text/html")) {
result = (String) bp.getContent();
}
}
}
}
}
else
if(contentObject instanceof String) {// a simple text message
result = (String) contentObject;
}
else {
// not a mime message
// logger.log(Level.WARNING,"notme part or multipart {0}",message.toString());
result = null;
}
System.out.println(result);
}
}
}
Camel Route Code
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:osgi="http://www.springframework.org/schema/osgi"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
xmlns:camel="http://camel.apache.org/schema/spring" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd
http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route id="mailreader">
<from
uri="pop3://mydomain?password=password&username=user1@mydomain&mapMailMessage=false&delete=true&unseen=true&consumer.delay=2000" />
<log message="Transforming input file" />
<process ref="myProcessor" />
<to uri="log:myLog" />
</route>
</camelContext>
<bean id="myProcessor" class="test.mail.attachment.MyProcessor" />
</beans>