Search in sources :

Example 21 with BaseEventContext

use of org.mule.runtime.core.privileged.event.BaseEventContext in project mule by mulesoft.

the class ExtensionComponent method getMetadataContext.

private MetadataContext getMetadataContext() throws MetadataResolvingException {
    CoreEvent fakeEvent = null;
    try {
        fakeEvent = getInitialiserEvent(muleContext);
        Optional<ConfigurationInstance> configuration = getConfiguration(fakeEvent);
        if (configuration.isPresent()) {
            ConfigurationProvider configurationProvider = findConfigurationProvider().orElseThrow(() -> new MetadataResolvingException("Failed to create the required configuration for Metadata retrieval", INVALID_CONFIGURATION));
            if (configurationProvider instanceof DynamicConfigurationProvider) {
                throw new MetadataResolvingException("Configuration used for Metadata fetch cannot be dynamic", INVALID_CONFIGURATION);
            }
        }
        String cacheId = configuration.map(ConfigurationInstance::getName).orElseGet(() -> extensionModel.getName() + "|" + componentModel.getName());
        return new DefaultMetadataContext(() -> configuration, connectionManager, metadataService.getMetadataCache(cacheId), typeLoader);
    } finally {
        if (fakeEvent != null) {
            ((BaseEventContext) fakeEvent.getContext()).success();
        }
    }
}
Also used : BaseEventContext(org.mule.runtime.core.privileged.event.BaseEventContext) MetadataResolvingException(org.mule.runtime.api.metadata.MetadataResolvingException) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) ConfigurationProvider(org.mule.runtime.extension.api.runtime.config.ConfigurationProvider) DynamicConfigurationProvider(org.mule.runtime.module.extension.internal.runtime.config.DynamicConfigurationProvider) DynamicConfigurationProvider(org.mule.runtime.module.extension.internal.runtime.config.DynamicConfigurationProvider) DefaultMetadataContext(org.mule.runtime.module.extension.internal.metadata.DefaultMetadataContext) ConfigurationInstance(org.mule.runtime.extension.api.runtime.config.ConfigurationInstance)

Example 22 with BaseEventContext

use of org.mule.runtime.core.privileged.event.BaseEventContext in project mule by mulesoft.

the class DefaultConfigurationProviderFactory method createStaticConfigurationProvider.

/**
 * {@inheritDoc}
 */
@Override
public ConfigurationProvider createStaticConfigurationProvider(String name, ExtensionModel extensionModel, ConfigurationModel configurationModel, ResolverSet resolverSet, ConnectionProviderValueResolver connectionProviderResolver, ReflectionCache reflectionCache, MuleContext muleContext) throws Exception {
    return withExtensionClassLoader(extensionModel, () -> {
        configureConnectionProviderResolver(name, connectionProviderResolver);
        ConfigurationInstance configuration;
        CoreEvent initialiserEvent = null;
        try {
            initialiserEvent = getInitialiserEvent(muleContext);
            initialiseIfNeeded(resolverSet, true, muleContext);
            configuration = new ConfigurationInstanceFactory(extensionModel, configurationModel, resolverSet, reflectionCache, muleContext).createConfiguration(name, initialiserEvent, connectionProviderResolver);
        } catch (MuleException e) {
            throw new ConfigurationException(createStaticMessage(format("Could not create configuration '%s' for the '%s'", name, extensionModel.getName())), e);
        } finally {
            if (initialiserEvent != null) {
                ((BaseEventContext) initialiserEvent.getContext()).success();
            }
        }
        return new ConfigurationProviderToolingAdapter(name, extensionModel, configurationModel, configuration, reflectionCache, muleContext);
    });
}
Also used : BaseEventContext(org.mule.runtime.core.privileged.event.BaseEventContext) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) ConfigurationException(org.mule.runtime.core.api.config.ConfigurationException) MuleException(org.mule.runtime.api.exception.MuleException) ConfigurationInstance(org.mule.runtime.extension.api.runtime.config.ConfigurationInstance)

Example 23 with BaseEventContext

use of org.mule.runtime.core.privileged.event.BaseEventContext in project mule by mulesoft.

the class OAuthConnectionProviderObjectBuilder method getInitialOAuthConfig.

private OAuthConfig getInitialOAuthConfig() throws MuleException {
    CoreEvent initialiserEvent = null;
    try {
        initialiserEvent = getInitialiserEvent(muleContext);
        MapValueResolver mapResolver = staticOnly((MapValueResolver) resolverSet.getResolvers().get(OAUTH_AUTHORIZATION_CODE_GROUP_NAME));
        AuthCodeConfig authCodeConfig = buildAuthCodeConfig(mapResolver.resolve(from(initialiserEvent)));
        Optional<OAuthObjectStoreConfig> storeConfig = buildOAuthObjectStoreConfig(initialiserEvent);
        mapResolver = staticOnly((MapValueResolver) resolverSet.getResolvers().get(OAUTH_CALLBACK_GROUP_NAME));
        OAuthCallbackConfig callbackConfig = buildOAuthCallbackConfig(mapResolver.resolve(from(initialiserEvent)));
        return new OAuthConfig(ownerConfigName, authCodeConfig, callbackConfig, storeConfig, grantType, getCustomParameters(initialiserEvent), callbackValues);
    } finally {
        if (initialiserEvent != null) {
            ((BaseEventContext) initialiserEvent.getContext()).success();
        }
    }
}
Also used : BaseEventContext(org.mule.runtime.core.privileged.event.BaseEventContext) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) MapValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.MapValueResolver)

Example 24 with BaseEventContext

use of org.mule.runtime.core.privileged.event.BaseEventContext in project mule by mulesoft.

the class ReflectiveOperationExecutorFactory method createExecutor.

@Override
public ComponentExecutor<M> createExecutor(M operationModel, Map<String, Object> parameters) {
    DefaultObjectBuilder objectBuilder = new DefaultObjectBuilder(implementationClass);
    parameters.forEach((k, v) -> objectBuilder.addPropertyResolver(k, new StaticValueResolver<>(v)));
    Object delegate;
    CoreEvent initialiserEvent = null;
    try {
        initialiserEvent = getInitialiserEvent();
        delegate = objectBuilder.build(from(initialiserEvent));
    } catch (Exception e) {
        throw new MuleRuntimeException(createStaticMessage("Could not create instance of operation class " + implementationClass.getName()), e);
    } finally {
        if (initialiserEvent != null) {
            ((BaseEventContext) initialiserEvent.getContext()).success();
        }
    }
    return new ReflectiveMethodOperationExecutor(operationModel, operationMethod, delegate);
}
Also used : BaseEventContext(org.mule.runtime.core.privileged.event.BaseEventContext) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) StaticValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.StaticValueResolver) ReflectiveMethodOperationExecutor(org.mule.runtime.module.extension.internal.runtime.operation.ReflectiveMethodOperationExecutor) DefaultObjectBuilder(org.mule.runtime.module.extension.internal.runtime.objectbuilder.DefaultObjectBuilder) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException)

Example 25 with BaseEventContext

use of org.mule.runtime.core.privileged.event.BaseEventContext in project mule by mulesoft.

the class ParameterGroupObjectBuilder method build.

public T build(ResolverSetResult result) throws MuleException {
    final Map<String, Object> resultMap = result.asMap();
    CoreEvent initialiserEvent = null;
    try {
        initialiserEvent = getInitialiserEvent();
        return doBuild(resultMap::containsKey, resultMap::get, from(initialiserEvent));
    } finally {
        if (initialiserEvent != null) {
            ((BaseEventContext) initialiserEvent.getContext()).success();
        }
    }
}
Also used : BaseEventContext(org.mule.runtime.core.privileged.event.BaseEventContext) CoreEvent(org.mule.runtime.core.api.event.CoreEvent)

Aggregations

BaseEventContext (org.mule.runtime.core.privileged.event.BaseEventContext)45 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)34 Test (org.junit.Test)24 MuleException (org.mule.runtime.api.exception.MuleException)10 Message (org.mule.runtime.api.message.Message)10 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)8 MessagingException (org.mule.runtime.core.internal.exception.MessagingException)7 Description (io.qameta.allure.Description)6 Optional.of (java.util.Optional.of)6 HeisenbergExtension (org.mule.test.heisenberg.extension.HeisenbergExtension)6 Optional (java.util.Optional)5 CompletableFuture (java.util.concurrent.CompletableFuture)5 EventContext (org.mule.runtime.api.event.EventContext)5 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)5 Publisher (org.reactivestreams.Publisher)5 Mono.from (reactor.core.publisher.Mono.from)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 Processor (org.mule.runtime.core.api.processor.Processor)4 InternalMessage (org.mule.runtime.core.internal.message.InternalMessage)4 String.format (java.lang.String.format)3