{
data = message.getPayloadAsBytes();
}
catch (Exception e)
{
throw new RoutingException(CoreMessages.failedToReadPayload(), event, getRoute(0, event), e);
}
int parts = data.length / messageSize;
if ((parts * messageSize) < data.length)
{
parts++;
}
int len = messageSize;
MuleMessage part;
int count = 0;
int pos = 0;
byte[] buffer;
try
{
for (; count < parts; count++)
{
if ((pos + len) > data.length)
{
len = data.length - pos;
}
buffer = new byte[len];
System.arraycopy(data, pos, buffer, 0, buffer.length);
pos += len;
part = new DefaultMuleMessage(buffer, message, muleContext);
part.setCorrelationId(message.getUniqueId());
part.setCorrelationGroupSize(parts);
part.setCorrelationSequence(count);
if (logger.isInfoEnabled())
{
logger.info(String.format("sending part %d of %d (seq # %d)", count + 1, parts, count));
}
super.route(new DefaultMuleEvent(part, event.getEndpoint(), session));
if (logger.isInfoEnabled())
{
logger.info("sent");
}
}
}
catch (RoutingException e)
{
// we'll want to send the whole message to the Exception handler
e = new RoutingException(e.getI18nMessage(), e.getEvent(), e.getRoute(), e.getCause());
// e.addInfo("chunking", "true");
// buffer = new byte[data.length - len];
// System.arraycopy(data, len, buffer, 0, buffer.length);
// e.addInfo("remaining data", buffer);
throw e;