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