MessageProcessor mp = routes.get(index);
if (!(mp instanceof ImmutableEndpoint))
{
return routes.get(index);
}
OutboundEndpoint ep = (OutboundEndpoint) mp;
String uri = ep.getAddress();
if (logger.isDebugEnabled())
{
logger.debug("Uri before parsing is: " + uri);
}
Map<String, Object> props = new HashMap<String, Object>();
// Also add the endpoint properties so that users can set fallback values
// when the property is not set on the event
props.putAll(ep.getProperties());
for (String propertyKey : message.getOutboundPropertyNames())
{
Object value = message.getOutboundProperty(propertyKey);
props.put(propertyKey, value);
}
propagateMagicProperties(message, message);
if (!parser.isContainsTemplate(uri))
{
logger.debug("Uri does not contain template(s)");
return ep;
}
else
{
String newUriString = parser.parse(props, uri);
if (parser.isContainsTemplate(newUriString))
{
newUriString = this.getMuleContext().getExpressionManager().parse(newUriString, message, true);
}
if (logger.isDebugEnabled())
{
logger.debug("Uri after parsing is: " + uri);
}
try
{
EndpointURI newUri = new MuleEndpointURI(newUriString, muleContext);
EndpointURI endpointURI = ep.getEndpointURI();
if (endpointURI != null && !newUri.getScheme().equalsIgnoreCase(endpointURI.getScheme()))
{
throw new CouldNotRouteOutboundMessageException(
CoreMessages.schemeCannotChangeForRouter(ep.getEndpointURI().getScheme(),
newUri.getScheme()), event, ep);
}
newUri.initialise();
return new DynamicURIOutboundEndpoint(ep, newUri);