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.async;
8   
9   import org.mule.module.spring.events.MuleApplicationEvent;
10  import org.mule.test.integration.spring.events.Order;
11  import org.mule.test.integration.spring.events.OrderManagerBean;
12  
13  import org.springframework.beans.BeansException;
14  import org.springframework.context.ApplicationContext;
15  import org.springframework.context.ApplicationContextAware;
16  
17  /**
18   * <code>OrderManagerBean</code> receives order beans from Mule and dispatches
19   * process relsults back through Mule via the applicationContext.
20   */
21  public class AsyncOrderManagerBean extends OrderManagerBean
22      implements AsyncOrderManager, ApplicationContextAware
23  {
24      private ApplicationContext applicationContext;
25  
26      /**
27       * We need the application context to send our asyncronous result somewhere
28       * 
29       * @param applicationContext
30       * @throws BeansException
31       */
32      public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
33      {
34          this.applicationContext = applicationContext;
35      }
36  
37      /**
38       * This will be invoked using as a web service. We'll return the result to a
39       * processing queue
40       * 
41       * @param order
42       */
43      public void processOrderAsync(Order order)
44      {
45          // Do some processing...
46          String message = "Order '" + order.getOrder() + "' Processed Async";
47          MuleApplicationEvent returnEvent = null;
48          returnEvent = new MuleApplicationEvent(message, "jms://processed.queue");
49  
50          // Call publish on the application context, Mule will do the rest
51          applicationContext.publishEvent(returnEvent);
52      }
53  }