Author: chug
Date: Tue Nov 2 20:50:54 2010
New Revision: 1030209
URL: http://svn.apache.org/viewvc?rev=1030209&view=rev
Log:
QPID-2923 Qpid Messaging .NET Binding fails to translate exceptions from C++ to .NET
This checkin moves code out of class constructor member initialization and puts it into try-catch blocks. Any SEH Exceptions thrown by the C++ Messaging libraries are caught and re-thrown as .NET exceptions.
Modified:
qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Address.cpp
qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Connection.cpp
qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/FailoverUpdates.cpp
qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Message.cpp
qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Receiver.cpp
qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Sender.cpp
qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Session.cpp
Modified: qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Address.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Address.cpp?rev=1030209&r1=1030208&r2=1030209&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Address.cpp (original)
+++ qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Address.cpp Tue Nov 2 20:50:54 2010
@@ -29,6 +29,7 @@
#include "QpidMarshal.h"
#include "QpidTypeCheck.h"
#include "TypeTranslator.h"
+#include "QpidException.h"
namespace Org {
namespace Apache {
@@ -40,28 +41,74 @@ namespace Messaging {
///
// Create empty
- Address::Address() :
- addressp(new ::qpid::messaging::Address(QpidMarshal::ToNative("")))
+ Address::Address()
{
+ System::Exception ^ newException = nullptr;
+
+ try
+ {
+ addressp = new ::qpid::messaging::Address(QpidMarshal::ToNative(""));
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
// Create string address
- Address::Address(System::String ^ address) :
- addressp(new ::qpid::messaging::Address(QpidMarshal::ToNative(address)))
+ Address::Address(System::String ^ address)
{
+ System::Exception ^ newException = nullptr;
+
+ try
+ {
+ addressp = new ::qpid::messaging::Address(QpidMarshal::ToNative(address));
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
// Create with options
Address::Address(System::String ^ name,
System::String ^ subject,
System::Collections::Generic::Dictionary<
- System::String ^, System::Object ^> ^ options) :
- addressp(new ::qpid::messaging::Address())
+ System::String ^, System::Object ^> ^ options)
{
- Name = name;
- Subject = subject;
- Options = options;
- Type = "";
+ System::Exception ^ newException = nullptr;
+
+ try
+ {
+ addressp = new ::qpid::messaging::Address();
+
+ Name = name;
+ Subject = subject;
+ Options = options;
+ Type = "";
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
// Create with options and type
@@ -69,26 +116,72 @@ namespace Messaging {
System::String ^ subject,
System::Collections::Generic::Dictionary<
System::String ^, System::Object ^> ^ options,
- System::String ^ type) :
- addressp(new ::qpid::messaging::Address())
+ System::String ^ type)
{
- Name = name;
- Subject = subject;
- Options = options;
- Type = type;
+ System::Exception ^ newException = nullptr;
+
+ try
+ {
+ addressp = new ::qpid::messaging::Address();
+
+ Name = name;
+ Subject = subject;
+ Options = options;
+ Type = type;
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
// copy constructor
Address::Address(const Address ^ address)
- : addressp(new ::qpid::messaging::Address(
- *(const_cast
(address)->NativeAddress)))
{
+ System::Exception ^ newException = nullptr;
+
+ try
+ {
+ addressp = new ::qpid::messaging::Address(
+ *(const_cast(address)->NativeAddress));
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
// unmanaged clone
- Address::Address(const ::qpid::messaging::Address & addrp) :
- addressp(new ::qpid::messaging::Address(addrp))
+ Address::Address(const ::qpid::messaging::Address & addrp)
{
+ System::Exception ^ newException = nullptr;
+
+ try
+ {
+ addressp = new ::qpid::messaging::Address(addrp);
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
// Destructor
@@ -121,6 +214,23 @@ namespace Messaging {
//
System::String ^ Address::ToStr()
{
- return gcnew System::String(addressp->str().c_str());
+ System::String ^ result = nullptr;
+ System::Exception ^ newException = nullptr;
+
+ try
+ {
+ result = gcnew System::String(addressp->str().c_str());
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
+ return result;
}
}}}}
Modified: qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Connection.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Connection.cpp?rev=1030209&r1=1030208&r2=1030209&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Connection.cpp (original)
+++ qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Connection.cpp Tue Nov 2 20:50:54 2010
@@ -43,36 +43,97 @@ namespace Messaging {
///
// constructors
- Connection::Connection(System::String ^ url) :
- connectionp(new ::qpid::messaging::Connection(QpidMarshal::ToNative(url)))
+ Connection::Connection(System::String ^ url)
{
+ System::Exception ^ newException = nullptr;
+
+ try
+ {
+ connectionp = new ::qpid::messaging::Connection(QpidMarshal::ToNative(url));
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
Connection::Connection(System::String ^ url,
System::Collections::Generic::Dictionary<
- System::String ^, System::Object ^> ^ options) :
- connectionp(new ::qpid::messaging::Connection(QpidMarshal::ToNative(url)))
+ System::String ^, System::Object ^> ^ options)
{
- for each (System::Collections::Generic::KeyValuePair kvp in options)
- {
- SetOption(kvp.Key, kvp.Value);
+ System::Exception ^ newException = nullptr;
+
+ try
+ {
+ connectionp = new ::qpid::messaging::Connection(QpidMarshal::ToNative(url));
+
+ for each (System::Collections::Generic::KeyValuePair kvp in options)
+ {
+ SetOption(kvp.Key, kvp.Value);
+ }
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
}
+
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
- Connection::Connection(System::String ^ url, System::String ^ options) :
- connectionp(new ::qpid::messaging::Connection(QpidMarshal::ToNative(url),
- QpidMarshal::ToNative(options)))
+ Connection::Connection(System::String ^ url, System::String ^ options)
{
+ System::Exception ^ newException = nullptr;
+
+ try
+ {
+ connectionp = new ::qpid::messaging::Connection(QpidMarshal::ToNative(url),
+ QpidMarshal::ToNative(options));
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
// Copy constructor
Connection::Connection(const Connection ^ connection)
- : connectionp(new ::qpid::messaging::Connection(
- *(const_cast(connection)->NativeConnection)))
{
+ System::Exception ^ newException = nullptr;
+
+ try
+ {
+ connectionp = new ::qpid::messaging::Connection(
+ *(const_cast(connection)->NativeConnection));
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
@@ -104,20 +165,65 @@ namespace Messaging {
void Connection::SetOption(System::String ^ name, System::Object ^ value)
{
- ::qpid::types::Variant entryValue;
- TypeTranslator::ManagedToNativeObject(value, entryValue);
- std::string entryName = QpidMarshal::ToNative(name);
- connectionp->::qpid::messaging::Connection::setOption(entryName, entryValue);
+ System::Exception ^ newException = nullptr;
+
+ try
+ {
+ ::qpid::types::Variant entryValue;
+ TypeTranslator::ManagedToNativeObject(value, entryValue);
+ std::string entryName = QpidMarshal::ToNative(name);
+ connectionp->::qpid::messaging::Connection::setOption(entryName, entryValue);
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
void Connection::Open()
{
- connectionp->open();
+ System::Exception ^ newException = nullptr;
+
+ try
+ {
+ connectionp->open();
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
void Connection::Close()
{
- connectionp->close();
+ System::Exception ^ newException = nullptr;
+
+ try
+ {
+ connectionp->close();
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
//
Modified: qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/FailoverUpdates.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/FailoverUpdates.cpp?rev=1030209&r1=1030208&r2=1030209&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/FailoverUpdates.cpp (original)
+++ qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/FailoverUpdates.cpp Tue Nov 2 20:50:54 2010
@@ -39,14 +39,10 @@ namespace Messaging {
///
// constructors
- //FailoverUpdates::FailoverUpdates(Connection ^ connection) :
- // failoverupdatesp(new ::qpid::messaging::FailoverUpdates(*(connection->NativeConnection)))
- //{
- //}
FailoverUpdates::FailoverUpdates(Connection ^ connection)
{
- System::Exception ^ newException = nullptr;
+ System::Exception ^ newException = nullptr;
try
{
@@ -62,8 +58,6 @@ namespace Messaging {
{
throw newException;
}
-
- return;
}
Modified: qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Message.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Message.cpp?rev=1030209&r1=1030208&r2=1030209&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Message.cpp (original)
+++ qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Message.cpp Tue Nov 2 20:50:54 2010
@@ -47,66 +47,126 @@ namespace Messaging {
///
// Create empty message
- Message::Message() :
- messagep(new ::qpid::messaging::Message(QpidMarshal::ToNative("")))
+ Message::Message()
{
+ System::Exception ^ newException = nullptr;
+
+ try
+ {
+ messagep = new ::qpid::messaging::Message(QpidMarshal::ToNative(""));
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
// Create from string
- Message::Message(System::String ^ theStr) :
- messagep(new ::qpid::messaging::Message(QpidMarshal::ToNative(theStr)))
+ Message::Message(System::String ^ theStr)
{
+ System::Exception ^ newException = nullptr;
+
+ try
+ {
+ messagep = new ::qpid::messaging::Message(QpidMarshal::ToNative(theStr));
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
// Create from object
- Message::Message(System::Object ^ theValue) :
- messagep(new ::qpid::messaging::Message(QpidMarshal::ToNative("")))
+ Message::Message(System::Object ^ theValue)
{
- if (QpidTypeCheck::ObjectIsMap(theValue))
- {
- // Create a mapped message using given dictionary
+ System::Exception ^ newException = nullptr;
- // Allocate a map
- ::qpid::types::Variant::Map newMap;
+ try
+ {
+ messagep = new ::qpid::messaging::Message(QpidMarshal::ToNative(""));
- // Add the map variables to the map
- TypeTranslator::ManagedToNative((QpidMap ^)theValue, newMap);
+ if (QpidTypeCheck::ObjectIsMap(theValue))
+ {
+ // Create a mapped message using given dictionary
- // Set message content type
- messagep->setContentType("ampq/map");
+ // Allocate a map
+ ::qpid::types::Variant::Map newMap;
- // Insert the map into the message
- ::qpid::messaging::encode(newMap, *messagep, QpidMarshal::ToNative("amqp/map"));
- }
- else if (QpidTypeCheck::ObjectIsList(theValue))
- {
- // Create a list message using given list
+ // Add the map variables to the map
+ TypeTranslator::ManagedToNative((QpidMap ^)theValue, newMap);
- // Allocate a list
- ::qpid::types::Variant::List newList;
+ // Set message content type
+ messagep->setContentType("ampq/map");
- // Add the list variables to the list
- TypeTranslator::ManagedToNative((QpidList ^)theValue, newList);
+ // Insert the map into the message
+ ::qpid::messaging::encode(newMap, *messagep, QpidMarshal::ToNative("amqp/map"));
+ }
+ else if (QpidTypeCheck::ObjectIsList(theValue))
+ {
+ // Create a list message using given list
- // Set message content type
- messagep->setContentType("ampq/list");
+ // Allocate a list
+ ::qpid::types::Variant::List newList;
- // Insert the list into the message
- ::qpid::messaging::encode(newList, *messagep, QpidMarshal::ToNative("amqp/list"));
- }
- else
- {
- // Create a binary string message
- messagep->setContent(QpidMarshal::ToNative(theValue->ToString()));
+ // Add the list variables to the list
+ TypeTranslator::ManagedToNative((QpidList ^)theValue, newList);
+
+ // Set message content type
+ messagep->setContentType("ampq/list");
+
+ // Insert the list into the message
+ ::qpid::messaging::encode(newList, *messagep, QpidMarshal::ToNative("amqp/list"));
+ }
+ else
+ {
+ // Create a binary string message
+ messagep->setContent(QpidMarshal::ToNative(theValue->ToString()));
+ }
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
}
+
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
// Create from bytes
Message::Message(array ^ bytes)
{
- pin_ptr pBytes = &bytes[0];
- messagep = new ::qpid::messaging::Message((char *)pBytes, bytes->Length);
+ System::Exception ^ newException = nullptr;
+ try
+ {
+ pin_ptr pBytes = &bytes[0];
+ messagep = new ::qpid::messaging::Message((char *)pBytes, bytes->Length);
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
// Create from byte array slice
@@ -115,15 +175,44 @@ namespace Messaging {
if ((offset + size) > bytes->Length)
throw gcnew QpidException("Message::Message Create from byte array slice: buffer length exceeded");
- pin_ptr pBytes = &bytes[offset];
- messagep = new ::qpid::messaging::Message((char *)pBytes, size);
+ System::Exception ^ newException = nullptr;
+ try
+ {
+ pin_ptr pBytes = &bytes[offset];
+ messagep = new ::qpid::messaging::Message((char *)pBytes, size);
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
// unmanaged clone
- Message::Message(const ::qpid::messaging::Message & msgp) :
- messagep(new ::qpid::messaging::Message(msgp))
+ Message::Message(const ::qpid::messaging::Message & msgp)
{
+ System::Exception ^ newException = nullptr;
+
+ try
+ {
+ messagep = new ::qpid::messaging::Message(msgp);
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
@@ -142,9 +231,24 @@ namespace Messaging {
// Copy constructor
Message::Message(const Message ^ message)
- : messagep(new ::qpid::messaging::Message(
- *(const_cast(message)->NativeMessage)))
{
+ System::Exception ^ newException = nullptr;
+
+ try
+ {
+ messagep = new ::qpid::messaging::Message(
+ *(const_cast(message)->NativeMessage));
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
// Destroys kept object
@@ -161,23 +265,68 @@ namespace Messaging {
// Property
void Message::SetProperty(System::String ^ name, System::Object ^ value)
{
- ::qpid::types::Variant entryValue;
- TypeTranslator::ManagedToNativeObject(value, entryValue);
+ System::Exception ^ newException = nullptr;
- messagep->getProperties()[QpidMarshal::ToNative(name)] = entryValue;
+ try
+ {
+ ::qpid::types::Variant entryValue;
+ TypeTranslator::ManagedToNativeObject(value, entryValue);
+
+ messagep->getProperties()[QpidMarshal::ToNative(name)] = entryValue;
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
// Content
void Message::SetContent(System::String ^ content)
{
- messagep->setContent(QpidMarshal::ToNative(content));
+ System::Exception ^ newException = nullptr;
+
+ try
+ {
+ messagep->setContent(QpidMarshal::ToNative(content));
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
void Message::SetContent(cli::array ^ bytes)
{
- pin_ptr pBytes = &bytes[0];
- messagep->setContent((char *)pBytes, bytes->Length);
+ System::Exception ^ newException = nullptr;
+
+ try
+ {
+ pin_ptr pBytes = &bytes[0];
+ messagep->setContent((char *)pBytes, bytes->Length);
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
@@ -186,14 +335,47 @@ namespace Messaging {
if ((offset + size) > bytes->Length)
throw gcnew QpidException("Message::SetContent from byte array slice: buffer length exceeded");
- pin_ptr pBytes = &bytes[offset];
- messagep->setContent((char *)pBytes, size);
+ System::Exception ^ newException = nullptr;
+
+ try
+ {
+ pin_ptr pBytes = &bytes[offset];
+ messagep->setContent((char *)pBytes, size);
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
System::String ^ Message::GetContent()
{
- return gcnew String(messagep->getContent().c_str());
+ System::String ^ result = nullptr;
+ System::Exception ^ newException = nullptr;
+
+ try
+ {
+ result = gcnew String(messagep->getContent().c_str());
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
+
+ return result;
}
@@ -204,12 +386,27 @@ namespace Messaging {
System::String^,
System::Object^> ^ dict)
{
- // Extract the message map from the message
- ::qpid::types::Variant::Map map;
-
- ::qpid::messaging::decode(*messagep, map, QpidMarshal::ToNative("amqp/map"));
+ System::Exception ^ newException = nullptr;
+
+ try
+ {
+ // Extract the message map from the message
+ ::qpid::types::Variant::Map map;
+
+ ::qpid::messaging::decode(*messagep, map, QpidMarshal::ToNative("amqp/map"));
+
+ TypeTranslator::NativeToManaged(map, dict);
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
- TypeTranslator::NativeToManaged(map, dict);
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
@@ -219,14 +416,29 @@ namespace Messaging {
void Message::GetContent(System::Collections::ObjectModel::Collection<
System::Object^> ^ list)
{
- // allocate a native messaging::List
- ::qpid::types::Variant::List nativeList;
-
- // Extract the list from the message in native format
- ::qpid::messaging::decode(*messagep, nativeList, QpidMarshal::ToNative("amqp/list"));
+ System::Exception ^ newException = nullptr;
- // translate native list into user's managed list
- TypeTranslator::NativeToManaged(nativeList, list);
+ try
+ {
+ // allocate a native messaging::List
+ ::qpid::types::Variant::List nativeList;
+
+ // Extract the list from the message in native format
+ ::qpid::messaging::decode(*messagep, nativeList, QpidMarshal::ToNative("amqp/list"));
+
+ // translate native list into user's managed list
+ TypeTranslator::NativeToManaged(nativeList, list);
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
//
@@ -236,60 +448,90 @@ namespace Messaging {
//
void Message::GetContent(array ^ arr)
{
- System::UInt32 size = messagep->getContentSize();
-
- if (0 == size)
- throw gcnew QpidException("Message::GetRaw - message size is zero");
-
- if (arr->Length != size)
- throw gcnew QpidException("Message::GetRaw - receive buffer is wrong size");
-
- const char * pMsgSrc = messagep->getContentPtr();
- pin_ptr pArr = &arr[0];
- memcpy(pArr, pMsgSrc, size);
+ System::Exception ^ newException = nullptr;
+
+ try
+ {
+ System::UInt32 size = messagep->getContentSize();
+
+ if (0 == size)
+ throw gcnew QpidException("Message::GetRaw - message size is zero");
+
+ if (arr->Length != size)
+ throw gcnew QpidException("Message::GetRaw - receive buffer is wrong size");
+
+ const char * pMsgSrc = messagep->getContentPtr();
+ pin_ptr pArr = &arr[0];
+ memcpy(pArr, pMsgSrc, size);
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
System::String ^ Message::MapAsString(System::Collections::Generic::Dictionary<
System::String^, System::Object^> ^ dict)
{
- System::String ^ leading = "";
- System::Text::StringBuilder ^ sb = gcnew System::Text::StringBuilder("{");
+ System::Text::StringBuilder ^ sb = gcnew System::Text::StringBuilder("{");
+ System::Exception ^ newException = nullptr;
- for each (System::Collections::Generic::KeyValuePair
- kvp in dict)
- {
- sb->Append(leading);
- leading = ", ";
+ try
+ {
+ System::String ^ leading = "";
- if (QpidTypeCheck::ObjectIsMap(kvp.Value))
+ for each (System::Collections::Generic::KeyValuePair
+ kvp in dict)
{
- sb->AppendFormat(
- "{0}={1}",
- kvp.Key,
- MapAsString((System::Collections::Generic::Dictionary ^)kvp.Value));
- }
- else if (QpidTypeCheck::ObjectIsList(kvp.Value))
- {
- sb->AppendFormat(
- "{0}={1}",
- kvp.Key,
- ListAsString((System::Collections::ObjectModel::Collection<
- System::Object^> ^)kvp.Value));
- }
- else if (nullptr == kvp.Value)
- {
- sb->AppendFormat(
- "{0}=",
- kvp.Key);
+ sb->Append(leading);
+ leading = ", ";
+
+ if (QpidTypeCheck::ObjectIsMap(kvp.Value))
+ {
+ sb->AppendFormat(
+ "{0}={1}",
+ kvp.Key,
+ MapAsString((System::Collections::Generic::Dictionary ^)kvp.Value));
+ }
+ else if (QpidTypeCheck::ObjectIsList(kvp.Value))
+ {
+ sb->AppendFormat(
+ "{0}={1}",
+ kvp.Key,
+ ListAsString((System::Collections::ObjectModel::Collection<
+ System::Object^> ^)kvp.Value));
+ }
+ else if (nullptr == kvp.Value)
+ {
+ sb->AppendFormat(
+ "{0}=",
+ kvp.Key);
+ }
+ else
+ sb->AppendFormat("{0}={1}", kvp.Key, kvp.Value);
}
- else
- sb->AppendFormat("{0}={1}", kvp.Key, kvp.Value);
+ sb->Append("}");
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
}
- sb->Append("}");
- System::String ^ result = gcnew System::String(sb->ToString());
- return result;
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
+
+ System::String ^ result = gcnew System::String(sb->ToString());
+ return result;
}
///
@@ -298,35 +540,50 @@ namespace Messaging {
/// The AMQP list
System::String ^ Message::ListAsString(System::Collections::ObjectModel::Collection ^ list)
{
- System::String ^ leading = "";
- System::Text::StringBuilder ^ sb = gcnew System::Text::StringBuilder("[");
+ System::Text::StringBuilder ^ sb = gcnew System::Text::StringBuilder("[");
+ System::Exception ^ newException = nullptr;
- for each (System::Object ^ obj in list)
- {
- sb->Append(leading);
- leading = ", ";
+ try
+ {
+ System::String ^ leading = "";
- if (QpidTypeCheck::ObjectIsMap(obj))
- {
- sb->Append(MapAsString((System::Collections::Generic::Dictionary<
- System::String^, System::Object^> ^)obj));
- }
- else if (QpidTypeCheck::ObjectIsList(obj))
- {
- sb->Append(ListAsString((System::Collections::ObjectModel::Collection<
- System::Object^> ^)obj));
- }
- else if (nullptr == obj)
+ for each (System::Object ^ obj in list)
{
- // no display for null objects
+ sb->Append(leading);
+ leading = ", ";
+
+ if (QpidTypeCheck::ObjectIsMap(obj))
+ {
+ sb->Append(MapAsString((System::Collections::Generic::Dictionary<
+ System::String^, System::Object^> ^)obj));
+ }
+ else if (QpidTypeCheck::ObjectIsList(obj))
+ {
+ sb->Append(ListAsString((System::Collections::ObjectModel::Collection<
+ System::Object^> ^)obj));
+ }
+ else if (nullptr == obj)
+ {
+ // no display for null objects
+ }
+ else
+ sb->Append(obj->ToString());
}
- else
- sb->Append(obj->ToString());
+ sb->Append("]");
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
}
- sb->Append("]");
- System::String ^ result = gcnew System::String(sb->ToString());
- return result;
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
+
+ System::String ^ result = gcnew System::String(sb->ToString());
+ return result;
}
System::String ^ Message::AsString(System::Object ^ obj)
Modified: qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Receiver.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Receiver.cpp?rev=1030209&r1=1030208&r2=1030209&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Receiver.cpp (original)
+++ qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Receiver.cpp Tue Nov 2 20:50:54 2010
@@ -46,9 +46,24 @@ namespace Messaging {
// unmanaged clone
Receiver::Receiver(const ::qpid::messaging::Receiver & r,
Org::Apache::Qpid::Messaging::Session ^ sessRef) :
- receiverp(new ::qpid::messaging::Receiver (r)),
parentSession(sessRef)
{
+ System::Exception ^ newException = nullptr;
+
+ try
+ {
+ receiverp = new ::qpid::messaging::Receiver (r);
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
// unmanaged clone
@@ -69,11 +84,26 @@ namespace Messaging {
// Copy constructor
- Receiver::Receiver(const Receiver ^ receiver)
- : receiverp(new ::qpid::messaging::Receiver(
- *(const_cast(receiver)->NativeReceiver))),
- parentSession(receiver->parentSession)
+ Receiver::Receiver(const Receiver ^ receiver) :
+ parentSession(receiver->parentSession)
{
+ System::Exception ^ newException = nullptr;
+
+ try
+ {
+ receiverp = new ::qpid::messaging::Receiver(
+ *(const_cast(receiver)->NativeReceiver));
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
Modified: qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Sender.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Sender.cpp?rev=1030209&r1=1030208&r2=1030209&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Sender.cpp (original)
+++ qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Sender.cpp Tue Nov 2 20:50:54 2010
@@ -29,6 +29,7 @@
#include "Sender.h"
#include "Message.h"
+#include "QpidException.h"
namespace Org {
namespace Apache {
@@ -42,9 +43,24 @@ namespace Messaging {
// unmanaged clone
Sender::Sender(const ::qpid::messaging::Sender & s,
Org::Apache::Qpid::Messaging::Session ^ sessRef) :
- senderp(new ::qpid::messaging::Sender (s)),
parentSession(sessRef)
{
+ System::Exception ^ newException = nullptr;
+
+ try
+ {
+ senderp = new ::qpid::messaging::Sender (s);
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
@@ -63,10 +79,25 @@ namespace Messaging {
// Copy constructor
Sender::Sender(const Sender ^ sender)
- : senderp(new ::qpid::messaging::Sender(
- *(const_cast(sender)->NativeSender))),
- parentSession(sender->parentSession)
+ : parentSession(sender->parentSession)
{
+ System::Exception ^ newException = nullptr;
+
+ try
+ {
+ senderp = new ::qpid::messaging::Sender(
+ *(const_cast(sender)->NativeSender));
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
@@ -91,12 +122,42 @@ namespace Messaging {
void Sender::Send(Message ^ mmsgp, bool sync)
{
- senderp->::qpid::messaging::Sender::send(*((*mmsgp).NativeMessage), sync);
+ System::Exception ^ newException = nullptr;
+
+ try
+ {
+ senderp->::qpid::messaging::Sender::send(*((*mmsgp).NativeMessage), sync);
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
void Sender::Close()
{
- senderp->close();
+ System::Exception ^ newException = nullptr;
+
+ try
+ {
+ senderp->close();
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
}}}}
Modified: qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Session.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Session.cpp?rev=1030209&r1=1030208&r2=1030209&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Session.cpp (original)
+++ qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Session.cpp Tue Nov 2 20:50:54 2010
@@ -48,9 +48,24 @@ namespace Messaging {
// unmanaged clone
Session::Session(const ::qpid::messaging::Session & session,
Org::Apache::Qpid::Messaging::Connection ^ connRef) :
- sessionp(new ::qpid::messaging::Session (session)),
parentConnectionp(connRef)
{
+ System::Exception ^ newException = nullptr;
+
+ try
+ {
+ sessionp = new ::qpid::messaging::Session (session);
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
@@ -69,10 +84,26 @@ namespace Messaging {
// Copy constructor
Session::Session(const Session ^ session)
- : sessionp(new ::qpid::messaging::Session(
- *(const_cast(session)->NativeSession))),
- parentConnectionp(session->parentConnectionp)
+ : parentConnectionp(session->parentConnectionp)
{
+ System::Exception ^ newException = nullptr;
+
+ try
+ {
+ sessionp = new ::qpid::messaging::Session(
+ *(const_cast(session)->NativeSession));
+
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
@@ -89,17 +120,62 @@ namespace Messaging {
void Session::Close()
{
- sessionp->close();
+ System::Exception ^ newException = nullptr;
+
+ try
+ {
+ sessionp->close();
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
void Session::Commit()
{
- sessionp->commit();
+ System::Exception ^ newException = nullptr;
+
+ try
+ {
+ sessionp->commit();
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
void Session::Rollback()
{
- sessionp->rollback();
+ System::Exception ^ newException = nullptr;
+
+ try
+ {
+ sessionp->rollback();
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
void Session::Acknowledge()
@@ -109,7 +185,22 @@ namespace Messaging {
void Session::Acknowledge(bool sync)
{
- sessionp->acknowledge(sync);
+ System::Exception ^ newException = nullptr;
+
+ try
+ {
+ sessionp->acknowledge(sync);
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
void Session::Acknowledge(Message ^ message)
@@ -119,17 +210,62 @@ namespace Messaging {
void Session::Acknowledge(Message ^ message, bool sync)
{
- sessionp->acknowledge(*(message->NativeMessage), sync);
+ System::Exception ^ newException = nullptr;
+
+ try
+ {
+ sessionp->acknowledge(*(message->NativeMessage), sync);
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
void Session::Reject(Message ^ message)
{
- sessionp->::qpid::messaging::Session::reject(*(message->NativeMessage));
+ System::Exception ^ newException = nullptr;
+
+ try
+ {
+ sessionp->::qpid::messaging::Session::reject(*(message->NativeMessage));
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
void Session::Release(Message ^ message)
{
- sessionp->::qpid::messaging::Session::release(*(message->NativeMessage));
+ System::Exception ^ newException = nullptr;
+
+ try
+ {
+ sessionp->::qpid::messaging::Session::release(*(message->NativeMessage));
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
void Session::Sync()
@@ -139,7 +275,22 @@ namespace Messaging {
void Session::Sync(bool block)
{
- sessionp->sync(block);
+ System::Exception ^ newException = nullptr;
+
+ try
+ {
+ sessionp->sync(block);
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
// next(receiver)
@@ -444,6 +595,21 @@ namespace Messaging {
void Session::CheckError()
{
- sessionp->checkError();
+ System::Exception ^ newException = nullptr;
+
+ try
+ {
+ sessionp->checkError();
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
}}}}
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org