Search in sources :

Example 1 with SourceCallbackContext

use of org.mule.runtime.extension.api.runtime.source.SourceCallbackContext in project mule by mulesoft.

the class SourceResultArgumentResolver method resolve.

@Override
public LazyValue<SourceResult> resolve(ExecutionContext executionContext) {
    return new LazyValue<>(() -> {
        Error error = errorArgumentResolver.resolve(executionContext).get();
        SourceCallbackContext callbackContext = callbackContextArgumentResolver.resolve(executionContext).get();
        if (error == null) {
            return success(callbackContext);
        } else {
            String errorIdentifier = error.getErrorType().getIdentifier();
            return isErrorGeneratingErrorResponse(errorIdentifier) ? invocationError(error, callbackContext) : responseError(error, callbackContext);
        }
    });
}
Also used : LazyValue(org.mule.runtime.api.util.LazyValue) SourceCallbackContext(org.mule.runtime.extension.api.runtime.source.SourceCallbackContext) SourceResult.responseError(org.mule.runtime.extension.api.runtime.source.SourceResult.responseError) SourceResult.invocationError(org.mule.runtime.extension.api.runtime.source.SourceResult.invocationError) Error(org.mule.runtime.api.message.Error)

Example 2 with SourceCallbackContext

use of org.mule.runtime.extension.api.runtime.source.SourceCallbackContext in project mule by mulesoft.

the class PetStoreSource method onStart.

@Override
public void onStart(SourceCallback<String, Object> sourceCallback) throws MuleException {
    SourceCallbackContext context = sourceCallback.createContext();
    context.setCorrelationId(breeder.getBirds());
    sourceCallback.handle(Result.<String, Object>builder().output(encoding).build(), context);
}
Also used : SourceCallbackContext(org.mule.runtime.extension.api.runtime.source.SourceCallbackContext)

Example 3 with SourceCallbackContext

use of org.mule.runtime.extension.api.runtime.source.SourceCallbackContext in project mule by mulesoft.

the class TransactionalSource method onStart.

@Override
public void onStart(SourceCallback<TestTransactionalConnection, Object> sourceCallback) throws MuleException {
    connectExecutor = newFixedThreadPool(1);
    connectExecutor.execute(() -> {
        SourceCallbackContext ctx = sourceCallback.createContext();
        try {
            TestTransactionalConnection connection = connectionProvider.connect();
            boolean isXa = false;
            if (connection instanceof XATransactionalConnection) {
                isXa = true;
                xaResource = (DummyXaResource) ((XATransactionalConnection) connection).getXAResource();
            }
            ctx.addVariable(IS_XA, isXa);
            ctx.bindConnection(connection);
            sourceCallback.handle(Result.<TestTransactionalConnection, Object>builder().output(connection).build(), ctx);
        } catch (ConnectionException e) {
            sourceCallback.onConnectionException(e);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    });
}
Also used : SourceCallbackContext(org.mule.runtime.extension.api.runtime.source.SourceCallbackContext) TestTransactionalConnection(org.mule.test.transactional.connection.TestTransactionalConnection) XATransactionalConnection(org.mule.runtime.extension.api.connectivity.XATransactionalConnection) ConnectionException(org.mule.runtime.api.connection.ConnectionException) ConnectionException(org.mule.runtime.api.connection.ConnectionException) TransactionException(org.mule.runtime.api.tx.TransactionException) MuleException(org.mule.runtime.api.exception.MuleException)

Aggregations

SourceCallbackContext (org.mule.runtime.extension.api.runtime.source.SourceCallbackContext)3 ConnectionException (org.mule.runtime.api.connection.ConnectionException)1 MuleException (org.mule.runtime.api.exception.MuleException)1 Error (org.mule.runtime.api.message.Error)1 TransactionException (org.mule.runtime.api.tx.TransactionException)1 LazyValue (org.mule.runtime.api.util.LazyValue)1 XATransactionalConnection (org.mule.runtime.extension.api.connectivity.XATransactionalConnection)1 SourceResult.invocationError (org.mule.runtime.extension.api.runtime.source.SourceResult.invocationError)1 SourceResult.responseError (org.mule.runtime.extension.api.runtime.source.SourceResult.responseError)1 TestTransactionalConnection (org.mule.test.transactional.connection.TestTransactionalConnection)1