Search in sources :

Example 1 with RoutingException

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));
    }
}
Also used : RoutingException(org.mule.runtime.core.privileged.routing.RoutingException) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Test(org.junit.Test)

Example 2 with RoutingException

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);
    }
}
Also used : DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) RoutingException(org.mule.runtime.core.privileged.routing.RoutingException) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) MuleException(org.mule.runtime.api.exception.MuleException) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) DispatchException(org.mule.runtime.core.privileged.connector.DispatchException) DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) RoutingException(org.mule.runtime.core.privileged.routing.RoutingException) MuleException(org.mule.runtime.api.exception.MuleException) DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException)

Example 3 with RoutingException

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());
}
Also used : RoutingException(org.mule.runtime.core.privileged.routing.RoutingException) Processor(org.mule.runtime.core.api.processor.Processor) Test(org.junit.Test)

Example 4 with RoutingException

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;
            }
        }
    }
}
Also used : ObjectStoreException(org.mule.runtime.api.store.ObjectStoreException) RoutingException(org.mule.runtime.core.privileged.routing.RoutingException) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) RoutingNotification(org.mule.runtime.api.notification.RoutingNotification) ObjectStoreException(org.mule.runtime.api.store.ObjectStoreException) ObjectDoesNotExistException(org.mule.runtime.api.store.ObjectDoesNotExistException) MuleException(org.mule.runtime.api.exception.MuleException) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) RegistrationException(org.mule.runtime.core.privileged.registry.RegistrationException) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) RoutingException(org.mule.runtime.core.privileged.routing.RoutingException) ObjectAlreadyExistsException(org.mule.runtime.api.store.ObjectAlreadyExistsException) EventGroup(org.mule.runtime.core.internal.routing.EventGroup)

Example 5 with RoutingException

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;
}
Also used : RoutingException(org.mule.runtime.core.privileged.routing.RoutingException) Message(org.mule.runtime.api.message.Message) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) ArrayList(java.util.ArrayList) RoutingException(org.mule.runtime.core.privileged.routing.RoutingException)

Aggregations

RoutingException (org.mule.runtime.core.privileged.routing.RoutingException)6 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)4 MuleException (org.mule.runtime.api.exception.MuleException)3 Test (org.junit.Test)2 DefaultMuleException (org.mule.runtime.api.exception.DefaultMuleException)2 Processor (org.mule.runtime.core.api.processor.Processor)2 MessagingException (org.mule.runtime.core.internal.exception.MessagingException)2 ArrayList (java.util.ArrayList)1 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)1 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)1 Message (org.mule.runtime.api.message.Message)1 RoutingNotification (org.mule.runtime.api.notification.RoutingNotification)1 ObjectAlreadyExistsException (org.mule.runtime.api.store.ObjectAlreadyExistsException)1 ObjectDoesNotExistException (org.mule.runtime.api.store.ObjectDoesNotExistException)1 ObjectStoreException (org.mule.runtime.api.store.ObjectStoreException)1 EventGroup (org.mule.runtime.core.internal.routing.EventGroup)1 DispatchException (org.mule.runtime.core.privileged.connector.DispatchException)1 RegistrationException (org.mule.runtime.core.privileged.registry.RegistrationException)1 CouldNotRouteOutboundMessageException (org.mule.runtime.core.privileged.routing.CouldNotRouteOutboundMessageException)1