message.setCorrelationGroupSize(recipients.size());
}
}
MuleEvent result = null;
OutboundEndpoint endpoint = null;
MuleMessage request = null;
boolean success = false;
for (Iterator iterator = recipients.iterator(); iterator.hasNext();)
{
request = new DefaultMuleMessage(message.getPayload(), message, muleContext);
try
{
endpoint = getRecipientEndpoint(request, iterator.next());
boolean lastEndpoint = !iterator.hasNext();
// TODO MULE-4476
if (!lastEndpoint && !endpoint.getExchangePattern().hasResponse())
{
throw new CouldNotRouteOutboundMessageException(
MessageFactory.createStaticMessage("The ExceptionBasedRouter does not support asynchronous endpoints, make sure all endpoints on the router are configured as synchronous"), event, endpoint);
}
if (endpoint.getExchangePattern().hasResponse())
{
MuleMessage resultMessage = null;
result = sendRequest(event, request, endpoint, true);
if (result != null)
{
resultMessage = result.getMessage();
}
if (resultMessage != null)
{
resultMessage.applyTransformers(result, endpoint.getResponseTransformers());
}
if (!exceptionPayloadAvailable(resultMessage))
{
if (logger.isDebugEnabled())
{
logger.debug("Successful invocation detected, stopping further processing.");
}
success = true;
break;
}
}
else
{
sendRequest(event, request, endpoint, false);
success = true;
break;
}
}
catch (MuleException e)
{
logger.info("Failed to send/dispatch to endpoint: " + endpoint.getEndpointURI().toString()
+ ". Error was: " + e.getMessage() + ". Trying next endpoint");
}
}
if (!success)