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);
}
}
}
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;
}
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;
}
}
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));
}
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;
}
Aggregations