1

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&amp;username=user1@mydomain&amp;mapMailMessage=false&amp;delete=true&amp;unseen=true&amp;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>
  • How should we be able to help you if you don't show us any code? – Peter Keller Sep 26 '14 at 14:05
  • Hi Peter, Sorry for the incovenience. I have updated the description. Request you to please have a look at it. Thanks. – Sneha Thigale Sep 29 '14 at 12:17
  • Looks like the problem is similar as the issue reported in [MR-625](https://issues.jboss.org/browse/MR-625) – Shailesh Pratapwar Sep 29 '14 at 14:51
  • Yes, [MR-625](https://issues.jboss.org/browse/MR-625) is the similar problem. And as per [this comment](https://issues.jboss.org/browse/MR-625?focusedCommentId=12848676&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-12848676), the issue should have been fixed in fuse version 7.0.1. However, [this regression issue](https://issues.jboss.org/browse/ENTESB-698) prevents this. – Sneha Thigale Sep 30 '14 at 14:11
  • From the comments in MR-625 & ENTESB-698, I have tried certain things and following setup seems to working for me. 1) Comment the line containing 'javax.activation' for each jre version in fuse_home/etc/jre.properties 2) Copied org.apache.servicemix.specs.activation-api-1.1.jar (Downloaded from maven repo) to fuse_home/lib/endorsed directory. With this setup, the camel exchange IN has attachments available within it. I can even parse the content part by part. However, **Could anyone please confirm, whether this is the right approach ?** – Sneha Thigale Sep 30 '14 at 14:21

0 Answers0