在 Tomcat 中发送带有附件文件的消息时缺少起始边界异常 [英] Missing start boundary Exception when sending messages with an attachment file in Tomcat

查看:26
本文介绍了在 Tomcat 中发送带有附件文件的消息时缺少起始边界异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了许多可能与此问题匹配的方法,但没有一个对我有用.

I've found a number of possible matches to this problem but none that work for me.

我正在使用 Apache Camel 将文件作为电子邮件附件发送.它使用以下 Maven 目标完美运行:

I'm using Apache Camel to deliver a file as an email attachement. It works perfectly using the following maven goals:

码头:运行码头:运行爆炸码头:跑战

jetty:run jetty:run-exploded jetty:run-war

我使用的是 Java 1.6.我的部署容器是 tomcat6.在 tomcat6 和 tomcat7 中,我得到以下异常:

I'm using java 1.6. My deployment container is tomcat6. In tomcat6 and tomcat7 I get the following exception:

org.springframework.mail.MailSendException:失败的消息:javax.mail.MessagingException:缺少起始边界;消息异常详细信息 (1) 是:失败消息 1:javax.mail.MessagingException:缺少起始边界在 javax.mail.internet.MimeMultipart.parsebm(MimeMultipart.java:882)

org.springframework.mail.MailSendException: Failed messages: javax.mail.MessagingException: Missing start boundary; message exception details (1) are: Failed message 1: javax.mail.MessagingException: Missing start boundary at javax.mail.internet.MimeMultipart.parsebm(MimeMultipart.java:882)

网络上的建议表明这是一个类加载器问题.要么是没有找到activation-1.1.jar或者mail-1.4.4.jar文件,要么就是没有找到mail-1.4.4.jar中的mailcap文件.

The advice on the web suggests this is a class loader problem. Its either that the activation-1.1.jar or mail-1.4.4.jar files are not being found, or the mailcap file in mail-1.4.4.jar is not being found.

我已经尝试将这些 jar 文件放在 tomcat/lib 中.我已经尝试将 jar 文件中的 mailcap 复制到爆炸战争的 META-INF 目录中.这些都没有区别.

I've tried putting these jar files in tomcat/lib. I've tried copying the mailcap from the jar file into the META-INF directory of the exploded war. Neither of these make a difference.

版本:

Windows:Apache Tomcat/7.0.5 JDK 1.6.0_27-b07 Apache Camel 2.8.0-fuse-00-08

Windows: Apache Tomcat/7.0.5 JDK 1.6.0_27-b07 Apache Camel 2.8.0-fuse-00-08

Linux - ubuntu 10.04 LTS 附带的版本 - 我稍后会检查这些并添加.

Linux - the versions that come with ubuntu 10.04 LTS - I'll check these later and add.

这是我的骆驼路线的简化版:

This is a simplified version of my camel routes:

<route id="uploadFileForm">
    <from uri="jetty:http://0.0.0.0:9095/premier"/>
    <to uri="velocity:form.html"/>
</route>
<route id="uploadFile">
    <from uri="jetty:http://0.0.0.0:9095/fup"/>
    <to uri="log:mail?showBody=true&amp;showHeaders=true"/>
    <to uri="smtp://localhost"/>
    <setHeader headerName="content-type"><constant>text/plain</constant></setHeader>
    <setBody><constant>Message Sent</constant></setBody>
</route>

这是日志显示的内容:

[4 - seda://mail-ws-audio-files] mail                           INFO  Exchange[ExchangePattern:InOut, Headers:{Connection=Keep-Alive, CamelHttpServletRequest=org.eclipse.jetty.servlets.MultiPartFilter$Wrapper@bb32c5, upfile=D:downloads!37SQFTS.pdf, CamelHttpPath=/fup, subject=BBC Premier League Update - Edition 1, CamelHttpQuery=null, CamelHttpServletResponse=HTTP/1.1 200 

, UntilMessage=until 10:30 GMT when a second bulletin is available (Mon-Fri only), Host=localhost:9095, User-Agent=Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E), Accept-Encoding=gzip, deflate, bulletin_type=am, to=julian.cable@yahoo.com, cc=admin@localhost, breadcrumbId=ID-B1-L0N336601-58958-1335935026761-0-2, CamelHttpUrl=http://localhost:9095/fup, Content-Length=24896, Referer=http://localhost:9095/premier, from=jfbcable@gmail.com, Accept=image/jpeg, application/x-ms-application, image/gif, application/xaml+xml, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*, Accept-Language=en-GB, Content-Type=multipart/form-data; boundary=---------------------------7dc3a8371906f6, CamelHttpUri=/fup, Cache-Control=no-cache, CamelHttpMethod=POST}, BodyType:String, Body:Dear Partner,

    please find attached the latest edition of our file. 

一个最小的Maven 项目示例是这里,战争是此处.如果你在 eclipse 中运行项目或者使用

A minimal example maven project is here and the war is here. If you run the project in eclipse or with

mvn jetty:run

然后使用 http://localhost:9095/premier

您将收到无法联系服务器"异常.但是,如果您将战争部署到 tomcat,您将获得缺少的开始边界异常.如果您编辑 applicationContext.xml 并将 ** 替换为有效值,它实际上会发送一封电子邮件.

You will get a "cannot contact server" exception. But if you deploy the war to tomcat you will get the missing start boundary exception. If you edit applicationContext.xml and replace the ** with valid values, it will actually send an email.

有什么想法吗?

推荐答案

我已经尝试了你的简化骆驼路线示例,它与 mvn jetty:run 配合得很好.

I have tried your simplified camel route sample, it works well with mvn jetty:run.

在我的 Tomcat 7.0.27、Java 6 中,它确实可以工作.邮件已正确发送.唯一的区别是我不使用:

In my Tomcat 7.0.27, Java 6, it actually works. The mail was sent correctly. The only difference is I don't use the:

mvn install

改为使用:

mvn package

然后将target/test-mail-0.0.1-SNAPSHOT.war复制到Tomcat webapps文件夹下,启动tomcat(bin/startup.sh或者bin/startup.bat)

Then copy the target/test-mail-0.0.1-SNAPSHOT.war to the Tomcat webapps folder, and start tomcat (bin/startup.sh or bin/startup.bat).

希望这也适用于您.

我的建议是您选择与我相同的 Tomcat 版本并执行相同的步骤.

My suggestion that you pick the same Tomcat version as I had and follow the same step.

您应该的其他问题来源:

Other source of problem you should:

  1. 检查您是否将环境变量 CATALINA_HOME 或 CATALINA_BASE 设置为指向其他 Tomcat 安装.
  2. 同样在环境变量中,检查您的 JRE_HOME 或 JAVA_HOME(使用 JDK 时)的内容,以及您的 CLASSPATH 变量.您应该将类​​路径设置为 $JAVA_HOME/jre/lib:$JAVA_HOME/jre/lib/ext:.或 %JAVA_HOME%/jre/lib;%JAVA_HOME%/jre/lib/ext;.(最后一个点很重要)
  3. 如果您仅在 JRE 上运行,请将 JAVA_HOME/lib 替换为 JRE_HOME.
  4. 您运行的是哪个版本的 JVM.我使用的是 Oracle JDK 6.您使用的是 OpenJDK/J9 还是其他?

这篇关于在 Tomcat 中发送带有附件文件的消息时缺少起始边界异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆