use of org.mule.runtime.extension.api.runtime.config.ConfigurationInstance in project mule by mulesoft.
the class CompositeArtifactExtensionManagerTestCase method returnsConfigurationFromProviderName.
@Test
public void returnsConfigurationFromProviderName() throws Exception {
ExtensionModel childExtension = mock(ExtensionModel.class);
Set<ExtensionModel> childExtensions = singleton(childExtension);
when(childExtensionManager.getExtensions()).thenReturn(childExtensions);
when(parentExtensionManager.getExtensions()).thenReturn(emptySet());
CompositeArtifactExtensionManager extensionManager = new CompositeArtifactExtensionManager(parentExtensionManager, childExtensionManager);
CoreEvent event = mock(CoreEvent.class);
ConfigurationProvider childConfigurationProvider = mock(ConfigurationProvider.class);
ConfigurationInstance configurationInstance = mock(ConfigurationInstance.class);
when(childConfigurationProvider.get(event)).thenReturn(configurationInstance);
when(childExtensionManager.getConfigurationProvider(PROVIDER_NAME)).thenReturn(of(childConfigurationProvider));
when(parentExtensionManager.getConfigurationProvider(PROVIDER_NAME)).thenReturn(empty());
ConfigurationInstance configuration = extensionManager.getConfiguration(PROVIDER_NAME, event);
assertThat(configuration, is(configurationInstance));
}
use of org.mule.runtime.extension.api.runtime.config.ConfigurationInstance 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();
}
}
}
use of org.mule.runtime.extension.api.runtime.config.ConfigurationInstance 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);
});
}
use of org.mule.runtime.extension.api.runtime.config.ConfigurationInstance in project mule by mulesoft.
the class DefaultImplicitConfigurationProviderFactory method createImplicitConfigurationProvider.
/**
* {@inheritDoc}
*/
@Override
public ConfigurationProvider createImplicitConfigurationProvider(ExtensionModel extensionModel, ConfigurationModel implicitConfigurationModel, CoreEvent event, ReflectionCache reflectionCache, MuleContext muleContext) {
if (implicitConfigurationModel == null || !canBeUsedImplicitly(implicitConfigurationModel)) {
throw new IllegalStateException("Could not find a config for extension '" + extensionModel.getName() + "' and none can be created automatically. Please define one");
}
final String providerName = getImplicitConfigurationProviderName(extensionModel, implicitConfigurationModel);
Callable<ResolverSet> resolverSetCallable = () -> buildImplicitResolverSet(implicitConfigurationModel, reflectionCache, muleContext);
ClassLoader pluginClassloader = getClassLoader(extensionModel);
final ResolverSet resolverSet = withContextClassLoader(pluginClassloader, resolverSetCallable);
try {
ImplicitConnectionProviderValueResolver implicitConnectionProviderValueResolver = new ImplicitConnectionProviderValueResolver(implicitConfigurationModel.getName(), extensionModel, implicitConfigurationModel, reflectionCache, muleContext);
ConfigurationInstance configurationInstance = withContextClassLoader(pluginClassloader, () -> new ConfigurationInstanceFactory(extensionModel, implicitConfigurationModel, resolverSet, reflectionCache, muleContext).createConfiguration(providerName, event, implicitConnectionProviderValueResolver));
if (resolverSet.isDynamic() || needsDynamicConnectionProvider(extensionModel, implicitConfigurationModel, implicitConnectionProviderValueResolver)) {
return new DynamicConfigurationProvider(providerName, extensionModel, implicitConfigurationModel, resolverSet, implicitConnectionProviderValueResolver, ImmutableExpirationPolicy.getDefault(new LocalTimeSupplier()), reflectionCache, muleContext);
}
return new ConfigurationProviderToolingAdapter(providerName, extensionModel, implicitConfigurationModel, configurationInstance, reflectionCache, muleContext);
} catch (Exception e) {
throw new MuleRuntimeException(createStaticMessage(format("Could not create an implicit configuration '%s' for the extension '%s'", implicitConfigurationModel.getName(), extensionModel.getName())), e);
}
}
use of org.mule.runtime.extension.api.runtime.config.ConfigurationInstance in project mule by mulesoft.
the class UnauthorizeOperationExecutor method execute.
@Override
public Publisher<Object> execute(ExecutionContext<ComponentModel> executionContext) {
ConfigurationInstance config = executionContext.getConfiguration().get();
String ownerId = executionContext.hasParameter(RESOURCE_OWNER_ID_PARAMETER_NAME) ? executionContext.getParameter(RESOURCE_OWNER_ID_PARAMETER_NAME) : DEFAULT_RESOURCE_OWNER_ID;
oauthManager.invalidate(config.getName(), ownerId);
return Mono.empty();
}
Aggregations