View Javadoc

1   /*
2    * $Id: OrderManagerBean.java 19191 2010-08-25 21:05:23Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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.test.integration.spring.events;
12  
13  import org.mule.module.spring.events.MuleApplicationEvent;
14  import org.mule.module.spring.events.MuleSubscriptionEventListener;
15  
16  import org.springframework.context.ApplicationEvent;
17  
18  /**
19   * <code>OrderManagerBean</code> receives Order beans from Mule and dispatches
20   * processed results back through Mule via the applicationContext
21   */
22  public class OrderManagerBean extends TestMuleEventBean
23      implements OrderManager, MuleSubscriptionEventListener
24  {
25      private String[] subscriptions;
26  
27      @Override
28      public void onApplicationEvent(ApplicationEvent event)
29      {
30          super.onApplicationEvent(event);
31          // Get the order
32          Order order = (Order)event.getSource();
33          String result = processOrder(order);
34  
35          // Cast the event to a Mule event, we'll use this to get the AppContext
36          MuleApplicationEvent muleEvent = (MuleApplicationEvent)event;
37  
38          // Create a new DefaultMuleEvent. This will be sent to the replyTo
39          // address
40          MuleApplicationEvent returnEvent = null;
41  
42          returnEvent = new MuleApplicationEvent(result, "jms://processed.queue");
43  
44          // Call publish on the application context, Mule will do the rest
45          muleEvent.getApplicationContext().publishEvent(returnEvent);
46      }
47  
48      public String processOrder(Order order)
49      {
50          // Do some processing...
51          return "Order '" + order.getOrder() + "' Processed";
52      }
53  
54      public String[] getSubscriptions()
55      {
56          return subscriptions;
57      }
58  
59      public void setSubscriptions(String[] subscriptions)
60      {
61          this.subscriptions = subscriptions;
62      }
63  
64  }