View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.test.integration.spring.events;
8   
9   import org.mule.module.spring.events.MuleApplicationEvent;
10  import org.mule.module.spring.events.MuleSubscriptionEventListener;
11  
12  import org.springframework.context.ApplicationEvent;
13  
14  /**
15   * <code>OrderManagerBean</code> receives Order beans from Mule and dispatches
16   * processed results back through Mule via the applicationContext
17   */
18  public class OrderManagerBean extends TestMuleEventBean
19      implements OrderManager, MuleSubscriptionEventListener
20  {
21      private String[] subscriptions;
22  
23      @Override
24      public void onApplicationEvent(ApplicationEvent event)
25      {
26          super.onApplicationEvent(event);
27          // Get the order
28          Order order = (Order)event.getSource();
29          String result = processOrder(order);
30  
31          // Cast the event to a Mule event, we'll use this to get the AppContext
32          MuleApplicationEvent muleEvent = (MuleApplicationEvent)event;
33  
34          // Create a new DefaultMuleEvent. This will be sent to the replyTo
35          // address
36          MuleApplicationEvent returnEvent = null;
37  
38          returnEvent = new MuleApplicationEvent(result, "jms://processed.queue");
39  
40          // Call publish on the application context, Mule will do the rest
41          muleEvent.getApplicationContext().publishEvent(returnEvent);
42      }
43  
44      public String processOrder(Order order)
45      {
46          // Do some processing...
47          return "Order '" + order.getOrder() + "' Processed";
48      }
49  
50      public String[] getSubscriptions()
51      {
52          return subscriptions;
53      }
54  
55      public void setSubscriptions(String[] subscriptions)
56      {
57          this.subscriptions = subscriptions;
58      }
59  
60  }