Search in sources :

Example 16 with ConfigurationInstance

use of org.mule.runtime.extension.api.runtime.config.ConfigurationInstance in project mule by mulesoft.

the class OAuthOperationMessageProcessor method getOAuthConnectionProvider.

private OAuthConnectionProviderWrapper getOAuthConnectionProvider(ExecutionContextAdapter operationContext) {
    ConfigurationInstance config = ((ConfigurationInstance) operationContext.getConfiguration().get());
    ConnectionProvider provider = unwrapProviderWrapper(config.getConnectionProvider().get(), OAuthConnectionProviderWrapper.class);
    return provider instanceof OAuthConnectionProviderWrapper ? (OAuthConnectionProviderWrapper) provider : null;
}
Also used : OAuthConnectionProviderWrapper(org.mule.runtime.module.extension.internal.runtime.connectivity.oauth.OAuthConnectionProviderWrapper) ConfigurationInstance(org.mule.runtime.extension.api.runtime.config.ConfigurationInstance) ConnectionProvider(org.mule.runtime.api.connection.ConnectionProvider)

Example 17 with ConfigurationInstance

use of org.mule.runtime.extension.api.runtime.config.ConfigurationInstance in project mule by mulesoft.

the class ConfigOverrideValueResolverWrapper method getParameterValueFromConfigField.

private Function<Object, Object> getParameterValueFromConfigField(ConfigurationInstance config, String fieldName) {
    Field parameterField = getField(config.getValue().getClass(), fieldName, reflectionCache).orElseThrow(() -> new IllegalArgumentException("Missing field with name [" + fieldName + "] in config [" + config.getName() + "]"));
    parameterField.setAccessible(true);
    return (target) -> {
        try {
            return parameterField.get(target);
        } catch (IllegalAccessException e) {
            throw new IllegalArgumentException("Failed to read field with name [" + parameterField.getName() + " in config [" + config.getName() + "]: " + e.getMessage());
        }
    };
}
Also used : ParameterGroupDescriptor(org.mule.runtime.module.extension.internal.loader.ParameterGroupDescriptor) I18nMessageFactory.createStaticMessage(org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage) IntrospectionUtils.getField(org.mule.runtime.module.extension.internal.util.IntrospectionUtils.getField) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) Preconditions.checkArgument(org.mule.runtime.api.util.Preconditions.checkArgument) ReflectionCache(org.mule.runtime.module.extension.internal.util.ReflectionCache) LifecycleUtils.initialiseIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.initialiseIfNeeded) ConfigurationInstance(org.mule.runtime.extension.api.runtime.config.ConfigurationInstance) Initialisable(org.mule.runtime.api.lifecycle.Initialisable) Field(java.lang.reflect.Field) Function(java.util.function.Function) String.format(java.lang.String.format) DeclaringMemberModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.DeclaringMemberModelProperty) DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) StringUtils.isBlank(org.apache.commons.lang3.StringUtils.isBlank) MuleContext(org.mule.runtime.core.api.MuleContext) MuleException(org.mule.runtime.api.exception.MuleException) Optional(java.util.Optional) DEFAULT_GROUP_NAME(org.mule.runtime.api.meta.model.parameter.ParameterGroupModel.DEFAULT_GROUP_NAME) ParameterGroupModel(org.mule.runtime.api.meta.model.parameter.ParameterGroupModel) ParameterGroupModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ParameterGroupModelProperty) IntrospectionUtils.getField(org.mule.runtime.module.extension.internal.util.IntrospectionUtils.getField) Field(java.lang.reflect.Field)

Example 18 with ConfigurationInstance

use of org.mule.runtime.extension.api.runtime.config.ConfigurationInstance in project mule by mulesoft.

the class PetStoreConnectionTestCase method getPets.

@Test
public void getPets() throws Exception {
    ConfigurationInstance config = muleContext.getExtensionManager().getConfiguration("petstore", testEvent());
    assertThat(config, is(notNullValue()));
    CoreEvent response = runFlow("getPets");
    List<String> pets = (List<String>) response.getMessage().getPayload().getValue();
    PetStoreConnector configValue = (PetStoreConnector) config.getValue();
    assertThat(pets, containsInAnyOrder(configValue.getPets().toArray()));
}
Also used : PetStoreConnector(org.mule.test.petstore.extension.PetStoreConnector) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) List(java.util.List) ConfigurationInstance(org.mule.runtime.extension.api.runtime.config.ConfigurationInstance) Test(org.junit.Test)

Example 19 with ConfigurationInstance

use of org.mule.runtime.extension.api.runtime.config.ConfigurationInstance in project mule by mulesoft.

the class ConnectionlessMessageSourceTestCase method obtainDisconnectedSourceConfigParameters.

@Test
public void obtainDisconnectedSourceConfigParameters() throws Exception {
    Component element = locator.find(Location.builder().globalName("source").addSourcePart().build()).get();
    assertThat(element, is(instanceOf(ConfiguredComponent.class)));
    final ConfigurationInstance configurationInstance = ((ConfiguredComponent) element).getConfigurationInstance().get();
    ConfigurationState configurationState = configurationInstance.getState();
    assertThat(configurationState.getConfigParameters().size(), is(0));
    assertThat(configurationState.getConnectionParameters().size(), is(0));
}
Also used : ConfigurationState(org.mule.runtime.extension.api.runtime.config.ConfigurationState) ConfiguredComponent(org.mule.runtime.extension.api.runtime.config.ConfiguredComponent) Component(org.mule.runtime.api.component.Component) ConfigurationInstance(org.mule.runtime.extension.api.runtime.config.ConfigurationInstance) Test(org.junit.Test)

Example 20 with ConfigurationInstance

use of org.mule.runtime.extension.api.runtime.config.ConfigurationInstance in project mule by mulesoft.

the class TransactionSourceBinder method bindToTransaction.

public <T extends TransactionalConnection> Optional<ConnectionHandler<T>> bindToTransaction(TransactionConfig transactionConfig, ConfigurationInstance configurationInstance, ConnectionHandler connectionHandler) throws ConnectionException, TransactionException {
    if (!transactionConfig.isTransacted()) {
        return empty();
    }
    Transaction tx = transactionConfig.getFactory().beginTransaction(muleContext);
    tx.setTimeout(transactionConfig.getTimeout());
    ConfigurationInstance configuration = ofNullable(configurationInstance).orElseThrow(() -> new IllegalStateException(format("Source '%s' of extension '%s' cannot participate in a transaction because it doesn't have a config", componentModel.getName(), extensionModel.getName())));
    final ExtensionTransactionKey txKey = new ExtensionTransactionKey(configuration);
    return Optional.of(transactionBindingDelegate.getBoundResource(transactionConfig, txKey, () -> connectionHandler));
}
Also used : Transaction(org.mule.runtime.core.api.transaction.Transaction) ConfigurationInstance(org.mule.runtime.extension.api.runtime.config.ConfigurationInstance)

Aggregations

ConfigurationInstance (org.mule.runtime.extension.api.runtime.config.ConfigurationInstance)25 Test (org.junit.Test)12 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)9 SmallTest (org.mule.tck.size.SmallTest)9 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)7 ConfigurationProvider (org.mule.runtime.extension.api.runtime.config.ConfigurationProvider)7 MuleException (org.mule.runtime.api.exception.MuleException)5 ExtensionsTestUtils.mockConfigurationInstance (org.mule.test.module.extension.internal.util.ExtensionsTestUtils.mockConfigurationInstance)5 List (java.util.List)4 ConnectionProvider (org.mule.runtime.api.connection.ConnectionProvider)4 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)4 ReflectionCache (org.mule.runtime.module.extension.internal.util.ReflectionCache)4 String.format (java.lang.String.format)3 Optional (java.util.Optional)3 Optional.empty (java.util.Optional.empty)3 Optional.of (java.util.Optional.of)3 DefaultMuleException (org.mule.runtime.api.exception.DefaultMuleException)3 ComponentModel (org.mule.runtime.api.meta.model.ComponentModel)3 ResolverSet (org.mule.runtime.module.extension.internal.runtime.resolver.ResolverSet)3 ResolverSetResult (org.mule.runtime.module.extension.internal.runtime.resolver.ResolverSetResult)3