activemq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rainy3 <rai...@poczta.onet.pl>
Subject Re: ActiveMQcpp cms::Session::createTextMessage() function usage question with ISO-8859-1 strings
Date Wed, 02 Sep 2009 07:47:49 GMT

>> 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-tp24747592p25253054.html
Sent from the ActiveMQ - Dev mailing list archive at Nabble.com.


Mime
View raw message