Search in sources :

Example 61 with MuleException

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

the class ArtifactFunctionalTestCase method createServiceManager.

private static void createServiceManager() {
    serviceRepository = ServiceManager.create(ServiceDiscoverer.create(new IsolatedServiceProviderDiscoverer(serviceClassLoaders)));
    try {
        serviceRepository.start();
    } catch (MuleException e) {
        throw new IllegalStateException("Couldn't start service manager", e);
    }
    serviceConfigurator = new TestServicesMuleContextConfigurator(serviceRepository);
}
Also used : IsolatedServiceProviderDiscoverer(org.mule.test.runner.api.IsolatedServiceProviderDiscoverer) MuleException(org.mule.runtime.api.exception.MuleException)

Example 62 with MuleException

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

the class ExtensionMessageSourceTestCase method workManagerDisposedIfSourceFailsToStart.

@Test
public void workManagerDisposedIfSourceFailsToStart() throws Exception {
    start();
    Exception e = new RuntimeException();
    doThrow(e).when(source).onStop();
    expectedException.expect(new BaseMatcher<Throwable>() {

        @Override
        public boolean matches(Object item) {
            Exception exception = (Exception) item;
            return exception.getCause() instanceof MuleException && exception.getCause().getCause() == e;
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("Exception was not wrapped as expected");
        }
    });
}
Also used : Description(org.hamcrest.Description) ThrowableAssert.catchThrowable(org.assertj.core.api.ThrowableAssert.catchThrowable) MuleException(org.mule.runtime.api.exception.MuleException) LifecycleException(org.mule.runtime.api.lifecycle.LifecycleException) IOException(java.io.IOException) RetryPolicyExhaustedException(org.mule.runtime.core.api.retry.policy.RetryPolicyExhaustedException) DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) ConnectionException(org.mule.runtime.api.connection.ConnectionException) MuleException(org.mule.runtime.api.exception.MuleException) DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) Test(org.junit.Test)

Example 63 with MuleException

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

the class MuleContainer method shutdown.

/**
 * Will shut down the server displaying the cause and time of the shutdown
 *
 * @param e the exception that caused the shutdown
 */
public void shutdown(Throwable e) throws MuleException {
    I18nMessage msg = fatalErrorWhileRunning();
    MuleException muleException = getRootMuleException(e);
    if (muleException != null) {
        logger.error(muleException.getDetailedMessage());
    } else {
        logger.error(msg.toString() + " " + e.getMessage(), e);
    }
    List<String> msgs = new ArrayList<>();
    msgs.add(msg.getMessage());
    Throwable root = getRootException(e);
    msgs.add(root.getMessage() + " (" + root.getClass().getName() + ")");
    msgs.add(" ");
    msgs.add(fatalErrorInShutdown().getMessage());
    String shutdownMessage = getBoilerPlate(msgs, '*', 80);
    logger.error(shutdownMessage);
    doShutdown();
    System.exit(1);
}
Also used : ArrayList(java.util.ArrayList) I18nMessage(org.mule.runtime.api.i18n.I18nMessage) MuleException(org.mule.runtime.api.exception.MuleException) ExceptionHelper.getRootMuleException(org.mule.runtime.api.exception.ExceptionHelper.getRootMuleException)

Example 64 with MuleException

use of org.mule.runtime.api.exception.MuleException 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)

Example 65 with MuleException

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

the class ExtensionActivator method registerEnumTransformers.

private void registerEnumTransformers(ExtensionModel extensionModel) {
    ClassLoader classLoader = getClassLoader(extensionModel);
    Set<Class<?>> parameterClasses = new HashSet<>();
    parameterClasses.addAll(getParameterClasses(extensionModel, classLoader));
    parameterClasses.addAll(getSubtypeClasses(extensionModel, classLoader));
    parameterClasses.stream().filter(type -> Enum.class.isAssignableFrom(type)).forEach(type -> {
        final Class<Enum> enumClass = (Class<Enum>) type;
        if (enumTypes.add(enumClass)) {
            try {
                StringToEnum stringToEnum = new StringToEnum(enumClass);
                registerObject(muleContext, getName(stringToEnum), stringToEnum, Transformer.class);
            } catch (MuleException e) {
                throw new MuleRuntimeException(createStaticMessage("Could not register transformer for enum " + enumClass.getName()), e);
            }
        }
    });
}
Also used : IntrospectionUtils.getSubtypeClasses(org.mule.runtime.module.extension.internal.util.IntrospectionUtils.getSubtypeClasses) FunctionModel(org.mule.runtime.api.meta.model.function.FunctionModel) IntrospectionUtils.getParameterClasses(org.mule.runtime.module.extension.internal.util.IntrospectionUtils.getParameterClasses) FunctionExecutor(org.mule.runtime.module.extension.internal.runtime.function.FunctionExecutor) MuleExtensionUtils.getClassLoader(org.mule.runtime.module.extension.internal.util.MuleExtensionUtils.getClassLoader) BindingContext(org.mule.runtime.api.el.BindingContext) StringToEnum(org.mule.runtime.core.internal.transformer.simple.StringToEnum) LifecycleUtils.initialiseIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.initialiseIfNeeded) DefaultExpressionModuleBuilder(org.mule.runtime.core.internal.el.DefaultExpressionModuleBuilder) HashSet(java.util.HashSet) MuleContext(org.mule.runtime.core.api.MuleContext) MuleException(org.mule.runtime.api.exception.MuleException) FunctionExecutorModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.FunctionExecutorModelProperty) BeanUtils.getName(org.mule.runtime.core.privileged.util.BeanUtils.getName) LifecycleUtils.stopIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.stopIfNeeded) LinkedList(java.util.LinkedList) Startable(org.mule.runtime.api.lifecycle.Startable) FunctionParameterDefaultValueResolverFactory(org.mule.runtime.module.extension.internal.runtime.function.FunctionParameterDefaultValueResolverFactory) DataType.fromFunction(org.mule.runtime.api.metadata.DataType.fromFunction) DefaultBindingContextBuilder(org.mule.runtime.core.internal.el.DefaultBindingContextBuilder) I18nMessageFactory.createStaticMessage(org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage) Set(java.util.Set) LifecycleUtils.startIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.startIfNeeded) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) Transformer(org.mule.runtime.core.api.transformer.Transformer) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) TypedValue(org.mule.runtime.api.metadata.TypedValue) List(java.util.List) Stream(java.util.stream.Stream) ExpressionModule(org.mule.runtime.api.el.ExpressionModule) Stoppable(org.mule.runtime.api.lifecycle.Stoppable) LegacyRegistryUtils.registerObject(org.mule.runtime.core.privileged.registry.LegacyRegistryUtils.registerObject) ModuleNamespace(org.mule.runtime.api.el.ModuleNamespace) ExtendedExpressionManager(org.mule.runtime.core.api.el.ExtendedExpressionManager) GlobalBindingContextProvider(org.mule.runtime.core.privileged.el.GlobalBindingContextProvider) StringToEnum(org.mule.runtime.core.internal.transformer.simple.StringToEnum) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) MuleExtensionUtils.getClassLoader(org.mule.runtime.module.extension.internal.util.MuleExtensionUtils.getClassLoader) StringToEnum(org.mule.runtime.core.internal.transformer.simple.StringToEnum) MuleException(org.mule.runtime.api.exception.MuleException) HashSet(java.util.HashSet)

Aggregations

MuleException (org.mule.runtime.api.exception.MuleException)68 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)21 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)19 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)19 Test (org.junit.Test)15 DefaultMuleException (org.mule.runtime.api.exception.DefaultMuleException)14 Processor (org.mule.runtime.core.api.processor.Processor)12 MessagingException (org.mule.runtime.core.internal.exception.MessagingException)9 Logger (org.slf4j.Logger)7 ArrayList (java.util.ArrayList)6 List (java.util.List)6 BaseEventContext (org.mule.runtime.core.privileged.event.BaseEventContext)6 RegistrationException (org.mule.runtime.core.privileged.registry.RegistrationException)6 Map (java.util.Map)5 ConnectionException (org.mule.runtime.api.connection.ConnectionException)5 MuleContext (org.mule.runtime.core.api.MuleContext)5 LifecycleUtils.stopIfNeeded (org.mule.runtime.core.api.lifecycle.LifecycleUtils.stopIfNeeded)5 Thread.currentThread (java.lang.Thread.currentThread)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 Startable (org.mule.runtime.api.lifecycle.Startable)4