1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.example.bookstore; |
12 | |
|
13 | |
import org.mule.RequestContext; |
14 | |
import org.mule.api.transformer.TransformerException; |
15 | |
import org.mule.transformer.AbstractTransformer; |
16 | |
import org.mule.transport.email.MailProperties; |
17 | |
|
18 | 0 | public class OrderToEmailTransformer extends AbstractTransformer |
19 | |
{ |
20 | |
@Override |
21 | |
protected Object doTransform(Object src, String encoding) throws TransformerException |
22 | |
{ |
23 | 0 | Object[] payload = (Object[]) src; |
24 | 0 | Book book = (Book) payload[0]; |
25 | 0 | String address = (String) payload[1]; |
26 | 0 | String email = (String) payload[2]; |
27 | |
|
28 | 0 | String body = "Thank you for placing your order for " + |
29 | |
book.getTitle() + " with Mule Bookstore. " + |
30 | |
"Your order will be shipped to " + |
31 | |
address + " by 3 PM today!"; |
32 | |
|
33 | 0 | RequestContext.getEventContext().getMessage().setProperty( |
34 | |
MailProperties.TO_ADDRESSES_PROPERTY, email); |
35 | 0 | System.out.println("Sent email to " + email); |
36 | 0 | return body; |
37 | |
} |
38 | |
} |