我创建了一个带有 pop3 骆驼路线的 osgi 包,用于阅读邮件。在 servicemix 5.1 中部署时,附件会按预期正确读取。
但是,相同的捆绑包在 FuseEsb-7.1.0.fuse-047-1_2013 中出现问题。骆驼交换中可用的消息内容(在下面的代码片段中,变量contentObject
)显示为“SharedByteArrayInputStream”类型,而不是“javax.mail.Multipart”。
我用谷歌搜索了很多,发现帖子提到了一个相关问题,这是由与 javax.mail 不同的类加载器加载的 javax.activation 引起的。似乎 javax.activation 需要从 javamail 工件中读取 META-INF/mailcap 但它看不到它。最近版本的 javax.mail 似乎已经修复了 MAINFEST 以包括 mailcap,但它似乎仍然出现在 FuseESB 中。
服务组合配置:
- 服务混合版本=5.1
- 骆驼邮件=2.13.2
- 骆驼核心=2.13.2
- javax.mail=Java7
- Javax.activation=Java7
FuseEsb 配置:
- FuseESB 版本=7.1.0
- Camel.mail=2.10.0.fuse-71-047
- 骆驼核=2.10.0.fuse-71-047
- Javax.mail=Java7
- javax.activation=Java7
谁能帮我解决这个问题?下面是读取邮件和骆驼路线的代码片段。如果需要任何进一步的信息来调试问题,请告诉我。谢谢。
代码片段:
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);
}
}
}
骆驼路线代码
<?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>