Search in sources :

Example 6 with ResolverSet

use of org.mule.runtime.module.extension.internal.runtime.resolver.ResolverSet in project mule by mulesoft.

the class ConfigurationProviderObjectFactory method createInnerInstance.

private ConfigurationProvider createInnerInstance() throws ConfigurationException {
    if (expirationPolicy == null) {
        expirationPolicy = muleContext.getConfiguration().getDynamicConfigExpiration().getExpirationPolicy();
    }
    ResolverSet resolverSet = getParametersResolver().getParametersAsHashedResolverSet(configurationModel, muleContext);
    final ConnectionProviderValueResolver connectionProviderResolver = getConnectionProviderResolver();
    return withContextClassLoader(getExtensionClassLoader(), () -> {
        connectionProviderResolver.getResolverSet().ifPresent((CheckedConsumer) resolver -> initialiseIfNeeded(resolver, true, muleContext));
        ConfigurationProvider configurationProvider;
        try {
            if (resolverSet.isDynamic() || connectionProviderResolver.isDynamic()) {
                configurationProvider = configurationProviderFactory.createDynamicConfigurationProvider(name, extensionModel, configurationModel, resolverSet, connectionProviderResolver, expirationPolicy, reflectionCache, muleContext);
            } else {
                configurationProvider = configurationProviderFactory.createStaticConfigurationProvider(name, extensionModel, configurationModel, resolverSet, connectionProviderResolver, reflectionCache, muleContext);
            }
        } catch (Exception e) {
            throw new MuleRuntimeException(createStaticMessage(format("Could not create an implicit configuration '%s' for the extension '%s'", configurationModel.getName(), extensionModel.getName())), e);
        }
        return configurationProvider;
    });
}
Also used : ResolverSet(org.mule.runtime.module.extension.internal.runtime.resolver.ResolverSet) Optional.empty(java.util.Optional.empty) Thread.currentThread(java.lang.Thread.currentThread) LifecycleUtils.initialiseIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.initialiseIfNeeded) ConnectionProviderValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.ConnectionProviderValueResolver) ResolverSet(org.mule.runtime.module.extension.internal.runtime.resolver.ResolverSet) ExpirationPolicy(org.mule.runtime.extension.api.runtime.ExpirationPolicy) MuleContext(org.mule.runtime.core.api.MuleContext) DefaultConfigurationProviderFactory(org.mule.runtime.module.extension.internal.runtime.config.DefaultConfigurationProviderFactory) ClassUtils.withContextClassLoader(org.mule.runtime.core.api.util.ClassUtils.withContextClassLoader) ObjectFactory(org.mule.runtime.dsl.api.component.ObjectFactory) CheckedConsumer(org.mule.runtime.core.api.util.func.CheckedConsumer) ConfigurationException(org.mule.runtime.core.api.config.ConfigurationException) ConfigurationProvider(org.mule.runtime.extension.api.runtime.config.ConfigurationProvider) Optional.ofNullable(java.util.Optional.ofNullable) I18nMessageFactory.createStaticMessage(org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage) ImplicitConnectionProviderValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.ImplicitConnectionProviderValueResolver) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ConfigurationModel(org.mule.runtime.api.meta.model.config.ConfigurationModel) ClassLoaderModelProperty(org.mule.runtime.extension.api.property.ClassLoaderModelProperty) StaticConnectionProviderResolver(org.mule.runtime.module.extension.internal.runtime.resolver.StaticConnectionProviderResolver) String.format(java.lang.String.format) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) ConnectionProviderResolver(org.mule.runtime.module.extension.internal.runtime.resolver.ConnectionProviderResolver) AbstractExtensionObjectFactory(org.mule.runtime.module.extension.internal.config.dsl.AbstractExtensionObjectFactory) ConfigurationProviderFactory(org.mule.runtime.module.extension.internal.runtime.config.ConfigurationProviderFactory) Optional(java.util.Optional) ConfigurationProvider(org.mule.runtime.extension.api.runtime.config.ConfigurationProvider) ConnectionProviderValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.ConnectionProviderValueResolver) ImplicitConnectionProviderValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.ImplicitConnectionProviderValueResolver) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ConfigurationException(org.mule.runtime.core.api.config.ConfigurationException) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException)

Example 7 with ResolverSet

use of org.mule.runtime.module.extension.internal.runtime.resolver.ResolverSet in project mule by mulesoft.

the class ConnectionProviderObjectFactory method doGetObject.

@Override
public ConnectionProviderResolver doGetObject() throws Exception {
    Callable<ResolverSet> callable = () -> getParametersResolver().getParametersAsHashedResolverSet(providerModel, muleContext);
    ResolverSet resolverSet = withContextClassLoader(getClassLoader(extensionModel), callable);
    ConnectionProviderObjectBuilder builder;
    if (extensionModel.getModelProperty(SoapExtensionModelProperty.class).isPresent()) {
        builder = new SoapConnectionProviderObjectBuilder(providerModel, resolverSet, poolingProfile, reconnectionConfig, extensionModel, muleContext);
    } else if (providerModel.getModelProperty(OAuthModelProperty.class).isPresent()) {
        builder = new OAuthConnectionProviderObjectBuilder(providerModel, resolverSet, poolingProfile, reconnectionConfig, oauthManager, extensionModel, muleContext);
    } else {
        builder = new DefaultConnectionProviderObjectBuilder(providerModel, resolverSet, poolingProfile, reconnectionConfig, extensionModel, muleContext);
    }
    return new ConnectionProviderResolver<>(builder, resolverSet, muleContext);
}
Also used : ResolverSet(org.mule.runtime.module.extension.internal.runtime.resolver.ResolverSet) SoapConnectionProviderObjectBuilder(org.mule.runtime.module.extension.soap.internal.runtime.connection.SoapConnectionProviderObjectBuilder) DefaultConnectionProviderObjectBuilder(org.mule.runtime.module.extension.internal.runtime.config.DefaultConnectionProviderObjectBuilder) OAuthConnectionProviderObjectBuilder(org.mule.runtime.module.extension.internal.runtime.connectivity.oauth.OAuthConnectionProviderObjectBuilder) ConnectionProviderObjectBuilder(org.mule.runtime.module.extension.internal.runtime.config.ConnectionProviderObjectBuilder) SoapConnectionProviderObjectBuilder(org.mule.runtime.module.extension.soap.internal.runtime.connection.SoapConnectionProviderObjectBuilder) OAuthConnectionProviderObjectBuilder(org.mule.runtime.module.extension.internal.runtime.connectivity.oauth.OAuthConnectionProviderObjectBuilder) ConnectionProviderResolver(org.mule.runtime.module.extension.internal.runtime.resolver.ConnectionProviderResolver) SoapExtensionModelProperty(org.mule.runtime.module.extension.soap.internal.loader.property.SoapExtensionModelProperty) DefaultConnectionProviderObjectBuilder(org.mule.runtime.module.extension.internal.runtime.config.DefaultConnectionProviderObjectBuilder)

Example 8 with ResolverSet

use of org.mule.runtime.module.extension.internal.runtime.resolver.ResolverSet in project mule by mulesoft.

the class ExtensionSourceObjectFactory method doGetObject.

@Override
public ExtensionMessageSource doGetObject() throws ConfigurationException, InitialisationException {
    return withContextClassLoader(getClassLoader(extensionModel), () -> {
        getParametersResolver().checkParameterGroupExclusiveness(Optional.of(sourceModel), sourceModel.getParameterGroupModels(), parameters.keySet());
        ResolverSet nonCallbackParameters = getNonCallbackParameters();
        if (nonCallbackParameters.isDynamic()) {
            throw dynamicParameterException(nonCallbackParameters, sourceModel);
        }
        ResolverSet responseCallbackParameters = getCallbackParameters(sourceModel.getSuccessCallback());
        ResolverSet errorCallbackParameters = getCallbackParameters(sourceModel.getErrorCallback());
        initialiseIfNeeded(nonCallbackParameters, true, muleContext);
        initialiseIfNeeded(responseCallbackParameters, true, muleContext);
        initialiseIfNeeded(errorCallbackParameters, true, muleContext);
        final BackPressureStrategy backPressureStrategy = getBackPressureStrategy();
        return new ExtensionMessageSource(extensionModel, sourceModel, getSourceAdapterFactory(nonCallbackParameters, responseCallbackParameters, errorCallbackParameters, backPressureStrategy), configurationProvider, primaryNodeOnly != null ? primaryNodeOnly : sourceModel.runsOnPrimaryNodeOnly(), getRetryPolicyTemplate(), cursorProviderFactory, backPressureStrategy, muleContext.getExtensionManager());
    });
}
Also used : ResolverSet(org.mule.runtime.module.extension.internal.runtime.resolver.ResolverSet) MuleExtensionUtils.toBackPressureStrategy(org.mule.runtime.module.extension.internal.util.MuleExtensionUtils.toBackPressureStrategy) BackPressureStrategy(org.mule.runtime.core.api.source.MessageSource.BackPressureStrategy) ExtensionMessageSource(org.mule.runtime.module.extension.internal.runtime.source.ExtensionMessageSource)

Example 9 with ResolverSet

use of org.mule.runtime.module.extension.internal.runtime.resolver.ResolverSet in project mule by mulesoft.

the class ComponentMessageProcessorBuilder method build.

public P build() {
    return withContextClassLoader(getClassLoader(extensionModel), () -> {
        try {
            final ExtensionManager extensionManager = muleContext.getExtensionManager();
            final ResolverSet operationArguments = getArgumentsResolverSet();
            P processor = createMessageProcessor(extensionManager, operationArguments);
            // TODO: MULE-5002 this should not be necessary but lifecycle issues when injecting message processors automatically
            muleContext.getInjector().inject(processor);
            return processor;
        } catch (Exception e) {
            throw new MuleRuntimeException(e);
        }
    });
}
Also used : ResolverSet(org.mule.runtime.module.extension.internal.runtime.resolver.ResolverSet) ExtensionManager(org.mule.runtime.core.api.extension.ExtensionManager) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ConfigurationException(org.mule.runtime.core.api.config.ConfigurationException) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException)

Example 10 with ResolverSet

use of org.mule.runtime.module.extension.internal.runtime.resolver.ResolverSet in project mule by mulesoft.

the class ImplicitObjectUtils method buildImplicitResolverSet.

/**
 * Creates a {@link ResolverSet} based on the default values for the {@link ParameterModel}s in the {@code parametrizedModel}.
 * <p>
 * If a {@link ParameterModel} returns {@code null} for {@link ParameterModel#getDefaultValue()} then it's ignored
 *
 * @param model a model holding the {@link ParameterModel}s to consider
 * @param muleContext the Mule node.
 * @return a {@link ResolverSet}
 */
public static ResolverSet buildImplicitResolverSet(ParameterizedModel model, ReflectionCache reflectionCache, MuleContext muleContext) {
    ResolverSet resolverSet = new HashedResolverSet(muleContext);
    ParametersResolver parametersResolver = ParametersResolver.fromDefaultValues(model, muleContext, reflectionCache);
    for (ParameterGroupModel groupModel : model.getParameterGroupModels()) {
        Optional<ParameterGroupDescriptor> descriptor = groupModel.getModelProperty(ParameterGroupModelProperty.class).map(ParameterGroupModelProperty::getDescriptor);
        if (descriptor.isPresent() && groupModel.getParameterModels().stream().noneMatch(ParameterModel::isRequired)) {
            String groupKey = getContainerName(descriptor.get().getContainer());
            resolverSet.add(groupKey, NullSafeValueResolverWrapper.of(new StaticValueResolver<>(null), descriptor.get().getMetadataType(), reflectionCache, muleContext, parametersResolver));
        } else {
            groupModel.getParameterModels().forEach(parameterModel -> {
                Object defaultValue = parameterModel.getDefaultValue();
                ValueResolver<?> resolver;
                if (defaultValue instanceof String) {
                    resolver = getExpressionBasedValueResolver((String) defaultValue, parameterModel.getType(), muleContext);
                } else {
                    resolver = new StaticValueResolver<>(null);
                }
                if (parameterModel.getModelProperty(NullSafeModelProperty.class).isPresent()) {
                    MetadataType metadataType = parameterModel.getModelProperty(NullSafeModelProperty.class).get().defaultType();
                    resolver = NullSafeValueResolverWrapper.of(resolver, metadataType, reflectionCache, muleContext, parametersResolver);
                }
                resolverSet.add(parameterModel.getName(), resolver);
            });
        }
    }
    return resolverSet;
}
Also used : HashedResolverSet(org.mule.runtime.module.extension.internal.runtime.resolver.HashedResolverSet) ResolverSet(org.mule.runtime.module.extension.internal.runtime.resolver.ResolverSet) NullSafeModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.NullSafeModelProperty) HashedResolverSet(org.mule.runtime.module.extension.internal.runtime.resolver.HashedResolverSet) ParameterGroupDescriptor(org.mule.runtime.module.extension.internal.loader.ParameterGroupDescriptor) ParameterGroupModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ParameterGroupModelProperty) MetadataType(org.mule.metadata.api.model.MetadataType) ParametersResolver(org.mule.runtime.module.extension.internal.runtime.resolver.ParametersResolver) ParameterGroupModel(org.mule.runtime.api.meta.model.parameter.ParameterGroupModel) StaticValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.StaticValueResolver)

Aggregations

ResolverSet (org.mule.runtime.module.extension.internal.runtime.resolver.ResolverSet)11 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)4 Test (org.junit.Test)2 MuleContext (org.mule.runtime.core.api.MuleContext)2 ConfigurationException (org.mule.runtime.core.api.config.ConfigurationException)2 ClassUtils.withContextClassLoader (org.mule.runtime.core.api.util.ClassUtils.withContextClassLoader)2 ImplicitObjectUtils.buildImplicitResolverSet (org.mule.runtime.module.extension.internal.loader.utils.ImplicitObjectUtils.buildImplicitResolverSet)2 ConnectionProviderResolver (org.mule.runtime.module.extension.internal.runtime.resolver.ConnectionProviderResolver)2 ImplicitConnectionProviderValueResolver (org.mule.runtime.module.extension.internal.runtime.resolver.ImplicitConnectionProviderValueResolver)2 SmallTest (org.mule.tck.size.SmallTest)2 HeisenbergExtension (org.mule.test.heisenberg.extension.HeisenbergExtension)2 String.format (java.lang.String.format)1 Thread.currentThread (java.lang.Thread.currentThread)1 Optional (java.util.Optional)1 Optional.empty (java.util.Optional.empty)1 Optional.ofNullable (java.util.Optional.ofNullable)1 MetadataType (org.mule.metadata.api.model.MetadataType)1 MuleException (org.mule.runtime.api.exception.MuleException)1 I18nMessageFactory.createStaticMessage (org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage)1 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)1