You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by rg...@apache.org on 2014/08/08 14:30:03 UTC
svn commit: r1616736 - in /qpid/trunk/qpid/java:
client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolHandler.java
common/src/main/java/org/apache/qpid/transport/network/security/ssl/SSLReceiver.java
Author: rgodfrey
Date: Fri Aug 8 12:30:03 2014
New Revision: 1616736
URL: http://svn.apache.org/r1616736
Log:
QPID-5978 : [Java Client] fail faster when a TCP connection is established, but the AMQP layer is not - e.g. due to SSL negotiation failure
Modified:
qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolHandler.java
qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/transport/network/security/ssl/SSLReceiver.java
Modified: qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolHandler.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolHandler.java?rev=1616736&r1=1616735&r2=1616736&view=diff
==============================================================================
--- qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolHandler.java (original)
+++ qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolHandler.java Fri Aug 8 12:30:03 2014
@@ -20,8 +20,16 @@
*/
package org.apache.qpid.client.protocol;
-import org.apache.qpid.client.HeartbeatListener;
-import org.apache.qpid.util.BytesDataOutput;
+import java.io.IOException;
+import java.net.SocketAddress;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.concurrent.CopyOnWriteArraySet;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -31,6 +39,7 @@ import org.apache.qpid.AMQException;
import org.apache.qpid.AMQTimeoutException;
import org.apache.qpid.client.AMQConnection;
import org.apache.qpid.client.AMQSession;
+import org.apache.qpid.client.HeartbeatListener;
import org.apache.qpid.client.failover.FailoverException;
import org.apache.qpid.client.failover.FailoverHandler;
import org.apache.qpid.client.failover.FailoverState;
@@ -59,16 +68,7 @@ import org.apache.qpid.thread.Threading;
import org.apache.qpid.transport.Sender;
import org.apache.qpid.transport.TransportException;
import org.apache.qpid.transport.network.NetworkConnection;
-
-import java.io.IOException;
-import java.net.SocketAddress;
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.Set;
-import java.util.concurrent.CopyOnWriteArraySet;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
+import org.apache.qpid.util.BytesDataOutput;
/**
* AMQProtocolHandler is the client side protocol handler for AMQP, it handles all protocol events received from the
@@ -182,6 +182,7 @@ public class AMQProtocolHandler implemen
private long _lastReadTime = System.currentTimeMillis();
private long _lastWriteTime = System.currentTimeMillis();
private HeartbeatListener _heartbeatListener = HeartbeatListener.DEFAULT;
+ private Throwable _initialConnectionException;
/**
* Creates a new protocol handler, associated with the specified client connection instance.
@@ -219,6 +220,8 @@ public class AMQProtocolHandler implemen
// in order to execute AMQConnection#exceptionRecievedout out of synchronization block,
// otherwise it might deadlock with failover mutex
boolean failoverNotAllowed = false;
+ boolean failedWithoutConnecting = false;
+ Throwable initialConnectionException = null;
synchronized (this)
{
if (_logger.isDebugEnabled())
@@ -256,8 +259,11 @@ public class AMQProtocolHandler implemen
}
else
{
+ failedWithoutConnecting = true;
+ initialConnectionException = _initialConnectionException;
_logger.debug("We are in process of establishing the initial connection");
}
+ _initialConnectionException = null;
}
else
{
@@ -270,6 +276,16 @@ public class AMQProtocolHandler implemen
_connection.exceptionReceived(new AMQDisconnectedException(
"Server closed connection and reconnection not permitted.", _stateManager.getLastException()));
}
+ else if(failedWithoutConnecting)
+ {
+ if(initialConnectionException == null)
+ {
+ initialConnectionException = _stateManager.getLastException();
+ }
+ String message = initialConnectionException == null ? "" : initialConnectionException.getMessage();
+ _connection.exceptionReceived(new AMQDisconnectedException(
+ "Connection could not be established: " + message, initialConnectionException));
+ }
}
if (_logger.isDebugEnabled())
@@ -343,6 +359,7 @@ public class AMQProtocolHandler implemen
if (causeIsAConnectionProblem)
{
_logger.info("Connection exception caught therefore going to attempt failover: " + cause, cause);
+ _initialConnectionException = cause;
}
else
{
Modified: qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/transport/network/security/ssl/SSLReceiver.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/transport/network/security/ssl/SSLReceiver.java?rev=1616736&r1=1616735&r2=1616736&view=diff
==============================================================================
--- qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/transport/network/security/ssl/SSLReceiver.java (original)
+++ qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/transport/network/security/ssl/SSLReceiver.java Fri Aug 8 12:30:03 2014
@@ -20,17 +20,18 @@
*/
package org.apache.qpid.transport.network.security.ssl;
-import org.apache.qpid.transport.Receiver;
-import org.apache.qpid.transport.TransportException;
-import org.apache.qpid.transport.network.security.SSLStatus;
-import org.apache.qpid.transport.util.Logger;
+import java.nio.ByteBuffer;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLEngineResult;
import javax.net.ssl.SSLEngineResult.HandshakeStatus;
import javax.net.ssl.SSLEngineResult.Status;
import javax.net.ssl.SSLException;
-import java.nio.ByteBuffer;
+
+import org.apache.qpid.transport.Receiver;
+import org.apache.qpid.transport.TransportException;
+import org.apache.qpid.transport.network.security.SSLStatus;
+import org.apache.qpid.transport.util.Logger;
public class SSLReceiver implements Receiver<ByteBuffer>
{
@@ -192,7 +193,7 @@ public class SSLReceiver implements Rece
{
_sslStatus.getSslLock().notifyAll();
}
- exception(new TransportException("Error in SSLReceiver",e));
+ exception(new TransportException("Error in SSLReceiver: " + e.getMessage(),e));
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org