KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > providers > jbi > components > MuleDispatcher


1 /*
2  * $Id: MuleDispatcher.java 3798 2006-11-04 04:07:14Z aperepel $
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 MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.providers.jbi.components;
12
13 import org.mule.impl.MuleEvent;
14 import org.mule.impl.MuleSession;
15 import org.mule.providers.AbstractConnector;
16 import org.mule.providers.jbi.JbiUtils;
17 import org.mule.umo.UMOEvent;
18 import org.mule.umo.UMOMessage;
19 import org.mule.umo.provider.UMOMessageDispatcher;
20
21 import javax.jbi.messaging.MessageExchange;
22 import javax.jbi.messaging.MessagingException;
23 import javax.jbi.messaging.NormalizedMessage;
24
25 /**
26  * Is a Jbi component that can dispatch Normalised Messages over a given transport
27  * specified by the muleEndpoint property. This component can deliver events over any
28  * Mule transport such as jms, ftp, htp, jdbc, ejb, etc
29  *
30  * @author <a HREF="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
31  * @version $Revision: 3798 $
32  */

33 public class MuleDispatcher extends AbstractEndpointComponent implements MessageExchangeListener
34 {
35
36     public void onExchange(MessageExchange messageExchange) throws MessagingException
37     {
38         if (logger.isDebugEnabled())
39         {
40             logger.debug("In Mule Dispatcher");
41         }
42         try
43         {
44             UMOMessageDispatcher dispatcher = muleEndpoint.getConnector().getDispatcher(muleEndpoint);
45             NormalizedMessage out = messageExchange.getMessage(IN);
46             UMOMessage message = JbiUtils.createMessage(out);
47             if (logger.isDebugEnabled())
48             {
49                 logger.debug("Dispatching Message via Mule: " + message);
50             }
51             MuleSession session = new MuleSession(message,
52                 ((AbstractConnector)muleEndpoint.getConnector()).getSessionHandler());
53
54             UMOEvent event = new MuleEvent(message, muleEndpoint, session, muleEndpoint.isSynchronous());
55             if (muleEndpoint.isSynchronous())
56             {
57                 logger.debug("Dispatching to: " + muleEndpoint.getEndpointURI());
58                 logger.debug("Payload is: " + event.getMessageAsString());
59
60                 UMOMessage result = dispatcher.send(event);
61                 // TODO send result back
62
}
63             else
64             {
65                 dispatcher.dispatch(event);
66             }
67         }
68         catch (Exception JavaDoc e)
69         {
70             handleException(e);
71             error(messageExchange, e);
72         }
73     }
74 }
75
Popular Tags