use of org.apache.qpid.protonj2.client.exceptions.ClientConnectionRemotelyClosedException in project qpid-protonj2 by apache.
the class ClientStreamSender method recreateLinkForReconnect.
@Override
protected void recreateLinkForReconnect() {
protonSender.localCloseHandler(null);
protonSender.localDetachHandler(null);
protonSender.close();
if (protonSender.hasUnsettled()) {
failPendingUnsettledAndBlockedSends(new ClientConnectionRemotelyClosedException("Connection failed and send result is unknown"));
}
protonSender = ClientSenderBuilder.recreateSender(session, protonSender, options);
protonSender.setLinkedResource(this);
}
use of org.apache.qpid.protonj2.client.exceptions.ClientConnectionRemotelyClosedException 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.ClientConnectionRemotelyClosedException in project qpid-protonj2 by apache.
the class ClientSession method handleEngineShutdown.
private void handleEngineShutdown(Engine engine) {
// opened once the remote has been recovered.
if (!connection.getEngine().isShutdown()) {
// No local close processing needed but we should try and let the session
// clean up any resources it can by closing it.
protonSession.localCloseHandler(null);
protonSession.close();
protonSession = configureSession(ClientSessionBuilder.recreateSession(connection, protonSession, options));
open();
} else {
final Connection connection = engine.connection();
final ClientException failureCause;
if (connection.getRemoteCondition() != null) {
failureCause = ClientExceptionSupport.convertToConnectionClosedException(connection.getRemoteCondition());
} else if (engine.failureCause() != null) {
failureCause = ClientExceptionSupport.convertToConnectionClosedException(engine.failureCause());
} else if (!isClosed()) {
failureCause = new ClientConnectionRemotelyClosedException("Remote closed without a specific error condition");
} else {
failureCause = null;
}
immediateSessionShutdown(failureCause);
}
}
use of org.apache.qpid.protonj2.client.exceptions.ClientConnectionRemotelyClosedException in project qpid-protonj2 by apache.
the class ReceiverTest method testReceiveBlockedForMessageFailsWhenConnectionRemotelyClosed.
@Test
public void testReceiveBlockedForMessageFailsWhenConnectionRemotelyClosed() throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.expectAttach().ofReceiver().respond();
peer.expectFlow().withLinkCredit(10);
peer.remoteClose().withErrorCondition(AmqpError.RESOURCE_DELETED.toString(), "Connection was deleted").afterDelay(25).queue();
peer.expectClose();
peer.start();
URI remoteURI = peer.getServerURI();
LOG.info("Receiver test started, peer listening on: {}", remoteURI);
Client container = Client.create();
Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort());
Session session = connection.openSession();
Receiver receiver = session.openReceiver("test-queue");
receiver.openFuture().get();
try {
receiver.receive();
fail("Receive should have failed when Connection remotely closed.");
} catch (ClientConnectionRemotelyClosedException cliEx) {
// Expected
}
connection.closeAsync().get();
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
use of org.apache.qpid.protonj2.client.exceptions.ClientConnectionRemotelyClosedException in project qpid-protonj2 by apache.
the class ReceiverTest method testTimedReceiveBlockedForMessageFailsWhenConnectionRemotelyClosed.
@Test
public void testTimedReceiveBlockedForMessageFailsWhenConnectionRemotelyClosed() throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.expectAttach().ofReceiver().respond();
peer.expectFlow().withLinkCredit(10);
peer.remoteClose().withErrorCondition(AmqpError.RESOURCE_DELETED.toString(), "Connection was deleted").afterDelay(25).queue();
peer.expectClose();
peer.start();
URI remoteURI = peer.getServerURI();
LOG.info("Receiver test started, peer listening on: {}", remoteURI);
Client container = Client.create();
Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort());
Session session = connection.openSession();
Receiver receiver = session.openReceiver("test-queue");
receiver.openFuture().get();
try {
receiver.receive(10, TimeUnit.SECONDS);
fail("Receive should have failed when Connection remotely closed.");
} catch (ClientConnectionRemotelyClosedException cliEx) {
// Expected send to throw indicating that the remote closed the connection
}
connection.closeAsync().get();
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
Aggregations