我正在尝试使用 MEL 在 Java 负载上调用方法 (getSubject())。但是我遇到异常无法解析方法:java.lang.String.getSubject() [arglength=0]]。显然,它假设有效负载是 String 类型,而实际上它是 NotifyVO 类型,如下面的日志语句所示。
INFO 2013-10-31 15:15:11,382 [[test].sendEmail.stage1.02] org.mule.api.processor.LoggerMessageProcessor:有效负载:类 com.test.NotifyVO
流程是——
<flow name="sendEmail" doc:name="sendEmail">
<vm:inbound-endpoint exchange-pattern="one-way"
path="send-email-vm" doc:name="VM" />
<logger level="INFO" doc:name="Logger" message="payload : #[payload.getClass()]"/>
<smtp:outbound-endpoint connector-ref="smtpGmailConnector"
host="${email.host}" port="${email.port}" user="${email.user}"
subject="#[payload.getSubject()]" password="${email.password}"
doc:name="SMTP" />
</flow>
异常(exception)是——
Root Exception stack trace:
[Error: unable to resolve method: java.lang.String.getSubject() [arglength=0]]
[Near : {... payload.getSubject() ....}]
^
最佳答案
SMTP 传输会将您的有效负载转换为字符串,以便使其成为电子邮件的正文。
解决方案是将主题存储在 SMTP 出站端点之前的变量中并使用该变量:
<logger level="INFO" doc:name="Logger" message="payload : #[payload.getClass()]"/>
<set-variable variableName="subject" value="#[payload.getSubject()]" />
<smtp:outbound-endpoint connector-ref="smtpGmailConnector"
host="${email.host}" port="${email.port}" user="${email.user}"
subject="#[flowVars['subject']]" password="${email.password}"
doc:name="SMTP" />
关于java - 使用 MEL 在 Java 负载上调用方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19715981/