【发布时间】:2014-02-03 16:33:29
【问题描述】:
请问如何在Mule(3.4.0)中添加文件作为附件?
我尝试了很多解决方案并在 Google 上搜索了很多,但没有找到任何好的解决方案。
这就是我现在所拥有的(发帖前的最后一次尝试):
<sub-flow name="sendBackMail" doc:name="sendBackMail">
<set-attachment attachmentName="changed.xml" value="#[payload]" contentType="text/xml" doc:name="Attachment"/>
<logger message="Attachment ok" level="INFO" doc:name="Logger"/>
<file:file-to-byte-array-transformer doc:name="File to Byte Array"/>
<logger message="Attachment ok. Message: #[message]" level="INFO" doc:name="Logger"/>
<smtps:outbound-endpoint host="${mailSMTP}" port="${mailSendPort}"
user="${mailUser}" password="${mailPass}" to="${receiver}"
from="${mailUser}" responseTimeout="60000" doc:name="SMTP"
connector-ref="SMTP" mimeType="text/xml" subject="msp2bass" >
</smtps:outbound-endpoint>
</sub-flow>
它发送邮件,但我将 xml 文件的内容作为邮件正文。
我应该做什么/更改,以便邮件作为附件发送。我从另一个服务获取文件,对其执行 XSLT,然后我应该将其发送到某个邮件。
我应该提供更多信息吗?
谢谢!
编辑
我如何称呼 bean:
<spring:bean id="SetAttachment" name="SetAttachment" class="si.irose.msp.cust.bass.SetAttachment">
</spring:bean>
<component doc:name="Java">
<spring-object bean="SetAttachment"/>
</component>
Java 类:
package si.irose.msp.cust.bass;
import org.mule.api.MuleEventContext;
import org.mule.api.MuleMessage;
import org.mule.api.lifecycle.Callable;
public class SetAttachment implements Callable{
private MuleMessage mule;
private String name;
@Override
public Object onCall(MuleEventContext eventContext) throws Exception {
mule = eventContext.getMessage();
String tryit="routeid";
for (int i=0;i<mule.getInvocationPropertyNames().toArray().length;i++) {
if (mule.getInvocationPropertyNames().toArray()[i].equals(tryit)) {
name=mule.getInvocationProperty(mule.getInvocationPropertyNames().toArray()[i].toString()).toString();
break;
}
}
mule.addOutboundAttachment(name, mule.getInvocationProperty(name), "text/xml");
return null;
}
}
【问题讨论】:
-
尝试下面的解决方案讨论stackoverflow.com/questions/19523239/…
-
我做了,但没用。至少我的设置不是。我应该插入什么值?