Search in sources :

Example 1 with ClientConnectionRemotelyClosedException

use of org.apache.qpid.protonj2.client.exceptions.ClientConnectionRemotelyClosedException in project qpid-protonj2 by apache.

the class ClientExceptionSupport method createConnectionRedirectException.

/**
 * When a connection redirect type exception is received this method is called to create the
 * appropriate redirect exception type containing the error details needed.
 *
 * @param error
 *        the Symbol that defines the redirection error type.
 * @param message
 *        the basic error message that should used or amended for the returned exception.
 * @param condition
 *        the ErrorCondition that describes the redirection.
 *
 * @return an Exception that captures the details of the redirection error.
 */
public static ClientConnectionRemotelyClosedException createConnectionRedirectException(Symbol error, String message, ErrorCondition condition) {
    ClientConnectionRemotelyClosedException result;
    Map<?, ?> info = condition.getInfo();
    if (info == null) {
        result = new ClientConnectionRemotelyClosedException(message + " : Redirection information not set.", new ClientErrorCondition(condition));
    } else {
        @SuppressWarnings("unchecked") ClientRedirect redirect = new ClientRedirect((Map<Symbol, Object>) info);
        try {
            result = new ClientConnectionRedirectedException(message, redirect.validate(), new ClientErrorCondition(condition));
        } catch (Exception ex) {
            result = new ClientConnectionRemotelyClosedException(message + " : " + ex.getMessage(), new ClientErrorCondition(condition));
        }
    }
    return result;
}
Also used : ClientConnectionRemotelyClosedException(org.apache.qpid.protonj2.client.exceptions.ClientConnectionRemotelyClosedException) Symbol(org.apache.qpid.protonj2.types.Symbol) ClientConnectionRedirectedException(org.apache.qpid.protonj2.client.exceptions.ClientConnectionRedirectedException) ClientLinkRedirectedException(org.apache.qpid.protonj2.client.exceptions.ClientLinkRedirectedException) SaslSystemException(org.apache.qpid.protonj2.engine.sasl.SaslSystemException) ClientIllegalStateException(org.apache.qpid.protonj2.client.exceptions.ClientIllegalStateException) ClientTransactionRolledBackException(org.apache.qpid.protonj2.client.exceptions.ClientTransactionRolledBackException) TimeoutException(java.util.concurrent.TimeoutException) ClientIOException(org.apache.qpid.protonj2.client.exceptions.ClientIOException) SaslException(javax.security.sasl.SaslException) ClientResourceRemotelyClosedException(org.apache.qpid.protonj2.client.exceptions.ClientResourceRemotelyClosedException) ClientException(org.apache.qpid.protonj2.client.exceptions.ClientException) ClientLinkRemotelyClosedException(org.apache.qpid.protonj2.client.exceptions.ClientLinkRemotelyClosedException) ClientConnectionRedirectedException(org.apache.qpid.protonj2.client.exceptions.ClientConnectionRedirectedException) ClientSessionRemotelyClosedException(org.apache.qpid.protonj2.client.exceptions.ClientSessionRemotelyClosedException) ClientConnectionSecurityException(org.apache.qpid.protonj2.client.exceptions.ClientConnectionSecurityException) ClientOperationTimedOutException(org.apache.qpid.protonj2.client.exceptions.ClientOperationTimedOutException) ClientConnectionRemotelyClosedException(org.apache.qpid.protonj2.client.exceptions.ClientConnectionRemotelyClosedException) ClientConnectionSecuritySaslException(org.apache.qpid.protonj2.client.exceptions.ClientConnectionSecuritySaslException)

Example 2 with ClientConnectionRemotelyClosedException

use of org.apache.qpid.protonj2.client.exceptions.ClientConnectionRemotelyClosedException in project qpid-protonj2 by apache.

the class ClientLinkType method handleEngineShutdown.

protected final void handleEngineShutdown(Engine engine) {
    if (!isDynamic() && !session.getConnection().getEngine().isShutdown()) {
        recreateLinkForReconnect();
        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;
        }
        immediateLinkShutdown(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 3 with ClientConnectionRemotelyClosedException

use of org.apache.qpid.protonj2.client.exceptions.ClientConnectionRemotelyClosedException in project qpid-protonj2 by apache.

the class ReconnectStreamSenderTest method testStreamMessageWriteThatFlushesFailsAfterConnectionDroppedAndReconnected.

@Test
public void testStreamMessageWriteThatFlushesFailsAfterConnectionDroppedAndReconnected() throws Exception {
    try (ProtonTestServer firstPeer = new ProtonTestServer();
        ProtonTestServer finalPeer = new ProtonTestServer()) {
        EncodedDataMatcher dataMatcher = new EncodedDataMatcher(new byte[] { 0, 1, 2, 3 });
        TransferPayloadCompositeMatcher payloadMatcher = new TransferPayloadCompositeMatcher();
        payloadMatcher.setMessageContentMatcher(dataMatcher);
        firstPeer.expectSASLAnonymousConnect();
        firstPeer.expectOpen().respond();
        firstPeer.expectBegin().respond();
        firstPeer.expectAttach().ofSender().respond();
        firstPeer.remoteFlow().withLinkCredit(1).queue();
        firstPeer.expectTransfer().withPayload(payloadMatcher).withMore(true);
        firstPeer.dropAfterLastHandler();
        firstPeer.start();
        finalPeer.expectSASLAnonymousConnect();
        finalPeer.expectOpen().respond();
        finalPeer.expectBegin().respond();
        finalPeer.expectAttach().ofSender().respond();
        finalPeer.start();
        final URI primaryURI = firstPeer.getServerURI();
        final URI backupURI = finalPeer.getServerURI();
        ConnectionOptions options = new ConnectionOptions();
        options.maxFrameSize(32768);
        options.idleTimeout(5, TimeUnit.SECONDS);
        options.reconnectOptions().reconnectEnabled(true);
        options.reconnectOptions().addReconnectLocation(backupURI.getHost(), backupURI.getPort());
        Client container = Client.create();
        Connection connection = container.connect(primaryURI.getHost(), primaryURI.getPort(), options);
        StreamSenderOptions senderOptions = new StreamSenderOptions();
        senderOptions.sendTimeout(1000);
        StreamSender sender = connection.openStreamSender("test-queue", senderOptions);
        StreamSenderMessage message = sender.beginMessage();
        OutputStream stream = message.body();
        stream.write(new byte[] { 0, 1, 2, 3 });
        stream.flush();
        firstPeer.waitForScriptToComplete();
        // Reconnection should have occurred now and we should not be able to flush data
        // from the stream as its initial sender instance was closed on disconnect.
        finalPeer.waitForScriptToComplete();
        // Ensure that idle processing happens in case send blocks so we can see the
        // send timed out exception
        finalPeer.remoteEmptyFrame().later(5000);
        finalPeer.remoteEmptyFrame().later(10000);
        finalPeer.remoteEmptyFrame().later(15000);
        // Test timeout kicks in now
        finalPeer.remoteEmptyFrame().later(20000);
        finalPeer.expectClose().respond();
        byte[] payload = new byte[1024];
        Arrays.fill(payload, (byte) 65);
        try {
            stream.write(payload);
            stream.flush();
            fail("Should not be able to write section after connection drop");
        } catch (IOException ioe) {
            assertFalse(ioe.getCause() instanceof ClientSendTimedOutException);
            assertTrue(ioe.getCause() instanceof ClientConnectionRemotelyClosedException);
        }
        connection.closeAsync().get();
        finalPeer.waitForScriptToComplete(5, TimeUnit.SECONDS);
    }
}
Also used : ProtonTestServer(org.apache.qpid.protonj2.test.driver.ProtonTestServer) OutputStream(java.io.OutputStream) EncodedDataMatcher(org.apache.qpid.protonj2.test.driver.matchers.types.EncodedDataMatcher) Connection(org.apache.qpid.protonj2.client.Connection) ClientSendTimedOutException(org.apache.qpid.protonj2.client.exceptions.ClientSendTimedOutException) IOException(java.io.IOException) TransferPayloadCompositeMatcher(org.apache.qpid.protonj2.test.driver.matchers.transport.TransferPayloadCompositeMatcher) URI(java.net.URI) StreamSenderOptions(org.apache.qpid.protonj2.client.StreamSenderOptions) ClientConnectionRemotelyClosedException(org.apache.qpid.protonj2.client.exceptions.ClientConnectionRemotelyClosedException) StreamSender(org.apache.qpid.protonj2.client.StreamSender) StreamSenderMessage(org.apache.qpid.protonj2.client.StreamSenderMessage) ConnectionOptions(org.apache.qpid.protonj2.client.ConnectionOptions) Client(org.apache.qpid.protonj2.client.Client) Test(org.junit.jupiter.api.Test)

Example 4 with ClientConnectionRemotelyClosedException

use of org.apache.qpid.protonj2.client.exceptions.ClientConnectionRemotelyClosedException in project qpid-protonj2 by apache.

the class ReconnectTest method testConnectionReportsFailedAfterMaxinitialReconnectAttempts.

@Test
public void testConnectionReportsFailedAfterMaxinitialReconnectAttempts() throws Exception {
    try (ProtonTestServer firstPeer = new ProtonTestServer()) {
        firstPeer.start();
        final URI primaryURI = firstPeer.getServerURI();
        firstPeer.close();
        ConnectionOptions options = new ConnectionOptions();
        options.reconnectOptions().reconnectEnabled(true);
        // Try forever if connect succeeds once.
        options.reconnectOptions().maxReconnectAttempts(-1);
        options.reconnectOptions().maxInitialConnectionAttempts(3);
        options.reconnectOptions().warnAfterReconnectAttempts(5);
        options.reconnectOptions().reconnectDelay(10);
        options.reconnectOptions().useReconnectBackOff(false);
        Client container = Client.create();
        Connection connection = container.connect(primaryURI.getHost(), primaryURI.getPort(), options);
        try {
            connection.openFuture().get();
            fail("Should not successfully connect.");
        } catch (ExecutionException exe) {
            assertTrue(exe.getCause() instanceof ClientConnectionRemotelyClosedException);
        }
        try {
            connection.defaultSender();
            fail("Connection should be in a failed state now.");
        } catch (ClientConnectionRemotelyClosedException cliEx) {
        }
        connection.close();
        try {
            connection.defaultSender();
            fail("Connection should be in a closed state now.");
        } catch (ClientIllegalStateException cliEx) {
        }
    }
}
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) ClientIllegalStateException(org.apache.qpid.protonj2.client.exceptions.ClientIllegalStateException) ConnectionOptions(org.apache.qpid.protonj2.client.ConnectionOptions) Client(org.apache.qpid.protonj2.client.Client) ExecutionException(java.util.concurrent.ExecutionException) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 5 with ClientConnectionRemotelyClosedException

use of org.apache.qpid.protonj2.client.exceptions.ClientConnectionRemotelyClosedException in project qpid-protonj2 by apache.

the class SenderTest method testSendBlockedForCreditFailsWhenConnectionDrops.

@Test
public void testSendBlockedForCreditFailsWhenConnectionDrops() throws Exception {
    try (ProtonTestServer peer = new ProtonTestServer()) {
        peer.expectSASLAnonymousConnect();
        peer.expectOpen().respond();
        peer.expectBegin().respond();
        peer.expectAttach().ofSender().respond();
        peer.dropAfterLastHandler(25);
        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 (ClientConnectionRemotelyClosedException cliEx) {
        // Expected send to throw indicating that the remote closed unexpectedly
        }
        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) ClientConnectionRemotelyClosedException(org.apache.qpid.protonj2.client.exceptions.ClientConnectionRemotelyClosedException) 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

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