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