use of org.mule.runtime.core.privileged.routing.RoutingException in project mule by mulesoft.
the class EventCorrelatorMemoryLeakTestCase method testEventGroupFreedInRoutingException.
@Test
public void testEventGroupFreedInRoutingException() throws Exception {
CoreEvent event = mock(CoreEvent.class);
try {
eventCorrelator.process(event);
fail("Routing Exception must be catched.");
} catch (RoutingException e) {
assertTrue("Event Group wasn't saved", eventGroupWasSaved);
assertThat(countOfEventGroups, is(0));
}
}
use of org.mule.runtime.core.privileged.routing.RoutingException in project mule by mulesoft.
the class AbstractOutboundRouter method process.
@Override
public CoreEvent process(final CoreEvent event) throws MuleException {
ExecutionTemplate<CoreEvent> executionTemplate = createTransactionalExecutionTemplate(muleContext, getTransactionConfig());
ExecutionCallback<CoreEvent> processingCallback = () -> {
try {
return route(event);
} catch (RoutingException e1) {
throw e1;
} catch (Exception e2) {
throw new RoutingException(AbstractOutboundRouter.this, e2);
}
};
try {
return executionTemplate.execute(processingCallback);
} catch (MuleException e) {
throw e;
} catch (Exception e) {
throw new DefaultMuleException(e);
}
}
use of org.mule.runtime.core.privileged.routing.RoutingException in project mule by mulesoft.
the class ExceptionsTestCase method testRoutingExceptionNullMessageValidProcessor.
@Test
public final void testRoutingExceptionNullMessageValidProcessor() throws MuleException {
Processor processor = mock(Processor.class);
RoutingException rex = new RoutingException(processor);
assertSame(processor, rex.getRoute());
}
use of org.mule.runtime.core.privileged.routing.RoutingException in project mule by mulesoft.
the class EventCorrelator method process.
public CoreEvent process(CoreEvent event) throws RoutingException {
// the correlationId of the event's message
final String groupId = event.getCorrelationId();
if (logger.isTraceEnabled()) {
try {
logger.trace(format("Received async reply message for correlationID: %s%n%s%n%s", groupId, truncate(StringMessageUtils.toString(event.getMessage().getPayload().getValue()), 200, false), event.getMessage().toString()));
} catch (Exception e) {
// ignore
}
}
// spinloop for the EventGroup lookup
while (true) {
try {
if (isGroupAlreadyProcessed(groupId)) {
if (logger.isDebugEnabled()) {
logger.debug("An event was received for an event group that has already been processed, " + "this is probably because the async-reply timed out. GroupCorrelation Id is: " + groupId + ". Dropping event");
}
// Fire a notification to say we received this message
notificationFirer.dispatch(new RoutingNotification(event.getMessage(), event.getContext().getOriginatingLocation().getComponentIdentifier().getIdentifier().getNamespace(), MISSED_AGGREGATION_GROUP_EVENT));
return null;
}
} catch (ObjectStoreException e) {
throw new RoutingException(timeoutMessageProcessor, e);
}
// check for an existing group first
EventGroup group;
try {
group = this.getEventGroup(groupId);
} catch (ObjectStoreException e) {
throw new RoutingException(timeoutMessageProcessor, e);
}
// does the group exist?
if (group == null) {
// ..apparently not, so create a new one & add it
try {
EventGroup eventGroup = callback.createEventGroup(event, groupId);
eventGroup.initEventsStore(correlatorStore);
group = this.addEventGroup(eventGroup);
} catch (ObjectStoreException e) {
throw new RoutingException(timeoutMessageProcessor, e);
}
}
// ensure that only one thread at a time evaluates this EventGroup
synchronized (groupsLock) {
if (logger.isDebugEnabled()) {
logger.debug("Adding event to aggregator group: " + groupId);
}
// add the incoming event to the group
try {
group.addEvent(event);
} catch (ObjectStoreException e) {
throw new RoutingException(timeoutMessageProcessor, e);
}
// check to see if the event group is ready to be aggregated
if (callback.shouldAggregateEvents(group)) {
// create the response event
CoreEvent returnEvent = null;
try {
returnEvent = callback.aggregateEvents(group);
} catch (RoutingException routingException) {
try {
this.removeEventGroup(group);
group.clear();
} catch (ObjectStoreException objectStoreException) {
throw new RoutingException(timeoutMessageProcessor, objectStoreException);
}
throw routingException;
}
// for this group once we aggregate
try {
this.removeEventGroup(group);
group.clear();
} catch (ObjectStoreException e) {
throw new RoutingException(timeoutMessageProcessor, e);
}
return returnEvent;
} else {
return null;
}
}
}
}
use of org.mule.runtime.core.privileged.routing.RoutingException in project mule by mulesoft.
the class MessageChunkSplitter method splitMessage.
@Override
protected List<?> splitMessage(CoreEvent event) throws RoutingException {
List<CoreEvent> messageParts = new ArrayList<>();
byte[] data;
try {
data = ((InternalEvent) event).getMessageAsBytes(muleContext);
} catch (Exception e) {
throw new RoutingException(CoreMessages.failedToReadPayload(), next, e);
}
Message message = event.getMessage();
int parts = data.length / messageSize;
if ((parts * messageSize) < data.length) {
parts++;
}
int len = messageSize;
int count = 0;
int pos = 0;
byte[] buffer;
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;
final CoreEvent childEvent = CoreEvent.builder(event).message(Message.builder(message).value(buffer).build()).groupCorrelation(Optional.of(of(count, parts))).build();
messageParts.add(childEvent);
}
return messageParts;
}
Aggregations