1 10 11 package org.mule.routing.outbound; 12 13 import org.mule.config.i18n.Message; 14 import org.mule.config.i18n.Messages; 15 import org.mule.impl.endpoint.MuleEndpointURI; 16 import org.mule.umo.UMOException; 17 import org.mule.umo.UMOMessage; 18 import org.mule.umo.UMOSession; 19 import org.mule.umo.endpoint.UMOEndpoint; 20 import org.mule.umo.endpoint.UMOEndpointURI; 21 import org.mule.umo.routing.CouldNotRouteOutboundMessageException; 22 import org.mule.umo.routing.RoutePathNotFoundException; 23 import org.mule.umo.routing.RoutingException; 24 import org.mule.util.TemplateParser; 25 26 import java.util.HashMap ; 27 import java.util.Map ; 28 import java.util.Iterator ; 29 30 41 public class TemplateEndpointRouter extends FilteringOutboundRouter 42 { 43 44 private TemplateParser parser = TemplateParser.createSquareBracesStyleParser(); 46 47 public UMOMessage route(UMOMessage message, UMOSession session, boolean synchronous) 48 throws RoutingException 49 { 50 UMOMessage result = null; 51 if (endpoints == null || endpoints.size() == 0) 52 { 53 throw new RoutePathNotFoundException(new Message(Messages.NO_ENDPOINTS_FOR_ROUTER), message, null); 54 } 55 try 56 { 57 UMOEndpoint ep = (UMOEndpoint)endpoints.get(0); 58 String uri = ep.getEndpointURI().toString(); 59 if (logger.isDebugEnabled()) 60 { 61 logger.debug("Uri before parsing is: " + uri); 62 } 63 Map props = new HashMap (); 64 props.putAll(ep.getProperties()); 67 for (Iterator iterator = message.getPropertyNames().iterator(); iterator.hasNext();) 68 { 69 String propertyKey = (String )iterator.next(); 70 props.put(propertyKey, message.getProperty(propertyKey)); 71 } 72 uri = parser.parse(props, uri); 73 if (logger.isDebugEnabled()) 74 { 75 logger.debug("Uri after parsing is: " + uri); 76 } 77 UMOEndpointURI newUri = new MuleEndpointURI(uri); 78 if (!newUri.getScheme().equalsIgnoreCase(ep.getEndpointURI().getScheme())) 79 { 80 throw new CouldNotRouteOutboundMessageException(new Message( 81 Messages.SCHEME_CANT_CHANGE_FOR_ROUTER_X_X, ep.getEndpointURI().getScheme(), 82 newUri.getScheme()), message, ep); 83 } 84 ep.setEndpointURI(new MuleEndpointURI(uri)); 85 if (synchronous) 86 { 87 result = send(session, message, ep); 88 } 89 else 90 { 91 dispatch(session, message, ep); 92 } 93 } 94 catch (UMOException e) 95 { 96 throw new CouldNotRouteOutboundMessageException(message, (UMOEndpoint)endpoints.get(0), e); 97 } 98 return result; 99 } 100 101 } 102 | Popular Tags |