String endpointName;
String prop = expressionConfig.getFullExpression(expressionManager);
if (!expressionManager.isValidExpression(prop))
{
throw new CouldNotRouteOutboundMessageException(
CoreMessages.expressionInvalidForProperty("expression", prop), event, null);
}
Object property = null;
try
{
property = expressionManager.evaluate(prop, event);
}
catch (ExpressionRuntimeException e)
{
logger.error(e.getMessage());
}
if (property == null && getDefaultEndpointName() == null)
{
throw new CouldNotRouteOutboundMessageException(
CoreMessages.expressionResultWasNull(
expressionConfig.getFullExpression(expressionManager)), event, null);
}
else if (property == null)
{
logger.info("Expression: " + prop + " returned null, using default endpoint: " + getDefaultEndpointName());
property = getDefaultEndpointName();
}
if (property instanceof String)
{
endpoints = new ArrayList<Object>(1);
endpoints.add(property);
}
else if (property instanceof List)
{
endpoints = (List<Object>) property;
}
else
{
throw new CouldNotRouteOutboundMessageException(CoreMessages.propertyIsNotSupportedType(
expressionConfig.getFullExpression(expressionManager),
new Class[]{String.class, List.class}, property.getClass()), event, null);
}
List<MuleEvent> results = new ArrayList<MuleEvent>(endpoints.size());
for (Iterator<Object> iterator = endpoints.iterator(); iterator.hasNext();)
{
endpointName = iterator.next().toString();
if (StringUtils.isEmpty(endpointName))
{
throw new CouldNotRouteOutboundMessageException(
CoreMessages.objectIsNull("Endpoint Name: " + expressionConfig.getFullExpression(expressionManager)), event, null);
}
MessageProcessor ep = null;
try
{
ep = lookupEndpoint(endpointName);
if (ep == null)
{
throw new CouldNotRouteOutboundMessageException(CoreMessages.objectNotFound("Endpoint",
endpointName), event, null);
}
MuleEvent result = sendRequest(event, message, ep, true);
if (result != null && !VoidMuleEvent.getInstance().equals(result))
{
results.add(result);
}
}
catch (MuleException e)
{
throw new CouldNotRouteOutboundMessageException(event, ep, e);
}
}
return resultsHandler.aggregateResults(results, event, muleContext);
}