activemq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Timothy Bish <tabish...@gmail.com>
Subject Re: ActiveMQcpp cms::Session::createTextMessage() function usage question with ISO-8859-1 strings
Date Wed, 02 Sep 2009 17:45:04 GMT
On Wed, 2009-09-02 at 10:06 -0700, martin@schlapfer.com wrote:
> Ah, I see.
> 
> Although I have not tried this, it looks like the getContent() method is
> public, so you could use the getContent() method rather than the getText()
> method.
> 
> You can then transform the payload data in the text message yourself
> (doing what was done in 2.2.1 getText() method) as a work around.
> 

You can grab the raw data from the getContent method, that will work
fine, just remember that the first four bytes are the size prefix of the
encoded data, and that the data is encoded in Java's Modified UTF-8
format, not plain UTF-8 so the null character (U+0000) is encoded as
0xC0,0x80 rather than 0x00. See:

http://en.wikipedia.org/wiki/UTF-8#Modified_UTF-8

Regards
Tim.

> On Wed, September 2, 2009 12:47 am, rainy3 wrote:
> >
> 
> >>> So it should be transparent to the user.  Your example should still
> >>> work when encoded to UTF-8, transmitted on the wire, and decoded back
> >>> into a character string (ie. treat 0xC4 as one character and 0x84 as
> >>> the subsequent character in the std::string).
> >
> > ActiveMQTextMessage.cpp (version 2.2.1)
> >
> >
> > std::string ActiveMQTextMessage::getText() const throw( cms::CMSException
> > )
> > {
> >
> >
> > try{ if( getContent().size() <= 4 ) { return ""; }
> >
> >
> > return std::string( (const char*)&getContent()[4], getContent().size()-4
> > );
> > }
> > AMQ_CATCH_RETHROW( ActiveMQException )
> > AMQ_CATCH_EXCEPTION_CONVERT( Exception, ActiveMQException )
> > AMQ_CATCHALL_THROW( ActiveMQException )
> > }
> >
> >
> > ActiveMQTextMessage.cpp (version 3.0.1)
> >
> >
> > std::string ActiveMQTextMessage::getText() const throw( cms::CMSException
> > )
> > {
> >
> >
> > try{ if( getContent().size() <= 4 ) { return ""; }
> >
> >
> > decaf::io::ByteArrayInputStream bais( getContent() );
> > decaf::io::DataInputStream dataIn( &bais );
> >
> >
> > return OpenwireStringSupport::readString( dataIn ); }
> > AMQ_CATCH_ALL_THROW_CMSEXCEPTION()
> > }
> >
> >
> > std::string OpenwireStringSupport::readString(
> > decaf::io::DataInputStream&
> > dataIn ) throw ( decaf::io::IOException ) {
> >
> > try {
> >
> > int utfLength = dataIn.readInt();
> >
> > if( utfLength <= 0 ) { return ""; }
> >
> >
> > ...
> >
> >
> > // a = 0xC4 so, here is a place where fail occurs
> > if( a & 0x1C ) { throw UTFDataFormatException( __FILE__, __LINE__,
> > "Invalid 2 byte UTF-8 encoding found, "
> > "This method only supports encoded ASCII values of
> > (0-255)." );
> > }
> >
> >
> > ...
> >
> >
> > return std::string( (char*)( &result[0] ), index ); }
> > AMQ_CATCH_RETHROW( decaf::io::IOException )
> > AMQ_CATCH_EXCEPTION_CONVERT( Exception, decaf::io::IOException )
> > AMQ_CATCHALL_THROW( decaf::io::IOException )
> > }
> >
> >
> > I don't have access to producer's java source but as far as i know it
> > reads text from database and then sends it as textMessage to ActiveMQ
> > broker. During/before sending the char 'A,' is UTF-8 encoded as 0xC484
> > octet stream so new getText method won't allow to reconvert it.
> >
> > --
> > View this message in context:
> > http://www.nabble.com/ActiveMQcpp-cms%3A%3ASession%3A%3AcreateTextMessage
> > %28%29-function-usage-question-with-ISO-8859-1-strings-tp24747592p2525305
> > 4.html
> > Sent from the ActiveMQ - Dev mailing list archive at Nabble.com.
> >
> >
> >
> 
> 
-- 
Tim Bish
http://fusesource.com
http://timbish.blogspot.com/




Mime
View raw message