Search in sources :

Example 21 with DefaultMuleException

use of org.mule.runtime.api.exception.DefaultMuleException in project mule by mulesoft.

the class EventCorrelator method handleGroupExpiry.

protected void handleGroupExpiry(EventGroup group) throws MuleException {
    try {
        removeEventGroup(group);
    } catch (ObjectStoreException e) {
        throw new DefaultMuleException(e);
    }
    if (isFailOnTimeout()) {
        CoreEvent messageCollectionEvent = group.getMessageCollectionEvent();
        notificationFirer.dispatch(new RoutingNotification(messageCollectionEvent.getMessage(), null, CORRELATION_TIMEOUT));
        try {
            group.clear();
        } catch (ObjectStoreException e) {
            logger.warn("Failed to clear group with id " + group.getGroupId() + " since underlying ObjectStore threw Exception:" + e.getMessage());
        }
        throw new CorrelationTimeoutException(correlationTimedOut(group.getGroupId()));
    } else {
        if (logger.isDebugEnabled()) {
            logger.debug(MessageFormat.format("Aggregator expired, but ''failOnTimeOut'' is false. Forwarding {0} events out of {1} " + "total for group ID: {2}", group.size(), group.expectedSize().map(v -> v.toString()).orElse(NOT_SET), group.getGroupId()));
        }
        try {
            if (!(group.getCreated() + DAYS.toMillis(1) < currentTimeMillis())) {
                CoreEvent newEvent = CoreEvent.builder(callback.aggregateEvents(group)).build();
                group.clear();
                if (!correlatorStore.contains((String) group.getGroupId(), getExpiredAndDispatchedPartitionKey())) {
                    // returned?
                    if (timeoutMessageProcessor != null) {
                        processToApply(newEvent, timeoutMessageProcessor, false, empty());
                    } else {
                        throw new MessagingException(createStaticMessage(MessageFormat.format("Group {0} timed out, but no timeout message processor was " + "configured.", group.getGroupId())), newEvent);
                    }
                    correlatorStore.store((String) group.getGroupId(), group.getCreated(), getExpiredAndDispatchedPartitionKey());
                } else {
                    logger.warn(MessageFormat.format("Discarding group {0}", group.getGroupId()));
                }
            }
        } catch (MessagingException me) {
            throw me;
        } catch (Exception e) {
            throw new MessagingException(group.getMessageCollectionEvent(), e);
        }
    }
}
Also used : DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) NOT_SET(org.mule.runtime.core.api.message.GroupCorrelation.NOT_SET) ObjectStoreException(org.mule.runtime.api.store.ObjectStoreException) System.currentTimeMillis(java.lang.System.currentTimeMillis) DeserializationPostInitialisable(org.mule.runtime.core.privileged.store.DeserializationPostInitialisable) LoggerFactory(org.slf4j.LoggerFactory) MINUTES(java.util.concurrent.TimeUnit.MINUTES) PartitionableObjectStore(org.mule.runtime.api.store.PartitionableObjectStore) Expirable(org.mule.runtime.core.privileged.util.monitor.Expirable) Processor(org.mule.runtime.core.api.processor.Processor) ObjectDoesNotExistException(org.mule.runtime.api.store.ObjectDoesNotExistException) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) MuleContextWithRegistries(org.mule.runtime.core.internal.context.MuleContextWithRegistries) MuleContext(org.mule.runtime.core.api.MuleContext) MuleException(org.mule.runtime.api.exception.MuleException) Scheduler(org.mule.runtime.api.scheduler.Scheduler) DAYS(java.util.concurrent.TimeUnit.DAYS) CORRELATION_TIMEOUT(org.mule.runtime.api.notification.RoutingNotification.CORRELATION_TIMEOUT) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) Mono.empty(reactor.core.publisher.Mono.empty) ExpiryMonitor(org.mule.runtime.core.privileged.util.monitor.ExpiryMonitor) RoutingNotification(org.mule.runtime.api.notification.RoutingNotification) Disposable(org.mule.runtime.api.lifecycle.Disposable) Startable(org.mule.runtime.api.lifecycle.Startable) MISSED_AGGREGATION_GROUP_EVENT(org.mule.runtime.api.notification.RoutingNotification.MISSED_AGGREGATION_GROUP_EVENT) Logger(org.slf4j.Logger) MessageProcessors.processToApply(org.mule.runtime.core.privileged.processor.MessageProcessors.processToApply) ObjectStore(org.mule.runtime.api.store.ObjectStore) I18nMessageFactory.createStaticMessage(org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) RegistrationException(org.mule.runtime.core.privileged.registry.RegistrationException) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) StringMessageUtils.truncate(org.mule.runtime.core.api.util.StringMessageUtils.truncate) StringMessageUtils(org.mule.runtime.core.api.util.StringMessageUtils) String.format(java.lang.String.format) EventGroup(org.mule.runtime.core.internal.routing.EventGroup) DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) List(java.util.List) Stoppable(org.mule.runtime.api.lifecycle.Stoppable) CoreMessages.objectIsNull(org.mule.runtime.core.api.config.i18n.CoreMessages.objectIsNull) CoreMessages.correlationTimedOut(org.mule.runtime.core.api.config.i18n.CoreMessages.correlationTimedOut) FlowConstruct(org.mule.runtime.core.api.construct.FlowConstruct) NotificationDispatcher(org.mule.runtime.api.notification.NotificationDispatcher) RoutingException(org.mule.runtime.core.privileged.routing.RoutingException) ObjectAlreadyExistsException(org.mule.runtime.api.store.ObjectAlreadyExistsException) ObjectStoreException(org.mule.runtime.api.store.ObjectStoreException) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) 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)

Example 22 with DefaultMuleException

use of org.mule.runtime.api.exception.DefaultMuleException in project mule by mulesoft.

the class AbstractAsyncRequestReplyRequester method retrieveEvent.

private PrivilegedEvent retrieveEvent(String correlationId) throws MuleException {
    MultipleRequestReplierEvent multipleEvent = (MultipleRequestReplierEvent) store.retrieve(correlationId);
    PrivilegedEvent event = multipleEvent.getEvent();
    // TODO MULE-10302 remove this.
    if (currentMuleContext.get() == null) {
        try {
            DeserializationPostInitialisable.Implementation.init(event, muleContext);
        } catch (Exception e) {
            throw new DefaultMuleException(e);
        }
    }
    return event;
}
Also used : DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) ObjectStoreException(org.mule.runtime.api.store.ObjectStoreException) ResponseTimeoutException(org.mule.runtime.core.privileged.routing.ResponseTimeoutException) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) MuleException(org.mule.runtime.api.exception.MuleException) RegistrationException(org.mule.runtime.core.privileged.registry.RegistrationException) DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException)

Example 23 with DefaultMuleException

use of org.mule.runtime.api.exception.DefaultMuleException in project mule by mulesoft.

the class TransformerUtils method getTransformers.

/**
 * Builds a list of Transformers.
 *
 * @param names - a list of transformers separated by commands
 * @param muleContext the current muleContext. This is used to look up transformers in the registry
 * @return a list (possibly empty) of transformers or
 * @throws MuleException if any of the transformers cannot be found
 */
public static List<Transformer> getTransformers(String names, MuleContext muleContext) throws MuleException {
    if (null != names) {
        List<Transformer> transformers = new LinkedList<>();
        StringTokenizer st = new StringTokenizer(names, COMMA);
        while (st.hasMoreTokens()) {
            String key = st.nextToken().trim();
            Transformer transformer = ((MuleContextWithRegistries) muleContext).getRegistry().lookupTransformer(key);
            if (transformer == null) {
                throw new DefaultMuleException(objectNotRegistered("Transformer", key));
            }
            transformers.add(transformer);
        }
        return transformers;
    } else {
        return null;
    }
}
Also used : DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) StringTokenizer(java.util.StringTokenizer) Transformer(org.mule.runtime.core.api.transformer.Transformer) AbstractTransformer(org.mule.runtime.core.api.transformer.AbstractTransformer) LinkedList(java.util.LinkedList)

Example 24 with DefaultMuleException

use of org.mule.runtime.api.exception.DefaultMuleException in project mule by mulesoft.

the class ClasspathMuleCoreExtensionDiscovererTestCase method setsContainerClassLoaderOnDiscoveredExtensions.

@Test
public void setsContainerClassLoaderOnDiscoveredExtensions() throws Exception {
    final ArtifactClassLoader artifactClassLoader = mock(ArtifactClassLoader.class);
    final ClassLoader classLoader = mock(ClassLoader.class);
    final URL resource = getClass().getClassLoader().getResource("test-core-extension.properties");
    when(classLoader.getResources(CORE_EXTENSION_RESOURCE_NAME)).thenReturn(new EnumerationAdapter<URL>(Collections.singleton(resource)));
    when(artifactClassLoader.getClassLoader()).thenReturn(classLoader);
    final ClasspathMuleCoreExtensionDiscoverer discoverer = new ClasspathMuleCoreExtensionDiscoverer(artifactClassLoader);
    // Uses context classloader to force discovering of the test properties
    final List<MuleCoreExtension> discover = withContextClassLoader(artifactClassLoader.getClassLoader(), () -> {
        try {
            return discoverer.discover();
        } catch (DefaultMuleException e) {
            throw new IllegalStateException(e);
        }
    });
    assertThat(discover.size(), equalTo(1));
    assertThat(discover.get(0), instanceOf(TestCoreExtension.class));
    assertThat(((TestCoreExtension) discover.get(0)).containerClassLoader, is(artifactClassLoader));
}
Also used : DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) ClassUtils.withContextClassLoader(org.mule.runtime.core.api.util.ClassUtils.withContextClassLoader) MuleCoreExtension(org.mule.runtime.container.api.MuleCoreExtension) URL(java.net.URL) Test(org.junit.Test)

Example 25 with DefaultMuleException

use of org.mule.runtime.api.exception.DefaultMuleException in project mule by mulesoft.

the class ClasspathMuleCoreExtensionDiscoverer method discover.

@Override
public List<MuleCoreExtension> discover() throws MuleException {
    List<MuleCoreExtension> result = new LinkedList<>();
    Enumeration<?> e = ClassUtils.getResources(CORE_EXTENSION_RESOURCE_NAME, getClass().getClassLoader());
    List<Properties> extensions = new LinkedList<Properties>();
    // load ALL of the extension files first
    while (e.hasMoreElements()) {
        try {
            URL url = (URL) e.nextElement();
            if (logger.isDebugEnabled()) {
                logger.debug("Reading extension file: " + url.toString());
            }
            extensions.add(loadProperties(url.openStream()));
        } catch (Exception ex) {
            throw new DefaultMuleException("Error loading Mule core extensions", ex);
        }
    }
    for (Properties extProps : extensions) {
        for (Map.Entry entry : extProps.entrySet()) {
            String extName = (String) entry.getKey();
            String extClass = (String) entry.getValue();
            try {
                MuleCoreExtension extension = (MuleCoreExtension) ClassUtils.instantiateClass(extClass);
                extension.setContainerClassLoader(containerClassLoader);
                result.add(extension);
            } catch (Throwable t) {
                throw new DefaultMuleException(format("Error starting Mule core extension '%s'. Extension class is %s", extName, extClass), t);
            }
        }
    }
    return result;
}
Also used : Properties(java.util.Properties) PropertiesUtils.loadProperties(org.mule.runtime.core.api.util.PropertiesUtils.loadProperties) LinkedList(java.util.LinkedList) URL(java.net.URL) DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) MuleException(org.mule.runtime.api.exception.MuleException) DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) MuleCoreExtension(org.mule.runtime.container.api.MuleCoreExtension) Map(java.util.Map)

Aggregations

DefaultMuleException (org.mule.runtime.api.exception.DefaultMuleException)26 Test (org.junit.Test)12 MuleException (org.mule.runtime.api.exception.MuleException)12 MessagingException (org.mule.runtime.core.internal.exception.MessagingException)8 SmallTest (org.mule.tck.size.SmallTest)6 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)5 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)5 IOException (java.io.IOException)3 ConnectionException (org.mule.runtime.api.connection.ConnectionException)3 URL (java.net.URL)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 ConnectionProvider (org.mule.runtime.api.connection.ConnectionProvider)2 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)2 ObjectStoreException (org.mule.runtime.api.store.ObjectStoreException)2 MuleCoreExtension (org.mule.runtime.container.api.MuleCoreExtension)2 Processor (org.mule.runtime.core.api.processor.Processor)2 MessageProcessors.processToApply (org.mule.runtime.core.privileged.processor.MessageProcessors.processToApply)2 RegistrationException (org.mule.runtime.core.privileged.registry.RegistrationException)2 RoutingException (org.mule.runtime.core.privileged.routing.RoutingException)2