From fc50d3132480f7225281e2fbc7fa751ea49e2e29 Mon Sep 17 00:00:00 2001 From: Robert Gemmell Date: Thu, 26 May 2011 14:27:07 +0000 Subject: QPID-3277: AMQCallbackHandler improvements. Refactor AMQCallbackHandler to accept ConnectionURL in place of AMQProtocolSession (improved information hiding, ease ability to write good unit tests). Remove unused protected constructor from AMQConnection and MockAMQConnection. Applied patch from Keith Wall git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1127939 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/qpid/client/AMQConnection.java | 56 ++++++------ .../handler/ConnectionStartMethodHandler.java | 2 +- .../qpid/client/protocol/AMQProtocolSession.java | 10 --- .../qpid/client/security/AMQCallbackHandler.java | 4 +- .../UsernameHashedPasswordCallbackHandler.java | 30 +++---- .../security/UsernamePasswordCallbackHandler.java | 17 ++-- .../org/apache/qpid/client/MockAMQConnection.java | 5 -- .../UsernameHashedPasswordCallbackHandlerTest.java | 99 ++++++++++++++++++++++ .../UsernamePasswordCallbackHandlerTest.java | 78 +++++++++++++++++ 9 files changed, 230 insertions(+), 71 deletions(-) create mode 100644 qpid/java/client/src/test/java/org/apache/qpid/client/security/UsernameHashedPasswordCallbackHandlerTest.java create mode 100644 qpid/java/client/src/test/java/org/apache/qpid/client/security/UsernamePasswordCallbackHandlerTest.java diff --git a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnection.java b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnection.java index ab59fee020..94a55ef52c 100644 --- a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnection.java +++ b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnection.java @@ -111,7 +111,7 @@ public class AMQConnection extends Closeable implements Connection, QueueConnect /** Maps from session id (Integer) to AMQSession instance */ private final ChannelToSessionMap _sessions = new ChannelToSessionMap(); - private String _clientName; + private final String _clientName; /** The user name to use for authentication */ private String _username; @@ -126,7 +126,7 @@ public class AMQConnection extends Closeable implements Connection, QueueConnect private ConnectionListener _connectionListener; - private ConnectionURL _connectionURL; + private final ConnectionURL _connectionURL; /** * Whether this connection is started, i.e. whether messages are flowing to consumers. It has no meaning for message @@ -257,6 +257,11 @@ public class AMQConnection extends Closeable implements Connection, QueueConnect */ public AMQConnection(ConnectionURL connectionURL, SSLConfiguration sslConfig) throws AMQException { + if (connectionURL == null) + { + throw new IllegalArgumentException("Connection must be specified"); + } + // set this connection maxPrefetch if (connectionURL.getOption(ConnectionURL.OPTIONS_MAXPREFETCH) != null) { @@ -264,7 +269,7 @@ public class AMQConnection extends Closeable implements Connection, QueueConnect } else { - // use the defaul value set for all connections + // use the default value set for all connections _maxPrefetch = Integer.parseInt(System.getProperties().getProperty(ClientProperties.MAX_PREFETCH_PROP_NAME, ClientProperties.MAX_PREFETCH_DEFAULT)); } @@ -278,7 +283,7 @@ public class AMQConnection extends Closeable implements Connection, QueueConnect } else { - // use the defaul value set for all connections + // use the default value set for all connections _syncPersistence = Boolean.getBoolean(ClientProperties.SYNC_PERSISTENT_PROP_NAME); if (_syncPersistence) { @@ -293,7 +298,7 @@ public class AMQConnection extends Closeable implements Connection, QueueConnect } else { - // use the defaul value set for all connections + // use the default value set for all connections _syncAck = Boolean.getBoolean(ClientProperties.SYNC_ACK_PROP_NAME); } @@ -346,11 +351,6 @@ public class AMQConnection extends Closeable implements Connection, QueueConnect } _sslConfiguration = sslConfig; - if (connectionURL == null) - { - throw new IllegalArgumentException("Connection must be specified"); - } - _connectionURL = connectionURL; _clientName = connectionURL.getClientName(); @@ -535,14 +535,6 @@ public class AMQConnection extends Closeable implements Connection, QueueConnect } } - protected AMQConnection(String username, String password, String clientName, String virtualHost) - { - _clientName = clientName; - _username = username; - _password = password; - setVirtualHost(virtualHost); - } - private void setVirtualHost(String virtualHost) { if (virtualHost != null && virtualHost.startsWith("/")) @@ -696,20 +688,6 @@ public class AMQConnection extends Closeable implements Connection, QueueConnect } } - private void reopenChannel(int channelId, int prefetchHigh, int prefetchLow, boolean transacted) - throws AMQException, FailoverException - { - try - { - createChannelOverWire(channelId, prefetchHigh, prefetchLow, transacted); - } - catch (AMQException e) - { - deregisterSession(channelId); - throw new AMQException(null, "Error reopening channel " + channelId + " after failover: " + e, e); - } - } - public void setFailoverPolicy(FailoverPolicy policy) { _failoverPolicy = policy; @@ -1372,6 +1350,20 @@ public class AMQConnection extends Closeable implements Connection, QueueConnect return buf.toString(); } + /** + * Returns connection url. + * @return connection url + */ + public ConnectionURL getConnectionURL() + { + return _connectionURL; + } + + /** + * Returns stringified connection url. This url is suitable only for display + * as {@link AMQConnectionURL#toString()} converts any password to asterisks. + * @return connection url + */ public String toURL() { return _connectionURL.toString(); diff --git a/qpid/java/client/src/main/java/org/apache/qpid/client/handler/ConnectionStartMethodHandler.java b/qpid/java/client/src/main/java/org/apache/qpid/client/handler/ConnectionStartMethodHandler.java index c81ad6422f..2b49bb8f81 100644 --- a/qpid/java/client/src/main/java/org/apache/qpid/client/handler/ConnectionStartMethodHandler.java +++ b/qpid/java/client/src/main/java/org/apache/qpid/client/handler/ConnectionStartMethodHandler.java @@ -226,7 +226,7 @@ public class ConnectionStartMethodHandler implements StateAwareMethodListener