activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r1338937 - in /activemq/activemq-cpp/trunk/activemq-cpp/src/main: activemq/commands/ActiveMQObjectMessage.cpp activemq/commands/ActiveMQObjectMessage.h cms/ObjectMessage.h
Date Tue, 15 May 2012 23:04:37 GMT
Author: tabish
Date: Tue May 15 23:04:36 2012
New Revision: 1338937

URL: http://svn.apache.org/viewvc?rev=1338937&view=rev
Log:
fix for: https://issues.apache.org/jira/browse/AMQCPP-401

Modified:
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/ActiveMQObjectMessage.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/ActiveMQObjectMessage.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/cms/ObjectMessage.h

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/ActiveMQObjectMessage.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/ActiveMQObjectMessage.cpp?rev=1338937&r1=1338936&r2=1338937&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/ActiveMQObjectMessage.cpp
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/ActiveMQObjectMessage.cpp
Tue May 15 23:04:36 2012
@@ -16,13 +16,31 @@
  */
 #include <activemq/commands/ActiveMQObjectMessage.h>
 
+#include <activemq/util/CMSExceptionSupport.h>
+
+#include <decaf/io/FilterOutputStream.h>
+#include <decaf/io/ByteArrayInputStream.h>
+#include <decaf/io/ByteArrayOutputStream.h>
+#include <decaf/io/EOFException.h>
+#include <decaf/io/IOException.h>
+
+#include <decaf/util/zip/DeflaterOutputStream.h>
+#include <decaf/util/zip/InflaterInputStream.h>
+
 using namespace std;
 using namespace activemq;
+using namespace activemq::util;
 using namespace activemq::commands;
+using namespace activemq::exceptions;
+using namespace decaf::io;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+using namespace decaf::util;
+using namespace decaf::util::zip;
 
 ////////////////////////////////////////////////////////////////////////////////
 ActiveMQObjectMessage::ActiveMQObjectMessage() :
-    ActiveMQMessageTemplate<cms::ObjectMessage>() {
+    ActiveMQMessageTemplate<cms::ObjectMessage> () {
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -32,22 +50,89 @@ unsigned char ActiveMQObjectMessage::get
 
 ////////////////////////////////////////////////////////////////////////////////
 ActiveMQObjectMessage* ActiveMQObjectMessage::cloneDataStructure() const {
-    std::auto_ptr<ActiveMQObjectMessage> message( new ActiveMQObjectMessage() );
-    message->copyDataStructure( this );
+    std::auto_ptr<ActiveMQObjectMessage> message(new ActiveMQObjectMessage());
+    message->copyDataStructure(this);
     return message.release();
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void ActiveMQObjectMessage::copyDataStructure( const DataStructure* src ) {
-    ActiveMQMessageTemplate<cms::ObjectMessage>::copyDataStructure( src );
+void ActiveMQObjectMessage::copyDataStructure(const DataStructure* src) {
+    ActiveMQMessageTemplate<cms::ObjectMessage>::copyDataStructure(src);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-std::string ActiveMQObjectMessage::toString() const{
+std::string ActiveMQObjectMessage::toString() const {
     return ActiveMQMessageTemplate<cms::ObjectMessage>::toString();
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-bool ActiveMQObjectMessage::equals( const DataStructure* value ) const {
-    return ActiveMQMessageTemplate<cms::ObjectMessage>::equals( value );
+bool ActiveMQObjectMessage::equals(const DataStructure* value) const {
+    return ActiveMQMessageTemplate<cms::ObjectMessage>::equals(value);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQObjectMessage::setObjectBytes(const std::vector<unsigned char>& bytes)
{
+
+    this->failIfReadOnlyBody();
+    try {
+
+        if (bytes.size() == 0) {
+            return;
+        }
+
+        if (this->connection != NULL && this->connection->isUseCompression())
{
+            this->compressed = true;
+
+            ByteArrayOutputStream bytesOut;
+            Deflater* deflator = new Deflater(this->connection->getCompressionLevel());
+            DeflaterOutputStream out(&bytesOut, deflator, false, true);
+            out.write(&bytes[0], (int)bytes.size());
+
+            std::pair<unsigned char*, int> array = bytesOut.toByteArray();
+            this->setContent(std::vector<unsigned char>(array.first, array.first
+ array.second));
+            delete[] array.first;
+        } else {
+            this->setContent(bytes);
+        }
+    }
+    AMQ_CATCH_ALL_THROW_CMSEXCEPTION()
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::vector<unsigned char> ActiveMQObjectMessage::getObjectBytes() const {
+
+    this->failIfWriteOnlyBody();
+    try {
+
+        if (this->isCompressed()) {
+
+            int length = 0;
+            ByteArrayInputStream is(this->getContent());
+            std::vector<unsigned char> uncompressed;
+
+            try {
+
+                DataInputStream dis(&is);
+                length = dis.readInt();
+
+                if (length == 0) {
+                    return std::vector<unsigned char>();
+                }
+
+                uncompressed.resize(length);
+            } catch (IOException& ex) {
+                throw CMSExceptionSupport::create(ex);
+            }
+
+            InflaterInputStream inflater(&is, false);
+            inflater.read(&uncompressed[0], length);
+            inflater.close();
+
+            return uncompressed;
+
+        } else {
+            return this->getContent();
+        }
+    }
+    AMQ_CATCH_ALL_THROW_CMSEXCEPTION()
 }

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/ActiveMQObjectMessage.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/ActiveMQObjectMessage.h?rev=1338937&r1=1338936&r2=1338937&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/ActiveMQObjectMessage.h
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/ActiveMQObjectMessage.h
Tue May 15 23:04:36 2012
@@ -40,31 +40,38 @@ namespace commands{
 
     private:
 
-        ActiveMQObjectMessage( const ActiveMQObjectMessage& );
-        ActiveMQObjectMessage& operator= ( const ActiveMQObjectMessage& );
+        ActiveMQObjectMessage(const ActiveMQObjectMessage&);
+        ActiveMQObjectMessage& operator=(const ActiveMQObjectMessage&);
 
     public:
 
         ActiveMQObjectMessage();
 
-        virtual ~ActiveMQObjectMessage() throw() {}
+        virtual ~ActiveMQObjectMessage() throw () {
+        }
 
         virtual unsigned char getDataStructureType() const;
 
         virtual ActiveMQObjectMessage* cloneDataStructure() const;
 
-        virtual void copyDataStructure( const DataStructure* src );
+        virtual void copyDataStructure(const DataStructure* src);
 
         virtual std::string toString() const;
 
-        virtual bool equals( const DataStructure* value ) const;
+        virtual bool equals(const DataStructure* value) const;
 
-    public:  // cms::Message
+    public: // cms::Message
 
         virtual cms::Message* clone() const {
-            return dynamic_cast<cms::Message*>( this->cloneDataStructure() );
+            return dynamic_cast<cms::Message*> (this->cloneDataStructure());
         }
 
+    public: // cms::ObjectMessage
+
+        virtual void setObjectBytes(const std::vector<unsigned char>& bytes);
+
+        virtual std::vector<unsigned char> getObjectBytes() const;
+
     };
 
 }}

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/cms/ObjectMessage.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/cms/ObjectMessage.h?rev=1338937&r1=1338936&r2=1338937&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/cms/ObjectMessage.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/cms/ObjectMessage.h Tue May 15 23:04:36
2012
@@ -25,7 +25,9 @@ namespace cms{
 
     /**
      * Place holder for interaction with JMS systems that support Java, the C++
-     * client is not responsible for deserializing the contained Object.
+     * client is not responsible for deserializing the contained Object.  The Object
+     * can be accessed in its serialized form as a vector of bytes which allows for
+     * bridging of message systems.
      *
      * serialized <code>ObjectMessage</code>s.
      *
@@ -36,6 +38,27 @@ namespace cms{
 
         virtual ~ObjectMessage();
 
+        /**
+         * Sets the payload bytes the represent the Object being transmitted.
+         *
+         * @param bytes
+         *      The byte array that contains the serialized object.
+         *
+         * @throws CMSException - if the operation fails due to an internal error.
+         * @throws MessageNotWriteableException - if the Message is in Read-only Mode.
+         */
+        virtual void setObjectBytes(const std::vector<unsigned char>& bytes) =
0;
+
+        /**
+         * Returns the byte array containing the serialized form of the transmitted Object.
+         *
+         * @returns a byte vector containing the serialized Object.
+         *
+         * @throws CMSException - if the operation fails due to an internal error.
+         * @throws MessageNotReadableException - if the message is in write only mode.
+         */
+        virtual std::vector<unsigned char> getObjectBytes() const = 0;
+
     };
 
 }



Mime
View raw message