View Javadoc

1   /*
2    * $$Id: OrderToEmailTransformer.java 12221 2008-07-01 20:04:09Z dfeist $$
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
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  public class OrderToEmailTransformer extends AbstractTransformer
19  {
20      @Override
21      protected Object doTransform(Object src, String encoding) throws TransformerException
22      {
23          Object[] payload = (Object[]) src;
24          Book book = (Book) payload[0];
25          String address = (String) payload[1];
26          String email = (String) payload[2];
27          
28          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          RequestContext.getEventContext().getMessage().setProperty(
34                        MailProperties.TO_ADDRESSES_PROPERTY, email);
35          System.out.println("Sent email to " + email);
36          return body;
37      }
38  }