use of org.mule.runtime.api.connection.ConnectionException 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);
}
});
}
use of org.mule.runtime.api.connection.ConnectionException in project mule by mulesoft.
the class PoolingConnectionManagementStrategyTestCase method exhaustion.
@Test
public void exhaustion() throws Exception {
poolingProfile = new PoolingProfile(1, 1, DEFAULT_MAX_POOL_WAIT, WHEN_EXHAUSTED_FAIL, INITIALISE_NONE);
initStrategy();
ConnectionHandler<Object> connectionHandler = strategy.getConnectionHandler();
try {
strategy.getConnectionHandler();
fail("Was expecting the pool to be exhausted");
} catch (ConnectionException e) {
// wiiiii
}
connectionHandler.release();
assertThat(strategy.getConnectionHandler(), is(notNullValue()));
}
use of org.mule.runtime.api.connection.ConnectionException in project mule by mulesoft.
the class ConnectionArgumentResolver method resolve.
/**
* Returns the connection previously set on the {@code executionContext} under the key
* {@link ExtensionProperties#CONNECTION_PARAM}
*
* @param executionContext an {@link ExecutionContext}
* @return the connection
* @throws IllegalArgumentException if the connection was not set
* @throws ClassCastException if {@code executionContext} is not an {@link ExecutionContextAdapter}
*/
@Override
public LazyValue<Object> resolve(ExecutionContext executionContext) {
return new LazyValue<>(() -> {
ConnectionHandler connectionHandler = ((ExecutionContextAdapter<ComponentModel>) executionContext).getVariable(CONNECTION_PARAM);
checkArgument(connectionHandler != null, "No connection was provided for the component [" + executionContext.getComponentModel().getName() + "]");
try {
return connectionHandler.getConnection();
} catch (ConnectionException e) {
throw new MuleRuntimeException(I18nMessageFactory.createStaticMessage(String.format("Error was found trying to obtain a connection to execute %s '%s' of extension '%s'", getComponentModelTypeName(executionContext.getComponentModel()), executionContext.getComponentModel().getName(), executionContext.getExtensionModel().getName())), e);
}
});
}
use of org.mule.runtime.api.connection.ConnectionException in project mule by mulesoft.
the class ReconnectionWithStreamingTestCase method createMockCursor.
private CursorStream createMockCursor() throws IOException {
CursorStream cursorStream = mock(CursorStream.class);
when(cursorStream.getPosition()).thenReturn(ORIGINAL_POSITION);
when(cursorStream.read(any(byte[].class), anyInt(), anyInt())).thenThrow(new RuntimeException(new ConnectionException("kaboom"))).thenAnswer(i -> {
byte[] buffer = (byte[]) i.getArguments()[0];
buffer[0] = 'h';
buffer[1] = 'n';
return 2;
}).thenReturn(-1);
return cursorStream;
}
use of org.mule.runtime.api.connection.ConnectionException in project mule by mulesoft.
the class DsqlQueryMetadataResolver method getOutputType.
/**
* Automatically resolves the output metadata for the {@link DsqlQuery}.
* <p>
* The base entity is resolved using the component {@link QueryEntityResolver} and assuming the key of the entity is the DSQL
* {@link DsqlQuery#getType() type}.
*
* @param context {@link MetadataContext} of the MetaData resolution
* @param query the {@link DsqlQuery} to resolve the output metadata from.
*/
@Override
public MetadataType getOutputType(MetadataContext context, Object query) throws MetadataResolvingException, ConnectionException {
if (query instanceof DsqlQuery) {
DsqlQuery dsqlQuery = (DsqlQuery) query;
MetadataType entityMetadata = entityResolver.getEntityMetadata(context, dsqlQuery.getType().getName());
BaseTypeBuilder builder = context.getTypeBuilder();
final List<Field> fields = dsqlQuery.getFields();
if (fields.size() == 1 && fields.get(0).getName().equals("*")) {
return entityMetadata;
}
entityMetadata.accept(new MetadataTypeVisitor() {
@Override
public void visitObject(ObjectType objectType) {
ObjectTypeBuilder objectTypeBuilder = builder.objectType();
objectType.getFields().stream().filter(p -> fields.stream().anyMatch(f -> f.getName().equalsIgnoreCase(p.getKey().getName().getLocalPart()))).forEach(p -> {
ObjectFieldTypeBuilder field = objectTypeBuilder.addField();
field.key(p.getKey().getName());
field.value(p.getValue());
});
}
});
return builder.build();
} else {
return nativeOutputResolver.getOutputType(context, query);
}
}
Aggregations