Author: jgomes
Date: Tue Feb 9 20:39:39 2010
New Revision: 908208
URL: http://svn.apache.org/viewvc?rev=908208&view=rev
Log:
Added serialization support to all NMS exceptions.
Fixes [AMQNET-210]. (See https://issues.apache.org/activemq/browse/AMQNET-210)
Modified:
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/BrokerException.cs
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Commands/BrokerError.cs
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/ConnectionClosedException.cs
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/ConsumerClosedException.cs
Modified:
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/BrokerException.cs
URL:
http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/BrokerException.cs?rev=908208&r1=908207&r2=908208&view=diff
==============================================================================
---
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/BrokerException.cs
(original)
+++
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/BrokerException.cs
Tue Feb 9 20:39:39 2010
@@ -14,60 +14,91 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
+using System;
using System.Text;
using Apache.NMS.ActiveMQ.Commands;
namespace Apache.NMS.ActiveMQ
{
-
/// <summary>
/// Exception thrown when the broker returns an error
/// </summary>
+ [Serializable]
public class BrokerException : NMSException
- {
- private BrokerError brokerError;
-
+ {
+ private BrokerError brokerError = null;
+
+ public BrokerException()
+ : base("Broker failed with missing exception log")
+ {
+ }
+
+ public BrokerException(BrokerError brokerError)
+ : this(brokerError, null)
+ {
+ }
+
+ public BrokerException(BrokerError brokerError, Exception
innerException)
+ : base(brokerError.ExceptionClass + " : " +
brokerError.Message + "\n" + StackTraceDump(brokerError.StackTraceElements),
+ innerException)
+ {
+ this.brokerError = brokerError;
+ }
+
+ #region ISerializable interface implementation
+
+ /// <summary>
+ /// Initializes a new instance of the BrokerException class
with serialized data.
+ /// Throws System.ArgumentNullException if the info parameter
is null.
+ /// Throws System.Runtime.Serialization.SerializationException
if the class name is null or System.Exception.HResult is zero (0).
+ /// </summary>
+ /// <param name="info">The SerializationInfo that holds the
serialized object data about the exception being thrown.</param>
+ /// <param name="context">The StreamingContext that contains
contextual information about the source or destination.</param>
+ protected
BrokerException(System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context)
+ : base(info, context)
+ {
+ brokerError =
info.GetValue("BrokerException.brokerError", typeof(BrokerError)) as
BrokerError;
+ }
+
+ /// <summary>
+ /// When overridden in a derived class, sets the
SerializationInfo
+ /// with information about the exception.
+ /// </summary>
+ /// <param name="info">The SerializationInfo that holds the
serialized object data about the exception being thrown.</param>
+ /// <param name="context">The StreamingContext that contains
contextual information about the source or destination.</param>
+ public override void
GetObjectData(System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context)
+ {
+ base.GetObjectData(info, context);
+ info.AddValue("BrokerException.brokerError",
brokerError);
+ }
+
+ #endregion
+
/// <summary>
/// Generates a nice textual stack trace
/// </summary>
public static string StackTraceDump(StackTraceElement[]
elements)
{
StringBuilder builder = new StringBuilder();
- if (elements != null)
+ if(elements != null)
{
- foreach (StackTraceElement e in elements)
+ foreach(StackTraceElement e in elements)
{
builder.Append("\n " + e.ClassName +
"." + e.MethodName + "(" + e.FileName + ":" + e.LineNumber + ")");
}
}
return builder.ToString();
}
-
- public BrokerException() : base("Broker failed with missing exception
log")
- {
- }
-
- public BrokerException(BrokerError brokerError) : base(
- brokerError.ExceptionClass + " : " + brokerError.Message + "\n" +
StackTraceDump(brokerError.StackTraceElements))
- {
- this.brokerError = brokerError;
- }
-
- public BrokerError BrokerError
- {
- get {
- return brokerError;
- }
- }
-
- public virtual string JavaStackTrace
- {
- get {
- return brokerError.StackTrace;
- }
- }
-
- }
-}
+ public BrokerError BrokerError
+ {
+ get { return brokerError; }
+ }
+ public virtual string JavaStackTrace
+ {
+ get { return brokerError.StackTrace; }
+ }
+ }
+}
Modified:
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Commands/BrokerError.cs
URL:
http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Commands/BrokerError.cs?rev=908208&r1=908207&r2=908208&view=diff
==============================================================================
---
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Commands/BrokerError.cs
(original)
+++
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Commands/BrokerError.cs
Tue Feb 9 20:39:39 2010
@@ -14,78 +14,79 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-using Apache.NMS.ActiveMQ.Commands;
+
using System;
using System.IO;
-
namespace Apache.NMS.ActiveMQ.Commands
{
- public struct StackTraceElement
- {
- public string ClassName;
- public string FileName;
- public string MethodName;
- public int LineNumber;
- }
-
- /// <summary>
- /// Represents an exception on the broker
- /// </summary>
- public class BrokerError : BaseCommand
- {
- private string message;
- private string exceptionClass;
- private StackTraceElement[] stackTraceElements = {};
- private BrokerError cause;
-
- public string Message
- {
- get { return message; }
- set { message = value; }
- }
-
- public string ExceptionClass
- {
- get { return exceptionClass; }
- set { exceptionClass = value; }
- }
-
- public StackTraceElement[] StackTraceElements
- {
- get { return stackTraceElements; }
- set { stackTraceElements = value; }
- }
-
- public BrokerError Cause
- {
- get { return cause; }
- set { cause = value; }
- }
-
- public String StackTrace
- {
- get {
- StringWriter writer = new StringWriter();
- PrintStackTrace(writer);
- return writer.ToString();
- }
- }
-
- public void PrintStackTrace(TextWriter writer)
- {
- writer.WriteLine(exceptionClass + ": " + message);
- for (int i = 0; i < stackTraceElements.Length; i++)
- {
- StackTraceElement element = stackTraceElements[i];
- writer.WriteLine(" at " + element.ClassName + "." +
element.MethodName + "(" + element.FileName + ":" + element.LineNumber + ")");
- }
- if (cause != null)
- {
- writer.WriteLine("Nested Exception:");
- cause.PrintStackTrace(writer);
- }
- }
- }
-}
+ public struct StackTraceElement
+ {
+ public string ClassName;
+ public string FileName;
+ public string MethodName;
+ public int LineNumber;
+ }
+
+ /// <summary>
+ /// Represents an exception on the broker
+ /// </summary>
+ [Serializable]
+ public class BrokerError : BaseCommand
+ {
+ private string message;
+ private string exceptionClass;
+ private StackTraceElement[] stackTraceElements = { };
+ private BrokerError cause;
+
+ public string Message
+ {
+ get { return message; }
+ set { message = value; }
+ }
+
+ public string ExceptionClass
+ {
+ get { return exceptionClass; }
+ set { exceptionClass = value; }
+ }
+ public StackTraceElement[] StackTraceElements
+ {
+ get { return stackTraceElements; }
+ set { stackTraceElements = value; }
+ }
+
+ public BrokerError Cause
+ {
+ get { return cause; }
+ set { cause = value; }
+ }
+
+ public String StackTrace
+ {
+ get
+ {
+ StringWriter writer = new StringWriter();
+ PrintStackTrace(writer);
+ return writer.ToString();
+ }
+ }
+
+ public void PrintStackTrace(TextWriter writer)
+ {
+ writer.WriteLine(exceptionClass + ": " + message);
+ for(int i = 0; i < stackTraceElements.Length; i++)
+ {
+ StackTraceElement element =
stackTraceElements[i];
+ writer.WriteLine(" at " + element.ClassName
+ "." + element.MethodName + "(" + element.FileName + ":" + element.LineNumber
+ ")");
+ }
+
+ if(cause != null)
+ {
+ writer.WriteLine("Nested Exception:");
+ cause.PrintStackTrace(writer);
+ }
+ }
+ }
+}
Modified:
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/ConnectionClosedException.cs
URL:
http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/ConnectionClosedException.cs?rev=908208&r1=908207&r2=908208&view=diff
==============================================================================
---
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/ConnectionClosedException.cs
(original)
+++
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/ConnectionClosedException.cs
Tue Feb 9 20:39:39 2010
@@ -14,15 +14,56 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-using Apache.NMS;
+
+using System;
namespace Apache.NMS.ActiveMQ
{
/// <summary>
- /// Exception thrown when a connection is used that it already closed
- /// </summary>
- public class ConnectionClosedException : NMSException {
- public ConnectionClosedException() : base("The connection is
already closed!") {
- }
- }
+ /// Exception thrown when a connection is used that it already closed
+ /// </summary>
+ [Serializable]
+ public class ConnectionClosedException : NMSException
+ {
+ public ConnectionClosedException()
+ : base("The connection is already closed!")
+ {
+ }
+
+ public ConnectionClosedException(string message)
+ : base(message)
+ {
+ }
+
+ public ConnectionClosedException(string message, string
errorCode)
+ : base(message, errorCode)
+ {
+ }
+
+ public ConnectionClosedException(string message, Exception
innerException)
+ : base(message, innerException)
+ {
+ }
+
+ public ConnectionClosedException(string message, string
errorCode, Exception innerException)
+ : base(message, errorCode, innerException)
+ {
+ }
+
+ #region ISerializable interface implementation
+
+ /// <summary>
+ /// Initializes a new instance of the ConnectionClosedException
class with serialized data.
+ /// Throws System.ArgumentNullException if the info parameter
is null.
+ /// Throws System.Runtime.Serialization.SerializationException
if the class name is null or System.Exception.HResult is zero (0).
+ /// </summary>
+ /// <param name="info">The SerializationInfo that holds the
serialized object data about the exception being thrown.</param>
+ /// <param name="context">The StreamingContext that contains
contextual information about the source or destination.</param>
+ protected
ConnectionClosedException(System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context)
+ : base(info, context)
+ {
+ }
+
+ #endregion
+ }
}
Modified:
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/ConsumerClosedException.cs
URL:
http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/ConsumerClosedException.cs?rev=908208&r1=908207&r2=908208&view=diff
==============================================================================
---
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/ConsumerClosedException.cs
(original)
+++
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/ConsumerClosedException.cs
Tue Feb 9 20:39:39 2010
@@ -14,15 +14,57 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
using Apache.NMS;
+using System;
namespace Apache.NMS.ActiveMQ
{
/// <summary>
- /// Exception thrown when a consumer is used that it already closed
- /// </summary>
- public class ConsumerClosedException : NMSException {
- public ConsumerClosedException() : base("The consumer is
already closed!") {
- }
- }
+ /// Exception thrown when a consumer is used that it already closed
+ /// </summary>
+ [Serializable]
+ public class ConsumerClosedException : NMSException
+ {
+ public ConsumerClosedException()
+ : base("The consumer is already closed!")
+ {
+ }
+
+ public ConsumerClosedException(string message)
+ : base(message)
+ {
+ }
+
+ public ConsumerClosedException(string message, string errorCode)
+ : base(message, errorCode)
+ {
+ }
+
+ public ConsumerClosedException(string message, Exception
innerException)
+ : base(message, innerException)
+ {
+ }
+
+ public ConsumerClosedException(string message, string
errorCode, Exception innerException)
+ : base(message, errorCode, innerException)
+ {
+ }
+
+ #region ISerializable interface implementation
+
+ /// <summary>
+ /// Initializes a new instance of the ConsumerClosedException
class with serialized data.
+ /// Throws System.ArgumentNullException if the info parameter
is null.
+ /// Throws System.Runtime.Serialization.SerializationException
if the class name is null or System.Exception.HResult is zero (0).
+ /// </summary>
+ /// <param name="info">The SerializationInfo that holds the
serialized object data about the exception being thrown.</param>
+ /// <param name="context">The StreamingContext that contains
contextual information about the source or destination.</param>
+ protected
ConsumerClosedException(System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context)
+ : base(info, context)
+ {
+ }
+
+ #endregion
+ }
}