View Javadoc

1   /*
2    * $Id: SyncVoipBroker.java 7963 2007-08-21 08:53:15Z dirk.olmes $
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.samples.voipservice.service;
12  
13  import org.mule.impl.MuleMessage;
14  import org.mule.impl.RequestContext;
15  import org.mule.samples.voipservice.interfaces.AddressValidation;
16  import org.mule.samples.voipservice.to.CreditProfileTO;
17  import org.mule.samples.voipservice.to.ServiceParamTO;
18  import org.mule.umo.UMOEventContext;
19  import org.mule.umo.UMOMessage;
20  
21  import java.util.HashMap;
22  import java.util.List;
23  import java.util.Map;
24  
25  import org.apache.commons.logging.Log;
26  import org.apache.commons.logging.LogFactory;
27  
28  public class SyncVoipBroker
29  {
30  
31      protected static transient Log logger = LogFactory.getLog(SyncVoipBroker.class);
32  
33      public UMOMessage validate(ServiceParamTO serviceParamTO) throws Exception
34      {
35  
36          logger.info("Inside Method : " + serviceParamTO);
37  
38          UMOMessage msg = null;
39          List endPoints = null;
40          UMOEventContext umoEventContext = RequestContext.getEventContext();
41          UMOMessage umoMessage = umoEventContext.sendEvent(serviceParamTO.getCustomer().getAddress());
42          Integer isValidAddress = (Integer)umoMessage.getPayload();
43          if (isValidAddress.intValue() == AddressValidation.SUCCESS)
44          {
45              umoMessage = umoEventContext.sendEvent(serviceParamTO.getCreditCard().getCardType());
46              endPoints = (List)umoMessage.getPayload();
47              logger.info("Inside Method : isValidAddress = " + isValidAddress + "; endPoints = " + endPoints);
48              Map props = new HashMap();
49              props.put("recipients", endPoints);
50              msg = new MuleMessage(new CreditProfileTO(serviceParamTO.getCustomer()), props);
51              umoEventContext.dispatchEvent(msg);
52              umoEventContext.setStopFurtherProcessing(true);
53          }
54          return msg;
55      }
56  }