use of org.apache.qpid.protonj2.client.exceptions.ClientConnectionSecurityException in project qpid-protonj2 by apache.
the class ClientExceptionSupport method convertToConnectionClosedException.
/**
* Given an ErrorCondition instance create a new Exception that best matches
* the error type that indicates the connection creation failed for some reason.
*
* @param errorCondition
* The ErrorCondition returned from the remote peer.
*
* @return a new Exception instance that best matches the ErrorCondition value.
*/
public static ClientConnectionRemotelyClosedException convertToConnectionClosedException(ErrorCondition errorCondition) {
final ClientConnectionRemotelyClosedException remoteError;
if (errorCondition != null && errorCondition.getCondition() != null) {
Symbol error = errorCondition.getCondition();
String message = extractErrorMessage(errorCondition);
if (error.equals(AmqpError.UNAUTHORIZED_ACCESS)) {
remoteError = new ClientConnectionSecurityException(message, new ClientErrorCondition(errorCondition));
} else if (error.equals(ConnectionError.REDIRECT)) {
remoteError = createConnectionRedirectException(error, message, errorCondition);
} else {
remoteError = new ClientConnectionRemotelyClosedException(message, new ClientErrorCondition(errorCondition));
}
} else {
remoteError = new ClientConnectionRemotelyClosedException("Unknown error from remote peer");
}
return remoteError;
}
use of org.apache.qpid.protonj2.client.exceptions.ClientConnectionSecurityException in project qpid-protonj2 by apache.
the class ReconnectTest method testConnectThrowsSecurityViolationOnFailureFromOpen.
@Test
public void testConnectThrowsSecurityViolationOnFailureFromOpen() throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().reject(AmqpError.UNAUTHORIZED_ACCESS.toString(), "Anonymous connections not allowed");
// Could arrive if remote open response not processed in time
peer.expectBegin().optional();
peer.expectClose();
peer.start();
ConnectionOptions options = new ConnectionOptions();
options.reconnectOptions().reconnectEnabled(true);
URI remoteURI = peer.getServerURI();
Client container = Client.create();
Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort(), options);
try {
connection.openFuture().get();
} catch (ExecutionException exe) {
// Possible based on time of rejecting open arrival.
assertTrue(exe.getCause() instanceof ClientConnectionSecurityException);
}
try {
connection.defaultSession().openFuture().get();
fail("Should fail connection since remote rejected open with auth error");
} catch (ClientConnectionSecurityException cliEx) {
} catch (ExecutionException exe) {
assertTrue(exe.getCause() instanceof ClientConnectionSecurityException);
}
connection.close();
try {
connection.defaultSession();
fail("Should fail as illegal state as connection was closed.");
} catch (ClientIllegalStateException exe) {
}
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
Aggregations