Search in sources :

Example 11 with MuleException

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

the class TypeBasedTransformerResolver method initialise.

@Override
public void initialise() throws InitialisationException {
    try {
        objectToString = new ObjectToString();
        objectToByteArray = new ObjectToByteArray();
        // these are just fallbacks that are not to go
        // into the mule registry
        initialiseIfNeeded(objectToString, muleContext);
        initialiseIfNeeded(objectToByteArray, muleContext);
    } catch (MuleException e) {
        throw new InitialisationException(e, this);
    }
}
Also used : ObjectToByteArray(org.mule.runtime.core.internal.transformer.simple.ObjectToByteArray) ObjectToString(org.mule.runtime.core.internal.transformer.simple.ObjectToString) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) MuleException(org.mule.runtime.api.exception.MuleException)

Example 12 with MuleException

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

the class ArtifactObjectSerializer method initialise.

@Override
public void initialise() throws InitialisationException {
    try {
        muleContext.getInjector().inject(javaInternalSerializerProtocol);
        muleContext.getInjector().inject(javaExternalSerializerProtocol);
    } catch (MuleException e) {
        throw new InitialisationException(e, this);
    }
}
Also used : InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) MuleException(org.mule.runtime.api.exception.MuleException)

Example 13 with MuleException

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

the class MuleExtensionModelLoaderManager method start.

/**
 * Will look through SPI every class that implements the {@code providerClass} and if there are repeated IDs, it will
 * collect them all to throw an exception with the detailed message.
 * <p/>
 * The exception, if thrown, will have the following message:
 * <pre>
 *   There are several loaders that return the same ID when looking up providers for 'org.mule.runtime.module.artifact.ExtensionModelLoader'. Full error list:
 *   ID [some-id] is being returned by the following classes [org.foo.FooLoader, org.bar.BarLoader]
 *   ID [another-id] is being returned by the following classes [org.foo2.FooLoader2, org.bar2.BarLoader2]
 * </pre>
 *
 * @throws IllegalStateException if there are loaders with repeated IDs.
 */
@Override
public void start() throws MuleException {
    final Class<ExtensionModelLoader> providerClass = ExtensionModelLoader.class;
    final SpiServiceRegistry spiServiceRegistry = new SpiServiceRegistry();
    final ClassLoader classLoader = containerClassLoader.getClassLoader();
    final Collection<ExtensionModelLoader> extensionModelLoaders = spiServiceRegistry.lookupProviders(providerClass, classLoader);
    final StringBuilder sb = new StringBuilder();
    extensionModelLoaders.stream().collect(groupingBy(ExtensionModelLoader::getId)).entrySet().stream().filter(entry -> entry.getValue().size() > 1).forEach(entry -> {
        // At this point we are sure there are at least 2 classes that return the same ID, we will append it to the builder
        final String classes = entry.getValue().stream().map(extensionModelLoader -> extensionModelLoader.getClass().getName()).collect(Collectors.joining(", "));
        sb.append(lineSeparator()).append("ID [").append(entry.getKey()).append("] is being returned by the following classes [").append(classes).append("]");
    });
    if (isNotBlank(sb.toString())) {
        throw new MuleRuntimeException(createStaticMessage(format("There are several loaders that return the same identifier when looking up providers for '%s'. Full error list: %s", providerClass.getName(), sb.toString())));
    }
    extensionModelLoaders.stream().forEach(extensionModelLoader -> this.extensionModelLoaders.put(extensionModelLoader.getId(), extensionModelLoader));
    if (logger.isDebugEnabled()) {
        logger.debug("ExtensionModelLoader registered identifiers: {}", printExtensionModelLoaderIDs());
    }
}
Also used : Optional.empty(java.util.Optional.empty) ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) System.lineSeparator(java.lang.System.lineSeparator) Logger(org.slf4j.Logger) Maps.newHashMap(com.google.common.collect.Maps.newHashMap) I18nMessageFactory.createStaticMessage(org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage) Optional.of(java.util.Optional.of) Collection(java.util.Collection) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) LoggerFactory(org.slf4j.LoggerFactory) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ExtensionModelLoaderManager(org.mule.runtime.module.extension.internal.loader.ExtensionModelLoaderManager) Preconditions.checkNotNull(org.mule.runtime.api.util.Preconditions.checkNotNull) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Collectors.joining(java.util.stream.Collectors.joining) SpiServiceRegistry(org.mule.runtime.core.api.registry.SpiServiceRegistry) StringUtils.isNotBlank(org.apache.commons.lang3.StringUtils.isNotBlank) LoaderDescriber(org.mule.runtime.deployment.model.api.plugin.LoaderDescriber) MuleException(org.mule.runtime.api.exception.MuleException) Map(java.util.Map) Optional(java.util.Optional) ExtensionModelLoader(org.mule.runtime.extension.api.loader.ExtensionModelLoader) ExtensionModelLoader(org.mule.runtime.extension.api.loader.ExtensionModelLoader) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) SpiServiceRegistry(org.mule.runtime.core.api.registry.SpiServiceRegistry)

Example 14 with MuleException

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

the class ErrorTypesResolutionTestCase method exceptionInfo.

@Test
public void exceptionInfo() throws Exception {
    Exception epe = flowRunner("withUnderlyingConnectorError").runExpectingException();
    Map<String, Object> info = ((MuleException) epe).getInfo();
    assertThat(info.get("Element").toString(), containsString("withUnderlyingConnectorError/processors/0"));
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) MuleException(org.mule.runtime.api.exception.MuleException) MuleException(org.mule.runtime.api.exception.MuleException) Test(org.junit.Test)

Example 15 with MuleException

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

the class HeisenbergMessageSourceTestCase method sourceFailsOnSuccessAndOnErrorParametersCallsOnTerminate.

@Test
public void sourceFailsOnSuccessAndOnErrorParametersCallsOnTerminate() throws Exception {
    startFlow("sourceWithInvalidSuccessAndErrorParameters");
    probe(TIMEOUT_MILLIS, POLL_DELAY_MILLIS, () -> assertState(false, false, true));
    assertThat(HeisenbergSource.terminateStatus, is(ERROR_INVOKE));
    Optional<Error> optionalError = HeisenbergSource.error;
    assertThat(optionalError, is(not(empty())));
    assertThat(optionalError.get().getErrorType(), is(errorType(SOURCE_ERROR_RESPONSE_GENERATE)));
    MuleException me = (MuleException) unwrap(optionalError.get().getCause());
    assertThat((String) me.getInfo().get(INFO_LOCATION_KEY), containsString("sourceWithInvalidSuccessAndErrorParameters/source"));
    assertThat((String) me.getInfo().get(INFO_SOURCE_XML_KEY), containsString("heisenberg:success-info"));
}
Also used : Error(org.mule.runtime.api.message.Error) MuleException(org.mule.runtime.api.exception.MuleException) Test(org.junit.Test)

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