Search in sources :

Example 6 with ConnectionProvider

use of org.mule.runtime.api.connection.ConnectionProvider 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 7 with ConnectionProvider

use of org.mule.runtime.api.connection.ConnectionProvider in project mule by mulesoft.

the class DefaultExecutionMediatorTestCase method before.

@Before
public void before() throws Exception {
    when(configurationInstance.getStatistics()).thenReturn(configurationStats);
    when(configurationInstance.getName()).thenReturn(DUMMY_NAME);
    when(configurationInstance.getModel()).thenReturn(configurationModel);
    when(extensionModel.getName()).thenReturn(DUMMY_NAME);
    when(extensionModel.getModelProperty(ClassLoaderModelProperty.class)).thenReturn(empty());
    mockExceptionEnricher(extensionModel, null);
    mockExceptionEnricher(operationModel, null);
    when(operationExecutor.execute(operationContext)).thenReturn(just(result));
    when(operationExceptionExecutor.execute(operationContext)).thenReturn(error(exception));
    when(operationContext.getConfiguration()).thenReturn(Optional.of(configurationInstance));
    when(operationContext.getExtensionModel()).thenReturn(extensionModel);
    when(operationContext.getTransactionConfig()).thenReturn(empty());
    when(operationContext.getRetryPolicyTemplate()).thenReturn(empty());
    when(operationContext.getCurrentScheduler()).thenReturn(IMMEDIATE_SCHEDULER);
    when(extensionModel.getXmlDslModel()).thenReturn(XmlDslModel.builder().setPrefix("test-extension").build());
    mediator = new DefaultExecutionMediator(extensionModel, operationModel, new DefaultConnectionManager(muleContext), muleContext.getErrorTypeRepository());
    final ReconnectableConnectionProviderWrapper<Object> connectionProviderWrapper = new ReconnectableConnectionProviderWrapper<>(null, new ReconnectionConfig(true, new SimpleRetryPolicyTemplate(10, RETRY_COUNT)));
    initialiseIfNeeded(connectionProviderWrapper, true, muleContext);
    Optional<ConnectionProvider> connectionProvider = Optional.of(connectionProviderWrapper);
    when(configurationInstance.getConnectionProvider()).thenReturn(connectionProvider);
    when(exceptionEnricher.enrichException(exception)).thenReturn(new HeisenbergException(ERROR));
    setInterceptors((Interceptable) configurationInstance, configurationInterceptor1, configurationInterceptor2);
    setInterceptors((Interceptable) operationExecutor, operationInterceptor1, operationInterceptor2);
    defineOrder(configurationInterceptor1, configurationInterceptor2, operationInterceptor1, operationInterceptor2);
}
Also used : DefaultConnectionManager(org.mule.runtime.core.internal.connection.DefaultConnectionManager) SimpleRetryPolicyTemplate(org.mule.runtime.core.api.retry.policy.SimpleRetryPolicyTemplate) DefaultExecutionMediator(org.mule.runtime.module.extension.internal.runtime.operation.DefaultExecutionMediator) HeisenbergException(org.mule.test.heisenberg.extension.exception.HeisenbergException) ReconnectionConfig(org.mule.runtime.core.internal.retry.ReconnectionConfig) ReconnectableConnectionProviderWrapper(org.mule.runtime.core.internal.connection.ReconnectableConnectionProviderWrapper) ConnectionProvider(org.mule.runtime.api.connection.ConnectionProvider) Before(org.junit.Before)

Example 8 with ConnectionProvider

use of org.mule.runtime.api.connection.ConnectionProvider in project mule by mulesoft.

the class ExtensionConnectionSupplierTestCase method xaTransaction.

@Test
public void xaTransaction() throws Exception {
    muleContext.setTransactionManager(mock(TransactionManager.class, RETURNS_DEEP_STUBS));
    XaTransaction transaction = spy(new XaTransaction(muleContext));
    XATransactionalConnection connection = mock(XATransactionalConnection.class, RETURNS_DEEP_STUBS);
    Object config = new Object();
    ExecutionContextAdapter operationContext = mock(ExecutionContextAdapter.class, RETURNS_DEEP_STUBS);
    ConnectionProvider connectionProvider = mock(ConnectionProvider.class);
    ConfigurationInstance configurationInstance = mock(ConfigurationInstance.class);
    when(configurationInstance.getConnectionProvider()).thenReturn(of(connectionProvider));
    when(operationContext.getConfiguration()).thenReturn(of(configurationInstance));
    when(configurationInstance.getValue()).thenReturn(config);
    when(connectionProvider.connect()).thenReturn(connection);
    TransactionConfig transactionConfig = mock(TransactionConfig.class);
    when(transactionConfig.getAction()).thenReturn(ACTION_ALWAYS_JOIN);
    when(transactionConfig.isTransacted()).thenReturn(true);
    when(operationContext.getTransactionConfig()).thenReturn(of(transactionConfig));
    connectionManager.bind(config, connectionProvider);
    TransactionCoordination.getInstance().bindTransaction(transaction);
    adapter.getConnection(operationContext);
    verify(transaction).bindResource(any(), any(XAExtensionTransactionalResource.class));
}
Also used : XaTransaction(org.mule.runtime.core.privileged.transaction.XaTransaction) XAExtensionTransactionalResource(org.mule.runtime.module.extension.internal.runtime.transaction.XAExtensionTransactionalResource) TransactionManager(javax.transaction.TransactionManager) TransactionConfig(org.mule.runtime.core.api.transaction.TransactionConfig) XATransactionalConnection(org.mule.runtime.extension.api.connectivity.XATransactionalConnection) ExecutionContextAdapter(org.mule.runtime.module.extension.api.runtime.privileged.ExecutionContextAdapter) ConnectionProvider(org.mule.runtime.api.connection.ConnectionProvider) ConfigurationInstance(org.mule.runtime.extension.api.runtime.config.ConfigurationInstance) Test(org.junit.Test)

Aggregations

ConnectionProvider (org.mule.runtime.api.connection.ConnectionProvider)8 ReconnectionConfig (org.mule.runtime.core.internal.retry.ReconnectionConfig)3 ConfigurationInstance (org.mule.runtime.extension.api.runtime.config.ConfigurationInstance)3 Test (org.junit.Test)2 DefaultMuleException (org.mule.runtime.api.exception.DefaultMuleException)2 MuleException (org.mule.runtime.api.exception.MuleException)2 ConnectionProviderModel (org.mule.runtime.api.meta.model.connection.ConnectionProviderModel)2 ReconnectableConnectionProviderWrapper (org.mule.runtime.core.internal.connection.ReconnectableConnectionProviderWrapper)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 List (java.util.List)1 Lock (java.util.concurrent.locks.Lock)1 TransactionManager (javax.transaction.TransactionManager)1 CallbackHelper (net.sf.cglib.proxy.CallbackHelper)1 Enhancer (net.sf.cglib.proxy.Enhancer)1 Enhancer.registerStaticCallbacks (net.sf.cglib.proxy.Enhancer.registerStaticCallbacks)1 MethodInterceptor (net.sf.cglib.proxy.MethodInterceptor)1 ClassUtils (org.apache.commons.lang3.ClassUtils)1 Before (org.junit.Before)1 PoolingProfile (org.mule.runtime.api.config.PoolingProfile)1