Search in sources :

Example 1 with ClientResourceRemotelyClosedException

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);
    }
}
Also used : Sender(org.apache.qpid.protonj2.client.Sender) ProtonTestServer(org.apache.qpid.protonj2.test.driver.ProtonTestServer) ClientResourceRemotelyClosedException(org.apache.qpid.protonj2.client.exceptions.ClientResourceRemotelyClosedException) Connection(org.apache.qpid.protonj2.client.Connection) Client(org.apache.qpid.protonj2.client.Client) URI(java.net.URI) Session(org.apache.qpid.protonj2.client.Session) Test(org.junit.jupiter.api.Test)

Example 2 with ClientResourceRemotelyClosedException

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;
}
Also used : ClientTransactionRolledBackException(org.apache.qpid.protonj2.client.exceptions.ClientTransactionRolledBackException) ClientResourceRemotelyClosedException(org.apache.qpid.protonj2.client.exceptions.ClientResourceRemotelyClosedException) Symbol(org.apache.qpid.protonj2.types.Symbol) ClientException(org.apache.qpid.protonj2.client.exceptions.ClientException)

Example 3 with ClientResourceRemotelyClosedException

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);
    }
}
Also used : ClientResourceRemotelyClosedException(org.apache.qpid.protonj2.client.exceptions.ClientResourceRemotelyClosedException) ClientException(org.apache.qpid.protonj2.client.exceptions.ClientException)

Example 4 with ClientResourceRemotelyClosedException

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;
    }
}
Also used : ClientResourceRemotelyClosedException(org.apache.qpid.protonj2.client.exceptions.ClientResourceRemotelyClosedException) ClientIllegalStateException(org.apache.qpid.protonj2.client.exceptions.ClientIllegalStateException) ClientResourceRemotelyClosedException(org.apache.qpid.protonj2.client.exceptions.ClientResourceRemotelyClosedException) ClientException(org.apache.qpid.protonj2.client.exceptions.ClientException) ClientOperationTimedOutException(org.apache.qpid.protonj2.client.exceptions.ClientOperationTimedOutException)

Example 5 with ClientResourceRemotelyClosedException

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);
    }
}
Also used : Sender(org.apache.qpid.protonj2.client.Sender) ProtonTestServer(org.apache.qpid.protonj2.test.driver.ProtonTestServer) ClientResourceRemotelyClosedException(org.apache.qpid.protonj2.client.exceptions.ClientResourceRemotelyClosedException) Connection(org.apache.qpid.protonj2.client.Connection) Client(org.apache.qpid.protonj2.client.Client) URI(java.net.URI) Session(org.apache.qpid.protonj2.client.Session) Test(org.junit.jupiter.api.Test)

Aggregations

ClientResourceRemotelyClosedException (org.apache.qpid.protonj2.client.exceptions.ClientResourceRemotelyClosedException)5 ClientException (org.apache.qpid.protonj2.client.exceptions.ClientException)3 URI (java.net.URI)2 Client (org.apache.qpid.protonj2.client.Client)2 Connection (org.apache.qpid.protonj2.client.Connection)2 Sender (org.apache.qpid.protonj2.client.Sender)2 Session (org.apache.qpid.protonj2.client.Session)2 ProtonTestServer (org.apache.qpid.protonj2.test.driver.ProtonTestServer)2 Test (org.junit.jupiter.api.Test)2 ClientIllegalStateException (org.apache.qpid.protonj2.client.exceptions.ClientIllegalStateException)1 ClientOperationTimedOutException (org.apache.qpid.protonj2.client.exceptions.ClientOperationTimedOutException)1 ClientTransactionRolledBackException (org.apache.qpid.protonj2.client.exceptions.ClientTransactionRolledBackException)1 Symbol (org.apache.qpid.protonj2.types.Symbol)1