Author: arnaudsimon
Date: Wed Apr  2 02:55:27 2008
New Revision: 643822

URL: http://svn.apache.org/viewvc?rev=643822&view=rev
Log:
QPID-829 Remove 0.10 specific URL. The code path is now selected based on 
broker response. We first try the highest protocol version and update the 
handler if the broker replies with a different protocol version. NOTE that we 
need to update the current java broker and 0.8 client for handling protocol 
headers. This should happen with the M2.1 merge. For the moment we only support 
an in VM 0.8 broker. Moreover, we'll need to migrate to a 0.10 vs 99.0 protocol 
version.

Added:
    
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/url/URLParser.java
      - copied, changed from r642963, 
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/url/URLParser_0_8.java
    
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/AMQProtocolException.java
    
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/ProtocolException.java
Removed:
    
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/url/URLParser_0_8.java
Modified:
    
incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/direct/direct.properties
    
incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/fanout/fanout.properties
    
incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/pubsub/pubsub.properties
    
incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/requestResponse.properties
    
incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/transacted/transacted.properties
    
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnection.java
    
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java
    
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionFactory.java
    
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionURL.java
    
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/jms/ConnectionURL.java
    
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/nclient/Client.java
    
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/tests.properties
    
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/protocol/AMQConstant.java
    
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/ErrorCode.java
    
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/ToyClient.java
    
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/transport/ConnectionDelegate.java
    
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/transport/TransportConstants.java
    incubator/qpid/trunk/qpid/java/test-provider.properties

Modified: 
incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/direct/direct.properties
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/direct/direct.properties?rev=643822&r1=643821&r2=643822&view=diff
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/direct/direct.properties
 (original)
+++ 
incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/direct/direct.properties
 Wed Apr  2 02:55:27 2008
@@ -20,7 +20,7 @@
 
 # register some connection factories
 # connectionfactory.[jndiname] = [ConnectionURL]
-connectionfactory.qpidConnectionfactory = qpid:password=pass;[EMAIL 
PROTECTED]:localhost:5672
+connectionfactory.qpidConnectionfactory = amqp://username:[EMAIL 
PROTECTED]/test?brokerlist='tcp://localhost:5672'
 
 # Register an AMQP destination in JNDI
 # destination.[jniName] = [BindingURL]

Modified: 
incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/fanout/fanout.properties
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/fanout/fanout.properties?rev=643822&r1=643821&r2=643822&view=diff
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/fanout/fanout.properties
 (original)
+++ 
incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/fanout/fanout.properties
 Wed Apr  2 02:55:27 2008
@@ -21,7 +21,7 @@
 
 # register some connection factories
 # connectionfactory.[jndiname] = [ConnectionURL]
-connectionfactory.qpidConnectionfactory = qpid:password=pass;[EMAIL 
PROTECTED]:localhost:5672
+connectionfactory.qpidConnectionfactory = amqp://username:[EMAIL 
PROTECTED]/test?brokerlist='tcp://localhost:5672'
 
 # Register an AMQP destination in JNDI
 # destination.[jniName] = [BindingURL]

Modified: 
incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/pubsub/pubsub.properties
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/pubsub/pubsub.properties?rev=643822&r1=643821&r2=643822&view=diff
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/pubsub/pubsub.properties
 (original)
+++ 
incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/pubsub/pubsub.properties
 Wed Apr  2 02:55:27 2008
@@ -21,7 +21,7 @@
 
 # register some connection factories
 # connectionfactory.[jndiname] = [ConnectionURL]
-connectionfactory.qpidConnectionfactory = qpid:password=pass;[EMAIL 
PROTECTED]:localhost:5672
+connectionfactory.qpidConnectionfactory = amqp://username:[EMAIL 
PROTECTED]/test?brokerlist='tcp://localhost:5672'
 
 # register some topics in JNDI using the form
 # topic.[jndiName] = [physicalName]

Modified: 
incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/requestResponse.properties
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/requestResponse.properties?rev=643822&r1=643821&r2=643822&view=diff
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/requestResponse.properties
 (original)
+++ 
incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/requestResponse.properties
 Wed Apr  2 02:55:27 2008
@@ -20,7 +20,7 @@
 
 # register some connection factories
 # connectionfactory.[jndiname] = [ConnectionURL]
-connectionfactory.qpidConnectionfactory = qpid:password=pass;[EMAIL 
PROTECTED]:localhost:5672
+connectionfactory.qpidConnectionfactory = amqp://username:[EMAIL 
PROTECTED]/test?brokerlist='tcp://localhost:5672'
 
 # register some queues in JNDI using the form
 # queue.[jndiName] = [physicalName]

Modified: 
incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/transacted/transacted.properties
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/transacted/transacted.properties?rev=643822&r1=643821&r2=643822&view=diff
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/transacted/transacted.properties
 (original)
+++ 
incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/transacted/transacted.properties
 Wed Apr  2 02:55:27 2008
@@ -20,7 +20,7 @@
 
 # register some connection factories
 # connectionfactory.[jndiname] = [ConnectionURL]
-connectionfactory.qpidConnectionfactory = qpid:password=pass;[EMAIL 
PROTECTED]:localhost:5672
+connectionfactory.qpidConnectionfactory = amqp://username:[EMAIL 
PROTECTED]/test?brokerlist='tcp://localhost:5672'
 
 # register some queues in JNDI using the form
 # queue.[jndiName] = [physicalName]

Modified: 
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnection.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnection.java?rev=643822&r1=643821&r2=643822&view=diff
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnection.java
 (original)
+++ 
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnection.java
 Wed Apr  2 02:55:27 2008
@@ -50,10 +50,7 @@
 import javax.naming.Referenceable;
 import javax.naming.StringRefAddr;
 
-import org.apache.qpid.AMQConnectionFailureException;
-import org.apache.qpid.AMQException;
-import org.apache.qpid.AMQUndeliveredException;
-import org.apache.qpid.AMQUnresolvedAddressException;
+import org.apache.qpid.*;
 import org.apache.qpid.client.failover.FailoverException;
 import org.apache.qpid.client.protocol.AMQProtocolHandler;
 import org.apache.qpid.exchange.ExchangeDefaults;
@@ -64,8 +61,8 @@
 import org.apache.qpid.jms.ConnectionURL;
 import org.apache.qpid.jms.FailoverPolicy;
 import org.apache.qpid.protocol.AMQConstant;
-import org.apache.qpid.url.QpidURL;
 import org.apache.qpid.url.URLSyntaxException;
+import org.apache.qpidity.transport.TransportConstants;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -234,30 +231,18 @@
      */
     public AMQConnection(ConnectionURL connectionURL, SSLConfiguration 
sslConfig) throws AMQException
     {
-        /* This JVM arg is only used for test code
-         Unless u pass a url it is difficult to determine which version to use
-         Most of the test code use an AMQConnection constructor that doesn't 
use
-         the url. So you need this switch to say which code path to test.
-
-        Another complication is that when a constructor is called with out a 
url
-        they would construct a 0-8 url and pass into the construtor that takes 
a url.
-
-        In such an instance u need the jvm argument to force an 0-10 connection
-        Once the 0-10 code base stabilises, 0-10 will be the default.
-        */
-
-        if (Boolean.getBoolean("SwitchCon"))
-        {
-            connectionURL.setURLVersion((Boolean.getBoolean("0-10")?  
ConnectionURL.URL_0_10:ConnectionURL.URL_0_8));
-        }
-
-        if (connectionURL.getURLVersion() == ConnectionURL.URL_0_10)
+        _failoverPolicy = new FailoverPolicy(connectionURL);
+        if 
(_failoverPolicy.getCurrentBrokerDetails().getTransport().equals(BrokerDetails.VM))
         {
-            _delegate = new AMQConnectionDelegate_0_10(this);
+            _delegate = new AMQConnectionDelegate_0_8(this);
         }
         else
         {
-            _delegate = new AMQConnectionDelegate_0_8(this);
+            // We always assume that the broker supports the lates AMQ 
protocol verions
+            // thie is currently 0.10
+            // TODO: use this code once we have switch to 0.10
+            // getDelegate();
+            _delegate = new AMQConnectionDelegate_0_10(this);
         }
 
         if (_logger.isInfoEnabled())
@@ -299,7 +284,6 @@
         }
 
 
-        _failoverPolicy = new FailoverPolicy(connectionURL);
         _protocolHandler = new AMQProtocolHandler(this);
 
         // We are not currently connected
@@ -316,6 +300,18 @@
                 lastException = null;
                 _connected = true;
             }
+            catch (AMQProtocolException pe)
+            {
+                if (_logger.isInfoEnabled())
+                {
+                    _logger.info(pe.getMessage());
+                    _logger.info("Trying broker supported protocol version: " +
+                            TransportConstants.getVersionMajor() + "." +
+                            TransportConstants.getVersionMinor());
+                }
+                // we need to check whether we have a delegate for the 
supported protocol
+                getDelegate();
+            }
             catch (Exception e)
             {
                 lastException = e;
@@ -381,6 +377,26 @@
         }
 
         _connectionMetaData = new QpidConnectionMetaData(this);
+    }
+
+    private void getDelegate() throws AMQProtocolException
+    {
+        try
+        {
+            Class c = 
Class.forName("org.apache.qpid.client.AMQConnectionDelegate_" +
+                    TransportConstants.getVersionMajor() + "_" +
+                    TransportConstants.getVersionMinor());
+             Class partypes[] = new Class[1];
+            partypes[0] = AMQConnection.class;
+            _delegate = (AMQConnectionDelegate) 
c.getConstructor(partypes).newInstance(this);
+        }
+        catch (Exception e)
+        {
+            throw new 
AMQProtocolException(AMQConstant.UNSUPPORTED_CLIENT_PROTOCOL_ERROR,
+                    "Protocol: " + TransportConstants.getVersionMajor() + "."
+            + TransportConstants.getVersionMinor() + " is rquired by the 
broker but is not " +
+                            "currently supported by this client library 
implementation", e);
+        }
     }
 
     protected AMQConnection(String username, String password, String 
clientName, String virtualHost)

Modified: 
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java?rev=643822&r1=643821&r2=643822&view=diff
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java
 (original)
+++ 
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java
 Wed Apr  2 02:55:27 2008
@@ -6,6 +6,7 @@
 import javax.jms.XASession;
 
 import org.apache.qpid.AMQException;
+import org.apache.qpid.AMQProtocolException;
 import org.apache.qpid.protocol.AMQConstant;
 import org.apache.qpid.client.failover.FailoverException;
 import org.apache.qpid.jms.BrokerDetails;
@@ -14,6 +15,7 @@
 import org.apache.qpidity.nclient.ClosedListener;
 import org.apache.qpidity.ErrorCode;
 import org.apache.qpidity.QpidException;
+import org.apache.qpidity.ProtocolException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -112,6 +114,10 @@
             _qpidConnection.connect(brokerDetail.getHost(), 
brokerDetail.getPort(), _conn.getVirtualHost(),
                                     _conn.getUsername(), _conn.getPassword());
             _qpidConnection.setClosedListener(this);
+        }
+        catch(ProtocolException pe)
+        {
+           throw new AMQProtocolException(null, pe.getMessage(), pe);
         }
         catch (QpidException e)
         {

Modified: 
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionFactory.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionFactory.java?rev=643822&r1=643821&r2=643822&view=diff
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionFactory.java
 (original)
+++ 
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionFactory.java
 Wed Apr  2 02:55:27 2008
@@ -37,6 +37,7 @@
 import org.apache.qpid.jms.ConnectionURL;
 import org.apache.qpid.url.AMQBindingURL;
 import org.apache.qpid.url.URLSyntaxException;
+import org.apache.qpidity.transport.TransportConstants;
 
 
 public class AMQConnectionFactory implements ConnectionFactory, 
QueueConnectionFactory, TopicConnectionFactory,
@@ -429,9 +430,10 @@
      */
     public XAConnection createXAConnection() throws JMSException
     {
-        if (_connectionDetails.getURLVersion() == ConnectionURL.URL_0_8)
+        if (TransportConstants.getVersionMajor() == 0 &&
+            TransportConstants.getVersionMinor() == 8)
         {
-            throw new UnsupportedOperationException("This version does not 
support XA operations");
+            throw new UnsupportedOperationException("This protocol version 
does not support XA operations");
         }
         else
         {

Modified: 
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionURL.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionURL.java?rev=643822&r1=643821&r2=643822&view=diff
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionURL.java
 (original)
+++ 
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionURL.java
 Wed Apr  2 02:55:27 2008
@@ -24,10 +24,8 @@
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
-import java.net.MalformedURLException;
 
-import org.apache.qpid.client.url.URLParser_0_8;
-import org.apache.qpid.client.url.URLParser_0_10;
+import org.apache.qpid.client.url.URLParser;
 import org.apache.qpid.framing.AMQShortString;
 import org.apache.qpid.jms.BrokerDetails;
 import org.apache.qpid.jms.ConnectionURL;
@@ -53,7 +51,6 @@
     private AMQShortString _defaultTopicExchangeName;
     private AMQShortString _temporaryTopicExchangeName;
     private AMQShortString _temporaryQueueExchangeName;
-    private byte _urlVersion;
 
     public AMQConnectionURL(String fullURL) throws URLSyntaxException
     {
@@ -62,48 +59,7 @@
         _options = new HashMap<String, String>();
         _brokers = new LinkedList<BrokerDetails>();
         _failoverOptions = new HashMap<String, String>();
-
-        if (!Boolean.getBoolean("SwitchCon"))
-        {
-            // We need to decided the version based on URL
-            if (fullURL.startsWith("qpid"))
-            {
-                //URLParser
-                URLParser_0_10 parser = null;
-                try
-                {
-                    parser = new URLParser_0_10(fullURL);
-                }
-                catch (MalformedURLException e)
-                {
-                    throw new URLSyntaxException(fullURL,e.getMessage(),0,0);
-                }
-                setBrokerDetails(parser.getAllBrokerDetails());
-                // use the first instance username and password
-                // This is temporary as the URL must be changed for olding 
this information as part of the full URL
-                BrokerDetails firstBroker = getBrokerDetails(0);
-                setUsername(firstBroker.getProperty(BrokerDetails.USERNAME));
-                setPassword(firstBroker.getProperty(BrokerDetails.PASSWORD));
-                
setClientName(firstBroker.getProperty(BrokerDetails.CLIENT_ID));
-                
setVirtualHost(firstBroker.getProperty(BrokerDetails.VIRTUAL_HOST));
-                _urlVersion = URL_0_10;
-            }
-            else
-            {
-                 new URLParser_0_8(this);
-                _urlVersion = URL_0_8;
-            }
-        }
-    }
-
-    public byte getURLVersion()
-    {
-        return _urlVersion;
-    }
-
-    public void setURLVersion(byte version)
-    {
-        _urlVersion = version;
+        new URLParser(this);
     }
 
     public String getURL()

Copied: 
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/url/URLParser.java
 (from r642963, 
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/url/URLParser_0_8.java)
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/url/URLParser.java?p2=incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/url/URLParser.java&p1=incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/url/URLParser_0_8.java&r1=642963&r2=643822&rev=643822&view=diff
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/url/URLParser_0_8.java
 (original)
+++ 
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/url/URLParser.java
 Wed Apr  2 02:55:27 2008
@@ -11,11 +11,11 @@
 import org.apache.qpid.url.URLHelper;
 import org.apache.qpid.url.URLSyntaxException;
 
-public class URLParser_0_8
+public class URLParser
 {
     private AMQConnectionURL _url;
 
-    public URLParser_0_8(AMQConnectionURL url)throws URLSyntaxException
+    public URLParser(AMQConnectionURL url)throws URLSyntaxException
     {
         _url = url;
         parseURL(_url.getURL());

Modified: 
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/jms/ConnectionURL.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/jms/ConnectionURL.java?rev=643822&r1=643821&r2=643822&view=diff
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/jms/ConnectionURL.java
 (original)
+++ 
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/jms/ConnectionURL.java
 Wed Apr  2 02:55:27 2008
@@ -43,11 +43,7 @@
     public static final String OPTIONS_TEMPORARY_QUEUE_EXCHANGE = 
"temporaryQueueExchange";
     public static final byte  URL_0_8 = 1;
     public static final byte  URL_0_10 = 2;
-
-    byte getURLVersion();
-
-    void setURLVersion(byte version);
-
+ 
     String getURL();
 
     String getFailoverMethod();

Modified: 
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/nclient/Client.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/nclient/Client.java?rev=643822&r1=643821&r2=643822&view=diff
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/nclient/Client.java
 (original)
+++ 
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/nclient/Client.java
 Wed Apr  2 02:55:27 2008
@@ -11,6 +11,7 @@
 import org.apache.qpid.url.QpidURL;
 import org.apache.qpidity.ErrorCode;
 import org.apache.qpidity.QpidException;
+import org.apache.qpidity.ProtocolException;
 import org.apache.qpidity.nclient.impl.ClientSession;
 import org.apache.qpidity.nclient.impl.ClientSessionDelegate;
 import org.apache.qpidity.transport.Channel;
@@ -49,14 +50,14 @@
 
     public void connect(String host, int port,String virtualHost,String 
username, String password) throws QpidException
     {
-        Condition negotiationComplete = _lock.newCondition();
+        final Condition negotiationComplete = _lock.newCondition();
         closeOk = _lock.newCondition();
         _lock.lock();
 
         ConnectionDelegate connectionDelegate = new ConnectionDelegate()
         {
             private boolean receivedClose = false;
-
+            private String _unsupportedProtocol;
             public SessionDelegate getSessionDelegate()
             {
                 return new ClientSessionDelegate();
@@ -115,6 +116,32 @@
 
                 this.receivedClose = true;
             }
+
+            @Override public void init(Channel ch, ProtocolHeader hdr)
+            {
+                // TODO: once the merge is done we'll need to update this code
+                // for handling 0.8 protocol version type i.e. major=8 and 
minor=0 :( 
+                if (hdr.getMajor() != TransportConstants.getVersionMajor()
+                        || hdr.getMinor() != 
TransportConstants.getVersionMinor())
+                {
+                    _unsupportedProtocol = 
TransportConstants.getVersionMajor() + "." +
+                                          TransportConstants.getVersionMinor();
+                    TransportConstants.setVersionMajor( hdr.getMajor() );
+                    TransportConstants.setVersionMinor( hdr.getMinor() );
+                    _lock.lock();
+                    negotiationComplete.signalAll();
+                    _lock.unlock();
+                }
+                else
+                {
+                    ch.connectionStart(hdr.getMajor(), hdr.getMinor(), null, 
"PLAIN", "utf8");
+                }
+            }
+
+            @Override public String getUnsupportedProtocol()
+            {
+                return _unsupportedProtocol;
+            }
         };
 
         connectionDelegate.setCondition(_lock,negotiationComplete);
@@ -123,8 +150,7 @@
         connectionDelegate.setVirtualHost(virtualHost);
 
         if (System.getProperty("transport","mina").equalsIgnoreCase("nio"))
-        {
-            System.out.println("Using NIO");
+        {            
             if( _logger.isDebugEnabled())
             {
                 _logger.debug("using NIO");
@@ -142,13 +168,21 @@
         }
 
         // XXX: hardcoded version numbers
-        _conn.send(new ConnectionEvent(0, new ProtocolHeader(1, 
TransportConstants.CONNECTION_VERSION_MAJOR, 
TransportConstants.CONNECTION_VERSION_MINOR)));
+        _conn.send(new ConnectionEvent(0, new ProtocolHeader(1, 
TransportConstants.getVersionMajor(),
+                TransportConstants.getVersionMinor())));
 
         try
         {
             negotiationComplete.await();
+            if( connectionDelegate.getUnsupportedProtocol() != null )
+            {
+                _conn.close();
+                throw new ProtocolException("Unsupported protocol version: " + 
connectionDelegate.getUnsupportedProtocol()
+                              , ErrorCode.UNSUPPORTED_PROTOCOL, null);
+
+            }
         }
-        catch (Exception e)
+        catch (InterruptedException e)
         {
             //
         }

Modified: 
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/tests.properties
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/tests.properties?rev=643822&r1=643821&r2=643822&view=diff
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/tests.properties
 (original)
+++ 
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/tests.properties
 Wed Apr  2 02:55:27 2008
@@ -23,7 +23,9 @@
 
 # register some connection factories
 # connectionfactory.[jndiname] = [ConnectionURL]
-connectionfactory.local = 
qpid:password=guest;username=guest;client_id=clientid;[EMAIL 
PROTECTED]:127.0.0.1:5672
+connectionfactory.local =  amqp://username:[EMAIL 
PROTECTED]/test?brokerlist='tcp://localhost:5672'
+#qpid:password=guest;username=guest;client_id=clientid;[EMAIL 
PROTECTED]:127.0.0.1:5672
+
                                                                      
 # register some queues in JNDI using the form
 # queue.[jndiName] = [physicalName]

Added: 
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/AMQProtocolException.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/AMQProtocolException.java?rev=643822&view=auto
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/AMQProtocolException.java
 (added)
+++ 
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/AMQProtocolException.java
 Wed Apr  2 02:55:27 2008
@@ -0,0 +1,38 @@
+package org.apache.qpid;
+
+import org.apache.qpid.protocol.AMQConstant;
+
+/* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*   http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied.  See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+
+public class AMQProtocolException extends AMQException
+{
+    /**
+     * Constructor for a Protocol Exception 
+     * <p> This is the only provided constructor and the parameters have to be
+     * set to null when they are unknown.
+     *
+     * @param msg       A description of the reason of this exception .
+     * @param errorCode A string specifyin the error code of this exception.
+     * @param cause     The linked Execption.
+     */
+    public AMQProtocolException(AMQConstant errorCode, String msg, Throwable 
cause)
+    {
+        super(errorCode, msg, cause);
+    }
+}

Modified: 
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/protocol/AMQConstant.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/protocol/AMQConstant.java?rev=643822&r1=643821&r2=643822&view=diff
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/protocol/AMQConstant.java
 (original)
+++ 
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/protocol/AMQConstant.java
 Wed Apr  2 02:55:27 2008
@@ -153,6 +153,15 @@
 
     public static final AMQConstant FRAME_MIN_SIZE = new AMQConstant(4096, 
"frame min size", true);
 
+    /**
+     * The server does not support the protocol version
+     */
+    public static final AMQConstant UNSUPPORTED_BROKER_PROTOCOL_ERROR = new 
AMQConstant(542, "broker unsupported protocol", true);
+    /**
+     * The client imp does not support the protocol version
+     */
+    public static final AMQConstant UNSUPPORTED_CLIENT_PROTOCOL_ERROR = new 
AMQConstant(543, "client unsupported protocol", true);
+
     /** The AMQP status code. */
     private int _code;
 

Modified: 
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/ErrorCode.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/ErrorCode.java?rev=643822&r1=643821&r2=643822&view=diff
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/ErrorCode.java
 (original)
+++ 
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/ErrorCode.java
 Wed Apr  2 02:55:27 2008
@@ -6,6 +6,7 @@
     UNDEFINED(1,"undefined",true),
     MESSAGE_REJECTED(2,"message_rejected",true),
     CONNECTION_ERROR(3,"connection was closed",true),
+    UNSUPPORTED_PROTOCOL(4, "protocol version is unsupported", true),
 
     //This might change in the spec, the error class is not applicable
     NO_ERROR(200,"reply-success",true),

Added: 
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/ProtocolException.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/ProtocolException.java?rev=643822&view=auto
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/ProtocolException.java
 (added)
+++ 
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/ProtocolException.java
 Wed Apr  2 02:55:27 2008
@@ -0,0 +1,36 @@
+/* Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.qpidity;
+
+public class ProtocolException extends QpidException
+{
+     /**
+     * Constructor for a Ptotocol Exception.
+     * <p> This is the only provided constructor and the parameters have to be 
set to null when
+     * they are unknown.
+     * @param message    A description of the reason of this exception.
+     * @param errorCode  A string specifyin the error code of this exception.
+     * @param cause     The linked Execption.
+     *
+     */
+    public ProtocolException(String message, ErrorCode errorCode, Throwable 
cause)
+    {
+        super(message, errorCode, cause);
+    }
+}

Modified: 
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/ToyClient.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/ToyClient.java?rev=643822&r1=643821&r2=643822&view=diff
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/ToyClient.java
 (original)
+++ 
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/ToyClient.java
 Wed Apr  2 02:55:27 2008
@@ -75,7 +75,9 @@
                                                   }
                                                   public void closed() {}
                                               });
-        conn.send(new ConnectionEvent(0, new ProtocolHeader(1, 
TransportConstants.CONNECTION_VERSION_MAJOR, 
TransportConstants.CONNECTION_VERSION_MINOR)));
+        conn.send(new ConnectionEvent(0, new ProtocolHeader(1,
+                TransportConstants.getVersionMajor(),
+                TransportConstants.getVersionMinor())));
 
         Channel ch = conn.getChannel(0);
         Session ssn = new Session();

Modified: 
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/transport/ConnectionDelegate.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/transport/ConnectionDelegate.java?rev=643822&r1=643821&r2=643822&view=diff
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/transport/ConnectionDelegate.java
 (original)
+++ 
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/transport/ConnectionDelegate.java
 Wed Apr  2 02:55:27 2008
@@ -83,7 +83,8 @@
         if (hdr.getMajor() != 0 && hdr.getMinor() != 10)
         {
             // XXX
-            ch.getConnection().send(new ConnectionEvent(0, new 
ProtocolHeader(1, TransportConstants.CONNECTION_VERSION_MAJOR, 
TransportConstants.CONNECTION_VERSION_MINOR)));
+            ch.getConnection().send(new ConnectionEvent(0, new 
ProtocolHeader(1, TransportConstants.getVersionMajor(),
+                    TransportConstants.getVersionMinor())));
             ch.getConnection().close();
         }
         else
@@ -281,5 +282,10 @@
     public void setVirtualHost(String host)
     {
         _virtualHost = host;
+    }
+
+    public String getUnsupportedProtocol()
+    {
+        return null;
     }
 }

Modified: 
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/transport/TransportConstants.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/transport/TransportConstants.java?rev=643822&r1=643821&r2=643822&view=diff
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/transport/TransportConstants.java
 (original)
+++ 
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/transport/TransportConstants.java
 Wed Apr  2 02:55:27 2008
@@ -2,6 +2,26 @@
 
 public class TransportConstants
 {
-    public static final byte CONNECTION_VERSION_MAJOR = 99;
-    public static final byte CONNECTION_VERSION_MINOR = 0;
+    private static byte _protocol_version_minor = 0;
+    private static byte _protocol_version_major = 99;
+
+    public static void setVersionMajor(byte value)
+    {
+        _protocol_version_major = value;
+    }
+
+    public static void setVersionMinor(byte value)
+    {
+        _protocol_version_minor = value;
+    }
+
+    public static byte getVersionMajor()
+    {
+        return _protocol_version_major;
+    }
+
+    public static byte getVersionMinor()
+    {
+        return _protocol_version_minor;
+    }
 }

Modified: incubator/qpid/trunk/qpid/java/test-provider.properties
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/test-provider.properties?rev=643822&r1=643821&r2=643822&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/java/test-provider.properties (original)
+++ incubator/qpid/trunk/qpid/java/test-provider.properties Wed Apr  2 02:55:27 
2008
@@ -1,4 +1,4 @@
-connectionfactory.local = 
qpid:password=guest;username=guest;client_id=clientid;[EMAIL 
PROTECTED]:127.0.0.1:5672
+connectionfactory.local = amqp://username:[EMAIL 
PROTECTED]/test?brokerlist='tcp://localhost:5672'
 
 queue.MyQueue = example.MyQueue
 queue.xaQueue =  xaQueue


Reply via email to