Search in sources :

Example 11 with ClientConnectionRemotelyClosedException

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

Example 12 with ClientConnectionRemotelyClosedException

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

Example 13 with ClientConnectionRemotelyClosedException

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

Example 14 with ClientConnectionRemotelyClosedException

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);
    }
}
Also used : ProtonTestServer(org.apache.qpid.protonj2.test.driver.ProtonTestServer) ClientConnectionRemotelyClosedException(org.apache.qpid.protonj2.client.exceptions.ClientConnectionRemotelyClosedException) Connection(org.apache.qpid.protonj2.client.Connection) Receiver(org.apache.qpid.protonj2.client.Receiver) 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 15 with ClientConnectionRemotelyClosedException

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);
    }
}
Also used : ProtonTestServer(org.apache.qpid.protonj2.test.driver.ProtonTestServer) ClientConnectionRemotelyClosedException(org.apache.qpid.protonj2.client.exceptions.ClientConnectionRemotelyClosedException) Connection(org.apache.qpid.protonj2.client.Connection) Receiver(org.apache.qpid.protonj2.client.Receiver) 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

ClientConnectionRemotelyClosedException (org.apache.qpid.protonj2.client.exceptions.ClientConnectionRemotelyClosedException)25 URI (java.net.URI)18 Client (org.apache.qpid.protonj2.client.Client)18 Connection (org.apache.qpid.protonj2.client.Connection)18 ProtonTestServer (org.apache.qpid.protonj2.test.driver.ProtonTestServer)18 Test (org.junit.jupiter.api.Test)16 Session (org.apache.qpid.protonj2.client.Session)14 Sender (org.apache.qpid.protonj2.client.Sender)8 ConnectionOptions (org.apache.qpid.protonj2.client.ConnectionOptions)7 ExecutionException (java.util.concurrent.ExecutionException)6 ClientException (org.apache.qpid.protonj2.client.exceptions.ClientException)5 Receiver (org.apache.qpid.protonj2.client.Receiver)4 ClientIllegalStateException (org.apache.qpid.protonj2.client.exceptions.ClientIllegalStateException)4 Tracker (org.apache.qpid.protonj2.client.Tracker)3 ClientConnectionSecurityException (org.apache.qpid.protonj2.client.exceptions.ClientConnectionSecurityException)2 ClientIOException (org.apache.qpid.protonj2.client.exceptions.ClientIOException)2 ClientTransactionRolledBackException (org.apache.qpid.protonj2.client.exceptions.ClientTransactionRolledBackException)2 Connection (org.apache.qpid.protonj2.engine.Connection)2 Symbol (org.apache.qpid.protonj2.types.Symbol)2 IOException (java.io.IOException)1