use of org.apache.qpid.protonj2.client.exceptions.ClientResourceRemotelyClosedException in project qpid-protonj2 by apache.
the class SenderTest method testSendBlockedForCreditFailsWhenLinkRemotelyClosed.
@Test
public void testSendBlockedForCreditFailsWhenLinkRemotelyClosed() throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.expectAttach().ofSender().respond();
peer.remoteDetach().withErrorCondition(AmqpError.RESOURCE_DELETED.toString(), "Link was deleted").afterDelay(25).queue();
peer.expectDetach();
peer.expectClose().respond();
peer.start();
URI remoteURI = peer.getServerURI();
LOG.info("Sender test started, peer listening on: {}", remoteURI);
Client container = Client.create();
Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort());
Session session = connection.openSession();
Sender sender = session.openSender("test-queue");
sender.openFuture().get();
Message<String> message = Message.create("Hello World");
try {
sender.send(message);
fail("Send should have timed out.");
} catch (ClientResourceRemotelyClosedException cliEx) {
// Expected send to throw indicating that the remote closed the link
}
connection.closeAsync().get();
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
use of org.apache.qpid.protonj2.client.exceptions.ClientResourceRemotelyClosedException in project qpid-protonj2 by apache.
the class ClientExceptionSupport method convertToNonFatalException.
/**
* Given an ErrorCondition instance create a new Exception that best matches
* the error type that indicates a non-fatal error usually at the link level
* such as link closed remotely or link create failed due to security access
* issues.
*
* @param errorCondition
* The ErrorCondition returned from the remote peer.
*
* @return a new Exception instance that best matches the ErrorCondition value.
*/
public static ClientException convertToNonFatalException(ErrorCondition errorCondition) {
final ClientException remoteError;
if (errorCondition != null && errorCondition.getCondition() != null) {
Symbol error = errorCondition.getCondition();
String message = extractErrorMessage(errorCondition);
if (error.equals(AmqpError.RESOURCE_LIMIT_EXCEEDED)) {
remoteError = new ClientResourceRemotelyClosedException(message, new ClientErrorCondition(errorCondition));
} else if (error.equals(AmqpError.NOT_FOUND)) {
remoteError = new ClientResourceRemotelyClosedException(message, new ClientErrorCondition(errorCondition));
} else if (error.equals(LinkError.DETACH_FORCED)) {
remoteError = new ClientResourceRemotelyClosedException(message, new ClientErrorCondition(errorCondition));
} else if (error.equals(LinkError.REDIRECT)) {
remoteError = createLinkRedirectException(error, message, errorCondition);
} else if (error.equals(AmqpError.RESOURCE_DELETED)) {
remoteError = new ClientResourceRemotelyClosedException(message, new ClientErrorCondition(errorCondition));
} else if (error.equals(TransactionErrors.TRANSACTION_ROLLBACK)) {
remoteError = new ClientTransactionRolledBackException(message);
} else {
remoteError = new ClientException(message);
}
} else {
remoteError = new ClientException("Unknown error from remote peer");
}
return remoteError;
}
use of org.apache.qpid.protonj2.client.exceptions.ClientResourceRemotelyClosedException in project qpid-protonj2 by apache.
the class ClientLinkType method handleParentEndpointClosed.
protected final void handleParentEndpointClosed(ProtonType link) {
// shutdown notification and respond to that change.
if (link.getEngine().isRunning()) {
final ClientException failureCause;
if (link.getConnection().getRemoteCondition() != null) {
failureCause = ClientExceptionSupport.convertToConnectionClosedException(link.getConnection().getRemoteCondition());
} else if (link.getSession().getRemoteCondition() != null) {
failureCause = ClientExceptionSupport.convertToSessionClosedException(link.getSession().getRemoteCondition());
} else if (link.getEngine().failureCause() != null) {
failureCause = ClientExceptionSupport.convertToConnectionClosedException(link.getEngine().failureCause());
} else if (!isClosed()) {
failureCause = new ClientResourceRemotelyClosedException("Remote closed without a specific error condition");
} else {
failureCause = null;
}
immediateLinkShutdown(failureCause);
}
}
use of org.apache.qpid.protonj2.client.exceptions.ClientResourceRemotelyClosedException in project qpid-protonj2 by apache.
the class ClientStreamReceiver method linkSpecificCleanupHandler.
@Override
protected void linkSpecificCleanupHandler(ClientException failureCause) {
// If the parent of this sender is a stream session than this sender owns it
// and must close it when it closes itself to ensure that the resources are
// cleaned up on the remote for the session.
session.closeAsync();
receiveRequests.forEach((future, timeout) -> {
if (timeout != null) {
timeout.cancel(false);
}
if (failureCause != null) {
future.failed(failureCause);
} else {
future.failed(new ClientResourceRemotelyClosedException("The Stream Receiver has closed"));
}
});
protonReceiver.unsettled().forEach((delivery) -> {
if (delivery.getLinkedResource() != null) {
try {
delivery.getLinkedResource(ClientStreamDelivery.class).handleReceiverClosed(this);
} catch (Exception ex) {
}
}
});
if (drainingTimeout != null) {
drainingFuture.failed(failureCause != null ? failureCause : new ClientResourceRemotelyClosedException("The Receiver has been closed"));
drainingTimeout.cancel(false);
drainingTimeout = null;
}
}
use of org.apache.qpid.protonj2.client.exceptions.ClientResourceRemotelyClosedException in project qpid-protonj2 by apache.
the class SenderTest method testSendBlockedForCreditFailsWhenSessionRemotelyClosed.
@Test
public void testSendBlockedForCreditFailsWhenSessionRemotelyClosed() throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.expectAttach().ofSender().respond();
peer.remoteEnd().withErrorCondition(AmqpError.RESOURCE_DELETED.toString(), "Session was deleted").afterDelay(25).queue();
peer.expectEnd();
peer.expectClose().respond();
peer.start();
URI remoteURI = peer.getServerURI();
LOG.info("Sender test started, peer listening on: {}", remoteURI);
Client container = Client.create();
Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort());
Session session = connection.openSession();
Sender sender = session.openSender("test-queue");
sender.openFuture().get();
Message<String> message = Message.create("Hello World");
try {
sender.send(message);
fail("Send should have timed out.");
} catch (ClientResourceRemotelyClosedException cliEx) {
// Expected send to throw indicating that the remote closed the session
}
connection.closeAsync().get();
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
Aggregations