Author: tabish
Date: Mon Nov 25 23:38:36 2013
New Revision: 1545459

URL: http://svn.apache.org/r1545459
Log:
https://issues.apache.org/jira/browse/AMQNET-458

Implementation

Added:
    
activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/Header.cs
   (with props)
    
activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Protocol/MQTTExceptionFactory.cs
   (with props)
    
activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/ErrorResponse.cs
   (with props)
Modified:
    activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Connection.cs
    
activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/Response.cs

Added: 
activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/Header.cs
URL: 
http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/Header.cs?rev=1545459&view=auto
==============================================================================
--- 
activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/Header.cs
 (added)
+++ 
activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/Header.cs
 Mon Nov 25 23:38:36 2013
@@ -0,0 +1,82 @@
+//
+// 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.
+//
+using System;
+
+namespace vs2008mqtt
+{
+       public class Header
+       {
+               private byte value;
+
+               public Header(byte value)
+               {
+               }
+
+               public int Type
+               {
+                       get { return (this.value & 0x0F) >> 4; }
+                       set
+                       {
+                               this.value &= 0xF0;
+                               this.value |= (byte)((value << 4) & 0x0F);
+                       }
+               }
+
+               public int QoS
+               {
+                       get { return (this.value & 0x06) >> 1; }
+                       set
+                       {
+                               this.value &= 0x06;
+                               this.value |= (byte)((value << 1) & 0x06);
+                       }
+               }
+
+               public bool Dup
+               {
+                       get { return (this.value & 0x80) > 0; }
+                       set
+                       {
+                               if (value)
+                               {
+                                       this.value |= 0x08;
+                               }
+                               else
+                               {
+                                       this.value &= 0xF7;
+                               }
+                       }
+               }
+
+               public bool Retain
+               {
+                       get { return (this.value & 0x01) > 0; }
+                       set
+                       {
+                               if(value)
+                               {
+                                       this.value |= 0x01;
+                               }
+                               else
+                               {
+                                       this.value &= 0xFE;
+                               }
+                       }
+               }
+       }
+}
+

Propchange: 
activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/Header.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Connection.cs
URL: 
http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Connection.cs?rev=1545459&r1=1545458&r2=1545459&view=diff
==============================================================================
--- 
activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Connection.cs 
(original)
+++ 
activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Connection.cs 
Mon Nov 25 23:38:36 2013
@@ -547,18 +547,15 @@ namespace Apache.NMS.MQTT
                                                                                
}
                                                                                
else
                                                                                
{
-                                                                               
        // TODO figure out correct error to throw.
-//                                                                             
        NMSException exception = 
CreateExceptionFromBrokerError(error.Exception);
-//                                                                             
        if(exception is InvalidClientIDException)
-//                                                                             
        {
-//                                                                             
                // This is non-recoverable.
-//                                                                             
                // Shutdown the transport connection, and re-create it, but 
don't start it.
-//                                                                             
                // It will be started if the connection is re-attempted.
-//                                                                             
                this.transport.Stop();
-//                                                                             
                ITransport newTransport = 
TransportFactory.CreateTransport(this.brokerUri);
-//                                                                             
                SetTransport(newTransport);
-//                                                                             
                throw exception;
-//                                                                             
        }
+                                                                               
        ErrorResponse error = response as ErrorResponse;
+                                                                               
        NMSException exception = error.Error;
+                                                                               
        // This is non-recoverable.
+                                                                               
        // Shutdown the transport connection, and re-create it, but don't start 
it.
+                                                                               
        // It will be started if the connection is re-attempted.
+                                                                               
        this.transport.Stop();
+                                                                               
        ITransport newTransport = 
TransportFactory.CreateTransport(this.brokerUri);
+                                                                               
        SetTransport(newTransport);
+                                                                               
        throw exception;
                                                                                
}
                                                                        }
                                                                }

Added: 
activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Protocol/MQTTExceptionFactory.cs
URL: 
http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Protocol/MQTTExceptionFactory.cs?rev=1545459&view=auto
==============================================================================
--- 
activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Protocol/MQTTExceptionFactory.cs
 (added)
+++ 
activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Protocol/MQTTExceptionFactory.cs
 Mon Nov 25 23:38:36 2013
@@ -0,0 +1,62 @@
+//
+// 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.
+//
+using System;
+
+using Apache.NMS;
+
+namespace Apache.NMS.MQTT.Protocol
+{
+       public class MQTTExceptionFactory
+       {
+               private MQTTExceptionFactory ()
+               {
+               }
+
+               static NMSException CreateConnectionException(short errorCode)
+               {
+                       NMSException result = null;
+
+                       if (errorCode == 1)
+                       {
+                               result = new NMSException("Invalid MQTT 
Protocol Version specified");
+                       }
+                       else if(errorCode == 2)
+                       {
+                               result = new InvalidClientIDException("Client 
ID not accepted by Broker");
+                       }
+                       else if(errorCode == 3)
+                       {
+                               result = new InvalidClientIDException("Server 
is Unavailable");
+                       }
+                       else if(errorCode == 4)
+                       {
+                               result = new NMSSecurityException("Bad user 
anem or password provided.");
+                       }
+                       else if(errorCode == 5)
+                       {
+                               result = new NMSSecurityException("User is not 
Authorized.");
+                       }
+                       else
+                       {
+                               result = new NMSException("Received unknown 
error code.");
+                       }
+
+                       return result;
+               }
+       }
+}
+

Propchange: 
activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Protocol/MQTTExceptionFactory.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/ErrorResponse.cs
URL: 
http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/ErrorResponse.cs?rev=1545459&view=auto
==============================================================================
--- 
activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/ErrorResponse.cs
 (added)
+++ 
activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/ErrorResponse.cs
 Mon Nov 25 23:38:36 2013
@@ -0,0 +1,40 @@
+//
+// 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.
+//
+using System;
+using Apache.NMS;
+
+namespace Apache.NMS.MQTT.Transport
+{
+       public class ErrorResponse : Response
+       {
+               private NMSException error;
+               public NMSException Error
+               {
+                       get { return error; }
+                       set { this.error = value; }
+               }
+
+               public override bool IsErrorResponse 
+               {
+                       get 
+                       {
+                               return true;
+                       }
+               }
+       }
+}
+

Propchange: 
activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/ErrorResponse.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/Response.cs
URL: 
http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/Response.cs?rev=1545459&r1=1545458&r2=1545459&view=diff
==============================================================================
--- 
activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/Response.cs
 (original)
+++ 
activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/Response.cs
 Mon Nov 25 23:38:36 2013
@@ -23,7 +23,7 @@ namespace Apache.NMS.MQTT.Transport
        /// </summary>
     public class Response : BaseCommand
     {
-        int correlationId;
+        short correlationId;
 
         ///
         /// <summery>
@@ -39,7 +39,7 @@ namespace Apache.NMS.MQTT.Transport
                 "CorrelationId = " + CorrelationId + " ]";
         }
 
-        public int CorrelationId
+        public short CorrelationId
         {
             get { return correlationId; }
             set { this.correlationId = value; }
@@ -55,7 +55,7 @@ namespace Apache.NMS.MQTT.Transport
             get { return true; }
         }
 
-        public bool IsErrorResponse
+        public virtual bool IsErrorResponse
         {
             get { return false; }
         }


Reply via email to