activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nmitt...@apache.org
Subject svn commit: r509060 - /activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/commands/ActiveMQTextMessage.cpp
Date Mon, 19 Feb 2007 02:23:54 GMT
Author: nmittler
Date: Sun Feb 18 18:23:54 2007
New Revision: 509060

URL: http://svn.apache.org/viewvc?view=rev&rev=509060
Log:
[AMQCPP-30] Fix to properly marshal/unmarshal the content of text messages.

Modified:
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/commands/ActiveMQTextMessage.cpp

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/commands/ActiveMQTextMessage.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/commands/ActiveMQTextMessage.cpp?view=diff&rev=509060&r1=509059&r2=509060
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/commands/ActiveMQTextMessage.cpp
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/commands/ActiveMQTextMessage.cpp
Sun Feb 18 18:23:54 2007
@@ -16,6 +16,9 @@
  */
 #include <activemq/connector/openwire/commands/ActiveMQTextMessage.h>
 
+#include <activemq/io/ByteArrayOutputStream.h>
+#include <activemq/io/DataOutputStream.h>
+
 using namespace std;
 using namespace activemq;
 using namespace activemq::connector;
@@ -43,7 +46,11 @@
 std::string ActiveMQTextMessage::getText() const throw( cms::CMSException ) {
 
     try{
-        return std::string( (const char*)&getContent()[0], getContent().size() ); 
+        if( getContent().size() < 4 ) {
+            return "";
+        }
+        
+        return std::string( (const char*)&getContent()[4], getContent().size()-4 ); 
     }
     AMQ_CATCH_RETHROW( exceptions::ActiveMQException )
     AMQ_CATCHALL_THROW( exceptions::ActiveMQException )
@@ -52,10 +59,11 @@
 ////////////////////////////////////////////////////////////////////////////////
 void ActiveMQTextMessage::setText( const char* msg ) throw( cms::CMSException ) {
     try{
-        size_t length = strlen( msg );
+        setText( std::string(msg) );
+        /*size_t length = strlen( msg );
         for( size_t i = 0; i < length; ++i ){
             getContent().push_back( msg[i] );
-        }
+        }*/
     }
     AMQ_CATCH_RETHROW( exceptions::ActiveMQException )
     AMQ_CATCHALL_THROW( exceptions::ActiveMQException )
@@ -64,9 +72,17 @@
 ////////////////////////////////////////////////////////////////////////////////
 void ActiveMQTextMessage::setText( const std::string& msg ) throw( cms::CMSException
) {
     try{
-        for( size_t i = 0; i < msg.length(); ++i ){
+        std::vector<unsigned char>& content = getContent();
+        content.clear();
+        io::ByteArrayOutputStream bos( content );
+        io::DataOutputStream dos( &bos );
+        
+        dos.writeInt( msg.length() );
+        dos.write( (const unsigned char*)msg.c_str(), msg.length() );
+
+        /*for( size_t i = 0; i < msg.length(); ++i ){
             getContent().push_back( msg[i] );
-        }
+        }*/
     }
     AMQ_CATCH_RETHROW( exceptions::ActiveMQException )
     AMQ_CATCHALL_THROW( exceptions::ActiveMQException )



Mime
View raw message