Search in sources :

Example 31 with MuleRuntimeException

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

the class CraftedExtensionModelLoader method declareExtension.

@Override
protected void declareExtension(ExtensionLoadingContext context) {
    Class<?> delegateType = getDelegateType(context, context.getExtensionClassLoader());
    if (!ExtensionLoadingDelegate.class.isAssignableFrom(delegateType)) {
        throw new IllegalArgumentException(format("Property '%s' was expected to point to an implementation of the '%s', but '%s' was found instead", TYPE_PROPERTY_NAME, ExtensionLoadingDelegate.class.getName(), delegateType.getClass().getName()));
    }
    if (!isInstantiable(delegateType, new ReflectionCache())) {
        throw new IllegalArgumentException(format("Type '%s' is not instantiable. A concrete class with a public default constructor was expected", delegateType.getName()));
    }
    ExtensionLoadingDelegate delegate;
    try {
        delegate = (ExtensionLoadingDelegate) ClassUtils.instantiateClass(delegateType);
    } catch (Throwable e) {
        throw new MuleRuntimeException(createStaticMessage(format("Could not instantiate type '%s'", delegateType.getName())), e);
    }
    delegate.accept(context.getExtensionDeclarer(), context);
}
Also used : ReflectionCache(org.mule.runtime.module.extension.internal.util.ReflectionCache) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ExtensionLoadingDelegate(org.mule.runtime.extension.api.loader.ExtensionLoadingDelegate)

Example 32 with MuleRuntimeException

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

the class ExtensionComponent method runWithMetadataContext.

protected <R> R runWithMetadataContext(Function<MetadataContext, R> metadataContextFunction) throws MetadataResolvingException, ConnectionException {
    MetadataContext context = null;
    R result;
    try {
        context = withContextClassLoader(getClassLoader(this.extensionModel), this::getMetadataContext);
        result = metadataContextFunction.apply(context);
    } catch (MuleRuntimeException e) {
        // TODO(MULE-13621) this should be deleted once the configuration is created lazily in the getMetadataContext method.
        try {
            throw e.getCause();
        } catch (MetadataResolvingException | ConnectionException cause) {
            throw cause;
        } catch (Throwable t) {
            throw e;
        }
    } finally {
        if (context != null) {
            context.dispose();
        }
    }
    return result;
}
Also used : MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) DefaultMetadataContext(org.mule.runtime.module.extension.internal.metadata.DefaultMetadataContext) MetadataContext(org.mule.runtime.api.metadata.MetadataContext)

Example 33 with MuleRuntimeException

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

the class DefaultExtensionsClient method disposeProcessor.

private void disposeProcessor(OperationMessageProcessor processor) {
    try {
        processor.stop();
        processor.dispose();
    } catch (MuleException e) {
        throw new MuleRuntimeException(createStaticMessage("Error while disposing the executing operation"), e);
    }
}
Also used : MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) MuleException(org.mule.runtime.api.exception.MuleException)

Example 34 with MuleRuntimeException

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

the class DefaultExtensionsClient method resolveParameters.

private Map<String, ValueResolver> resolveParameters(Map<String, Object> parameters, CoreEvent event) {
    LinkedHashMap<String, ValueResolver> values = new LinkedHashMap<>();
    parameters.forEach((name, value) -> {
        if (value instanceof ComplexParameter) {
            ComplexParameter complex = (ComplexParameter) value;
            DefaultObjectBuilder<?> builder = new DefaultObjectBuilder<>(complex.getType());
            resolveParameters(complex.getParameters(), event).forEach((propertyName, valueResolver) -> {
                try {
                    initialiseIfNeeded(valueResolver, true, muleContext);
                    builder.addPropertyResolver(propertyName, valueResolver);
                } catch (InitialisationException e) {
                    throw new MuleRuntimeException(e);
                }
            });
            try {
                values.put(name, new StaticValueResolver<>(builder.build(from(event))));
            } catch (MuleException e) {
                throw new MuleRuntimeException(createStaticMessage(format("Could not construct parameter [%s]", name)), e);
            }
        } else {
            if (value instanceof String && parser.isContainsTemplate((String) value)) {
                values.put(name, new ExpressionValueResolver((String) value));
            } else {
                values.put(name, new StaticValueResolver<>(value));
            }
        }
    });
    return values;
}
Also used : ComplexParameter(org.mule.runtime.extension.internal.client.ComplexParameter) StaticValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.StaticValueResolver) ValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.ValueResolver) ExpressionValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.ExpressionValueResolver) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) DefaultObjectBuilder(org.mule.runtime.module.extension.internal.runtime.objectbuilder.DefaultObjectBuilder) MuleException(org.mule.runtime.api.exception.MuleException) LinkedHashMap(java.util.LinkedHashMap) ExpressionValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.ExpressionValueResolver)

Example 35 with MuleRuntimeException

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

the class DefaultExtensionsClient method findOperation.

private OperationModel findOperation(ExtensionModel extensionModel, String operationName) {
    Reference<OperationModel> operation = new Reference<>();
    ExtensionWalker walker = new IdempotentExtensionWalker() {

        @Override
        protected void onOperation(OperationModel operationModel) {
            if (operationName.equals(operationModel.getName())) {
                operation.set(operationModel);
                stop();
            }
        }
    };
    walker.walk(extensionModel);
    if (operation.get() == null) {
        throw new MuleRuntimeException(createStaticMessage("No Operation [" + operationName + "] Found"));
    }
    return operation.get();
}
Also used : Reference(org.mule.runtime.api.util.Reference) IdempotentExtensionWalker(org.mule.runtime.api.meta.model.util.IdempotentExtensionWalker) ExtensionWalker(org.mule.runtime.api.meta.model.util.ExtensionWalker) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) IdempotentExtensionWalker(org.mule.runtime.api.meta.model.util.IdempotentExtensionWalker) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel)

Aggregations

MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)123 IOException (java.io.IOException)22 List (java.util.List)22 MuleException (org.mule.runtime.api.exception.MuleException)22 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)22 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)22 Map (java.util.Map)20 Optional (java.util.Optional)20 I18nMessageFactory.createStaticMessage (org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage)18 ArrayList (java.util.ArrayList)17 String.format (java.lang.String.format)16 File (java.io.File)15 HashMap (java.util.HashMap)15 HashSet (java.util.HashSet)13 Set (java.util.Set)13 Collectors.toList (java.util.stream.Collectors.toList)12 ConfigurationException (org.mule.runtime.core.api.config.ConfigurationException)12 ComponentIdentifier (org.mule.runtime.api.component.ComponentIdentifier)10 Collections.emptyMap (java.util.Collections.emptyMap)9 Optional.empty (java.util.Optional.empty)9