Reputation: 6186
I am trying to invoke a method (getSubject()) on java payload using MEL. However I am getting exception unable to resolve method: java.lang.String.getSubject() [arglength=0]]. Apparently it is assuming the payload is of type String where as it is of type NotifyVO as shown in the log statement below.
INFO 2013-10-31 15:15:11,382 [[test].sendEmail.stage1.02] org.mule.api.processor.LoggerMessageProcessor: payload : class com.test.NotifyVO
The flow is --
<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 is --
Root Exception stack trace:
[Error: unable to resolve method: java.lang.String.getSubject() [arglength=0]]
[Near : {... payload.getSubject() ....}]
^
Upvotes: 1
Views: 1532
Reputation: 2319
The SMTP transport is transforming your payload to a String in order to make it the body of the e-mail.
The solution for this is to store the subject in a variable prior to the SMTP outbound endpoint and use that variable:
<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" />
Upvotes: 1