Return-Path: X-Original-To: apmail-activemq-commits-archive@www.apache.org Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 95767DE9A for ; Fri, 2 Nov 2012 22:24:15 +0000 (UTC) Received: (qmail 57997 invoked by uid 500); 2 Nov 2012 22:24:15 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 57961 invoked by uid 500); 2 Nov 2012 22:24:15 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 57951 invoked by uid 99); 2 Nov 2012 22:24:15 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 02 Nov 2012 22:24:15 +0000 X-ASF-Spam-Status: No, hits=-1999.0 required=5.0 tests=ALL_TRUSTED,FILL_THIS_FORM_SHORT X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 02 Nov 2012 22:24:07 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 58AF923889D7 for ; Fri, 2 Nov 2012 22:23:44 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1405184 - in /activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp: StompFrame.cpp StompFrame.h StompHelper.cpp StompHelper.h StompWireFormat.cpp StompWireFormat.h StompWireFormatFactory.cpp StompWireFormatFactory.h Date: Fri, 02 Nov 2012 22:23:43 -0000 To: commits@activemq.apache.org From: tabish@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20121102222344.58AF923889D7@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: tabish Date: Fri Nov 2 22:23:43 2012 New Revision: 1405184 URL: http://svn.apache.org/viewvc?rev=1405184&view=rev Log: fix for this issue: https://issues.apache.org/jira/browse/AMQCPP-386 Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompFrame.cpp activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompFrame.h activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompHelper.cpp activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompHelper.h activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompWireFormat.cpp activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompWireFormat.h activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompWireFormatFactory.cpp activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompWireFormatFactory.h Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompFrame.cpp URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompFrame.cpp?rev=1405184&r1=1405183&r2=1405184&view=diff ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompFrame.cpp (original) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompFrame.cpp Fri Nov 2 22:23:43 2012 @@ -37,7 +37,8 @@ using namespace decaf::lang; using namespace decaf::lang::exceptions; //////////////////////////////////////////////////////////////////////////////// -StompFrame::StompFrame() : command(), properties(), body() { +StompFrame::StompFrame() : + command(), properties(), body() { } //////////////////////////////////////////////////////////////////////////////// @@ -47,178 +48,173 @@ StompFrame::~StompFrame() { //////////////////////////////////////////////////////////////////////////////// StompFrame* StompFrame::clone() const { StompFrame* frame = new StompFrame(); - frame->copy( this ); + frame->copy(this); return frame; } //////////////////////////////////////////////////////////////////////////////// -void StompFrame::copy( const StompFrame* src ) { +void StompFrame::copy(const StompFrame* src) { - this->setCommand( src->getCommand() ); + this->setCommand(src->getCommand()); this->properties = src->getProperties(); this->body = src->getBody(); } //////////////////////////////////////////////////////////////////////////////// -void StompFrame::setBody( const unsigned char* bytes, std::size_t numBytes ) { +void StompFrame::setBody(const unsigned char* bytes, std::size_t numBytes) { // Remove old data body.clear(); - body.reserve( numBytes ); + body.reserve(numBytes); // Copy data to internal buffer. - this->body.insert( this->body.begin(), bytes, bytes + numBytes ); + this->body.insert(this->body.begin(), bytes, bytes + numBytes); } //////////////////////////////////////////////////////////////////////////////// -void StompFrame::toStream( decaf::io::DataOutputStream* stream ) const { +void StompFrame::toStream(decaf::io::DataOutputStream* stream) const { - if( stream == NULL ) { - throw NullPointerException( - __FILE__, __LINE__, "Stream Passed is Null" ); + if (stream == NULL) { + throw NullPointerException(__FILE__, __LINE__, "Stream Passed is Null"); } // Write the command. const string& cmdString = this->getCommand(); - stream->write( (unsigned char*)cmdString.c_str(), (int)cmdString.length(), 0, (int)cmdString.length() ); - stream->write( '\n' ); + stream->write((unsigned char*) cmdString.c_str(), (int) cmdString.length(), 0, (int) cmdString.length()); + stream->write('\n'); // Write all the headers. - vector< pair > headers = this->getProperties().toArray(); - for( std::size_t ix=0; ix < headers.size(); ++ix ) { + vector > headers = this->getProperties().toArray(); + for (std::size_t ix = 0; ix < headers.size(); ++ix) { string& name = headers[ix].first; string& value = headers[ix].second; - stream->write( (unsigned char*)name.c_str(), (int)name.length(), 0, (int)name.length() ); - stream->write( ':' ); - stream->write( (unsigned char*)value.c_str(), (int)value.length(), 0, (int)value.length() ); - stream->write( '\n' ); + stream->write((unsigned char*) name.c_str(), (int) name.length(), 0, (int) name.length()); + stream->write(':'); + stream->write((unsigned char*) value.c_str(), (int) value.length(), 0, (int) value.length()); + stream->write('\n'); } // Finish the header section with a form feed. - stream->write( '\n' ); + stream->write('\n'); // Write the body. const std::vector& body = this->getBody(); - if( body.size() > 0 ) { - stream->write( &body[0], (int)body.size(), 0, (int)body.size() ); + if (body.size() > 0) { + stream->write(&body[0], (int) body.size(), 0, (int) body.size()); } - if( ( this->getBodyLength() == 0 ) || - ( this->getProperty( StompCommandConstants::HEADER_CONTENTLENGTH ) != "" ) ) { + if ((this->getBodyLength() == 0) || (this->getProperty(StompCommandConstants::HEADER_CONTENTLENGTH) != "")) { - stream->write( '\0' ); + stream->write('\0'); } - stream->write( '\n' ); + stream->write('\n'); // Flush the stream. stream->flush(); } //////////////////////////////////////////////////////////////////////////////// -void StompFrame::fromStream( decaf::io::DataInputStream* in ) { +void StompFrame::fromStream(decaf::io::DataInputStream* in) { - if( in == NULL ) { - throw decaf::io::IOException( - __FILE__, __LINE__, "DataInputStream passed is NULL" ); + if (in == NULL) { + throw decaf::io::IOException(__FILE__, __LINE__, "DataInputStream passed is NULL"); } - try{ + try { // Read the command header. - readCommandHeader( in ); + readCommandHeader(in); // Read the headers. - readHeaders( in ); + readHeaders(in); // Read the body. - readBody( in ); + readBody(in); } - AMQ_CATCH_RETHROW( decaf::io::IOException ) - AMQ_CATCH_EXCEPTION_CONVERT( decaf::lang::Exception, decaf::io::IOException ) - AMQ_CATCHALL_THROW( decaf::io::IOException ) + AMQ_CATCH_RETHROW(decaf::io::IOException) + AMQ_CATCH_EXCEPTION_CONVERT(decaf::lang::Exception, decaf::io::IOException) + AMQ_CATCHALL_THROW(decaf::io::IOException) } //////////////////////////////////////////////////////////////////////////////// -void StompFrame::readCommandHeader( decaf::io::DataInputStream* in ) { +void StompFrame::readCommandHeader(decaf::io::DataInputStream* in) { - try{ + try { std::vector buffer; - while( true ) { + while (true) { // The command header is formatted just like any other stomp header. - readHeaderLine( buffer, in ); + readHeaderLine(buffer, in); // Ignore all white space before the command. long long offset = -1; - for( size_t ix = 0; ix < buffer.size()-1; ++ix ) { + for (size_t ix = 0; ix < buffer.size() - 1; ++ix) { // Find the first non whitespace character - if( !Character::isWhitespace( buffer[ix] ) ){ - offset = (long long)ix; + if (!Character::isWhitespace(buffer[ix])) { + offset = (long long) ix; break; } } - if( offset >= 0 ) { + if (offset >= 0) { // Set the command in the frame - copy the memory. - this->setCommand( reinterpret_cast( &buffer[(size_t)offset] ) ); + this->setCommand(reinterpret_cast(&buffer[(size_t) offset])); break; } } } - AMQ_CATCH_RETHROW( decaf::io::IOException ) - AMQ_CATCH_EXCEPTION_CONVERT( decaf::lang::Exception, decaf::io::IOException ) - AMQ_CATCHALL_THROW( decaf::io::IOException ) + AMQ_CATCH_RETHROW(decaf::io::IOException) + AMQ_CATCH_EXCEPTION_CONVERT(decaf::lang::Exception, decaf::io::IOException) + AMQ_CATCHALL_THROW(decaf::io::IOException) } //////////////////////////////////////////////////////////////////////////////// -void StompFrame::readHeaders( decaf::io::DataInputStream* in ) { +void StompFrame::readHeaders(decaf::io::DataInputStream* in) { - try{ + try { // Read the command; bool endOfHeaders = false; std::vector buffer; - while( !endOfHeaders ) { + while (!endOfHeaders) { // Read in the next header line. - std::size_t numChars = readHeaderLine( buffer, in ); + std::size_t numChars = readHeaderLine(buffer, in); - if( numChars == 0 ) { + if (numChars == 0) { // should never get here - throw decaf::io::IOException( - __FILE__, __LINE__, - "StompWireFormat::readStompHeaders: no characters read" ); + throw decaf::io::IOException(__FILE__, __LINE__, "StompWireFormat::readStompHeaders: no characters read"); } // Check for an empty line to demark the end of the header section. // if its not the end then we have a header to process, so parse it. - if( numChars == 1 && buffer[0] == '\0' ) { + if (numChars == 1 && buffer[0] == '\0') { endOfHeaders = true; } else { // Search through this line to separate the key/value pair. - for( size_t ix = 0; ix < buffer.size(); ++ix ) { + for (size_t ix = 0; ix < buffer.size(); ++ix) { // If found the key/value separator... - if( buffer[ix] == ':' ) { + if (buffer[ix] == ':') { // Null-terminate the key. buffer[ix] = '\0'; - const char* key = reinterpret_cast( &buffer[0] ); - const char* value = reinterpret_cast( &buffer[ix+1] ); + const char* key = reinterpret_cast(&buffer[0]); + const char* value = reinterpret_cast(&buffer[ix + 1]); // Assign the header key/value pair. - this->getProperties().setProperty( key, value ); + this->getProperties().setProperty(key, value); // Break out of the for loop. break; @@ -227,66 +223,63 @@ void StompFrame::readHeaders( decaf::io: } } } - AMQ_CATCH_RETHROW( decaf::io::IOException ) - AMQ_CATCH_EXCEPTION_CONVERT( decaf::lang::Exception, decaf::io::IOException ) - AMQ_CATCHALL_THROW( decaf::io::IOException ) + AMQ_CATCH_RETHROW(decaf::io::IOException) + AMQ_CATCH_EXCEPTION_CONVERT(decaf::lang::Exception, decaf::io::IOException) + AMQ_CATCHALL_THROW(decaf::io::IOException) } //////////////////////////////////////////////////////////////////////////////// -std::size_t StompFrame::readHeaderLine( std::vector& buffer, - decaf::io::DataInputStream* in ) { +std::size_t StompFrame::readHeaderLine(std::vector& buffer, decaf::io::DataInputStream* in) { - try{ + try { // Clear any data from the buffer. buffer.clear(); std::size_t count = 0; - while( true ) { + while (true) { // Read the next char from the stream. - buffer.push_back( in->readByte() ); + buffer.push_back(in->readByte()); // Increment the position pointer. count++; // If we reached the line terminator, return the total number // of characters read. - if( buffer[count-1] == '\n' ) { + if (buffer[count - 1] == '\n') { // Overwrite the line feed with a null character. - buffer[count-1] = '\0'; + buffer[count - 1] = '\0'; return count; } } // If we get here something bad must have happened. - throw decaf::io::IOException( - __FILE__, __LINE__, - "StompWireFormat::readStompHeaderLine: " - "Unrecoverable, error condition"); + throw decaf::io::IOException(__FILE__, __LINE__, "StompWireFormat::readStompHeaderLine: " + "Unrecoverable, error condition"); } - AMQ_CATCH_RETHROW( decaf::io::IOException ) - AMQ_CATCH_EXCEPTION_CONVERT( decaf::lang::Exception, decaf::io::IOException ) - AMQ_CATCHALL_THROW( decaf::io::IOException ) + AMQ_CATCH_RETHROW(decaf::io::IOException) + AMQ_CATCH_EXCEPTION_CONVERT(decaf::lang::Exception, decaf::io::IOException) + AMQ_CATCHALL_THROW(decaf::io::IOException) } //////////////////////////////////////////////////////////////////////////////// -void StompFrame::readBody( decaf::io::DataInputStream* in ) { +void StompFrame::readBody(decaf::io::DataInputStream* in) { - try{ + try { // Clear any data from the body. this->body.clear(); unsigned int content_length = 0; - if( this->hasProperty( StompCommandConstants::HEADER_CONTENTLENGTH ) ) { - string length = this->getProperty( StompCommandConstants::HEADER_CONTENTLENGTH ); - content_length = (unsigned int)Integer::parseInt( length ); - } + if (this->hasProperty(StompCommandConstants::HEADER_CONTENTLENGTH)) { + string length = this->getProperty(StompCommandConstants::HEADER_CONTENTLENGTH); + content_length = (unsigned int) Integer::parseInt(length); + } - if( content_length != 0 ) { + if (content_length != 0) { // For this case its assumed that content length indicates how // much to read. We reserve space in the buffer for it to // minimize the number of reallocs that might occur. We are @@ -300,40 +293,36 @@ void StompFrame::readBody( decaf::io::Da // iterator. Reserve adds the benefit that the mem is set to // zero. - this->body.reserve( (std::size_t)content_length ); - this->body.resize( (std::size_t)content_length ); + this->body.reserve((std::size_t) content_length); + this->body.resize((std::size_t) content_length); // Read the Content Length now - in->read( &body[0], (int)body.size(), 0, content_length ); + in->read(&body[0], (int) body.size(), 0, content_length); // Content Length read, now pop the end terminator off (\0\n). - if( in->readByte() != '\0' ) { - - throw decaf::io::IOException( - __FILE__, __LINE__, - "StompWireFormat::readStompBody: " - "Read Content Length, and no trailing null"); + if (in->readByte() != '\0') { + throw decaf::io::IOException(__FILE__, __LINE__, "StompWireFormat::readStompBody: " + "Read Content Length, and no trailing null"); } } else { // Content length was either zero, or not set, so we read until the // first null is encountered. - while( true ) { + while (true) { char byte = in->readByte(); + this->body.push_back(byte); - this->body.push_back( byte ); - - if( byte != '\0' ) { + if (byte != '\0') { continue; } - break; // Read null and newline we are done. + break; // Read null and newline we are done. } } } - AMQ_CATCH_RETHROW( decaf::io::IOException ) - AMQ_CATCH_EXCEPTION_CONVERT( decaf::lang::Exception, decaf::io::IOException ) - AMQ_CATCHALL_THROW( decaf::io::IOException ) + AMQ_CATCH_RETHROW(decaf::io::IOException) + AMQ_CATCH_EXCEPTION_CONVERT(decaf::lang::Exception, decaf::io::IOException) + AMQ_CATCHALL_THROW(decaf::io::IOException) } Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompFrame.h URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompFrame.h?rev=1405184&r1=1405183&r2=1405184&view=diff ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompFrame.h (original) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompFrame.h Fri Nov 2 22:23:43 2012 @@ -26,15 +26,14 @@ #include #include -namespace activemq{ -namespace wireformat{ -namespace stomp{ +namespace activemq { +namespace wireformat { +namespace stomp { /** - * A Stomp-level message frame that encloses all messages - * to and from the broker. + * A Stomp-level message frame that encloses all messages to and from the broker. */ - class AMQCPP_API StompFrame{ + class AMQCPP_API StompFrame { private: // String Name of this command. @@ -69,20 +68,20 @@ namespace stomp{ * Copies the contents of the passed Frame to this one * @param src - Frame to copy */ - void copy( const StompFrame* src ); + void copy(const StompFrame* src); /** * Sets the command for this stomp frame. * @param cmd command The command to be set. */ - void setCommand( const std::string& cmd ){ + void setCommand(const std::string& cmd) { this->command = cmd; } /** * Accessor for this frame's command field. */ - const std::string& getCommand() const{ + const std::string& getCommand() const { return command; } @@ -91,8 +90,8 @@ namespace stomp{ * * @param name - The name of the property to check for. */ - bool hasProperty( const std::string& name ) const { - return this->properties.hasProperty( name ); + bool hasProperty(const std::string& name) const { + return this->properties.hasProperty(name); } /** @@ -104,8 +103,8 @@ namespace stomp{ * * @return string value of the property asked for. */ - std::string getProperty( const std::string& name, const std::string& fallback = "" ) const { - return this->properties.getProperty( name, fallback ); + std::string getProperty(const std::string& name, const std::string& fallback = "") const { + return this->properties.getProperty(name, fallback); } /** @@ -114,8 +113,8 @@ namespace stomp{ * * @param name - the Name of the property to get and return. */ - std::string removeProperty( const std::string& name ) { - return this->properties.getProperty( name, "" ); + std::string removeProperty(const std::string& name) { + return this->properties.getProperty(name, ""); } /** @@ -124,15 +123,17 @@ namespace stomp{ * @param name - Name of the property. * @param value - Value to set the property to. */ - void setProperty( const std::string& name, const std::string& value ) { - this->properties.setProperty( name, value ); + void setProperty(const std::string& name, const std::string& value) { + this->properties.setProperty(name, value); } /** * Gets access to the header properties for this frame. * @return the Properties object owned by this Frame */ - decaf::util::Properties& getProperties(){ return properties; } + decaf::util::Properties& getProperties() { + return properties; + } const decaf::util::Properties& getProperties() const { return properties; } @@ -141,14 +142,14 @@ namespace stomp{ * Accessor for the body data of this frame. * @return char pointer to body data */ - const std::vector& getBody() const{ + const std::vector& getBody() const { return body; } /** * Non-const version of the body accessor. */ - std::vector& getBody(){ + std::vector& getBody() { return body; } @@ -156,14 +157,16 @@ namespace stomp{ * Return the number of bytes contained in this frames body * @return Body bytes length. */ - std::size_t getBodyLength() const{ return body.size(); } + std::size_t getBodyLength() const { + return body.size(); + } /** * Sets the body data of this frame as a byte sequence. * @param bytes The byte buffer to be set in the body. * @param numBytes The number of bytes in the buffer. */ - void setBody( const unsigned char* bytes, std::size_t numBytes ); + void setBody(const unsigned char* bytes, std::size_t numBytes); /** * Writes this Frame to an OuputStream in the Stomp Wire Format. @@ -172,7 +175,7 @@ namespace stomp{ * * @throw IOException if an error occurs while reading the Frame. */ - void toStream( decaf::io::DataOutputStream* stream ) const; + void toStream(decaf::io::DataOutputStream* stream) const; /** * Reads a Stop Frame from a DataInputStream in the Stomp Wire format. @@ -181,7 +184,7 @@ namespace stomp{ * * @throw IOException if an error occurs while writing the Frame. */ - void fromStream( decaf::io::DataInputStream* stream ); + void fromStream(decaf::io::DataInputStream* stream); private: @@ -190,14 +193,14 @@ namespace stomp{ * @param in - The stream to read the Frame from. * @throws IOException */ - void readCommandHeader( decaf::io::DataInputStream* in ); + void readCommandHeader(decaf::io::DataInputStream* in); /** * Read all the Stomp Headers for the incoming Frame * @param in - The stream to read the Frame from. * @throws IOException */ - void readHeaders( decaf::io::DataInputStream* in ); + void readHeaders(decaf::io::DataInputStream* in); /** * Reads a Stomp Header line and stores it in the buffer object @@ -206,15 +209,14 @@ namespace stomp{ * @return number of bytes read, zero if there was a problem. * @throws IOException */ - std::size_t readHeaderLine( std::vector& buffer, - decaf::io::DataInputStream* in ); + std::size_t readHeaderLine(std::vector& buffer, decaf::io::DataInputStream* in); /** * Reads the Stomp Body from the Wire and store it in the frame. * @param in - The stream to read the Frame from. * @throws IOException */ - void readBody( decaf::io::DataInputStream* in ); + void readBody(decaf::io::DataInputStream* in); }; Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompHelper.cpp URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompHelper.cpp?rev=1405184&r1=1405183&r2=1405184&view=diff ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompHelper.cpp (original) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompHelper.cpp Fri Nov 2 22:23:43 2012 @@ -17,6 +17,7 @@ #include "StompHelper.h" +#include #include #include @@ -35,7 +36,7 @@ using namespace decaf::lang; using namespace decaf::util; //////////////////////////////////////////////////////////////////////////////// -StompHelper::StompHelper() : messageIdGenerator() { +StompHelper::StompHelper(StompWireFormat* wireformat) : messageIdGenerator(), wireFormat(wireformat) { } //////////////////////////////////////////////////////////////////////////////// @@ -43,240 +44,222 @@ StompHelper::~StompHelper() { } //////////////////////////////////////////////////////////////////////////////// -void StompHelper::convertProperties( const Pointer& frame, - const Pointer& message ) { +void StompHelper::convertProperties(const Pointer& frame, const Pointer& message) { - const std::string destination = - frame->removeProperty( StompCommandConstants::HEADER_DESTINATION ); - message->setDestination( convertDestination( destination ) ); - - const std::string messageId = - frame->removeProperty( StompCommandConstants::HEADER_MESSAGEID ); - message->setMessageId( convertMessageId( messageId ) ); + const std::string destination = frame->removeProperty(StompCommandConstants::HEADER_DESTINATION); + message->setDestination(convertDestination(destination)); + + const std::string messageId = frame->removeProperty(StompCommandConstants::HEADER_MESSAGEID); + message->setMessageId(convertMessageId(messageId)); // the standard JMS headers - if( frame->hasProperty( StompCommandConstants::HEADER_CORRELATIONID ) ) { + if (frame->hasProperty(StompCommandConstants::HEADER_CORRELATIONID)) { message->setCorrelationId( - frame->removeProperty( StompCommandConstants::HEADER_CORRELATIONID ) ); + frame->removeProperty(StompCommandConstants::HEADER_CORRELATIONID)); } - if( frame->hasProperty( StompCommandConstants::HEADER_EXPIRES ) ) { - message->setExpiration( Long::parseLong( - frame->removeProperty( StompCommandConstants::HEADER_EXPIRES ) ) ); + if (frame->hasProperty(StompCommandConstants::HEADER_EXPIRES)) { + message->setExpiration(Long::parseLong( + frame->removeProperty(StompCommandConstants::HEADER_EXPIRES))); } - if( frame->hasProperty( StompCommandConstants::HEADER_JMSPRIORITY ) ) { - message->setPriority( (unsigned char)Integer::parseInt( - frame->removeProperty( StompCommandConstants::HEADER_JMSPRIORITY ) ) ); + if (frame->hasProperty(StompCommandConstants::HEADER_JMSPRIORITY)) { + message->setPriority((unsigned char) Integer::parseInt( + frame->removeProperty(StompCommandConstants::HEADER_JMSPRIORITY))); } - if( frame->hasProperty( StompCommandConstants::HEADER_TYPE ) ) { - message->setType( frame->removeProperty( StompCommandConstants::HEADER_TYPE ) ); + if (frame->hasProperty(StompCommandConstants::HEADER_TYPE)) { + message->setType( + frame->removeProperty(StompCommandConstants::HEADER_TYPE)); } - if( frame->hasProperty( StompCommandConstants::HEADER_REPLYTO ) ) { - message->setReplyTo( convertDestination( - frame->removeProperty( StompCommandConstants::HEADER_REPLYTO ) ) ); + if (frame->hasProperty(StompCommandConstants::HEADER_REPLYTO)) { + message->setReplyTo(convertDestination( + frame->removeProperty(StompCommandConstants::HEADER_REPLYTO))); } - if( frame->hasProperty( StompCommandConstants::HEADER_PERSISTENT ) ) { - message->setPersistent( Boolean::parseBoolean( - frame->removeProperty( StompCommandConstants::HEADER_PERSISTENT ) ) ); + if (frame->hasProperty(StompCommandConstants::HEADER_PERSISTENT)) { + message->setPersistent(Boolean::parseBoolean( + frame->removeProperty(StompCommandConstants::HEADER_PERSISTENT))); } - if( frame->hasProperty( StompCommandConstants::HEADER_TRANSACTIONID ) ) { - std::string transactionId = - frame->removeProperty( StompCommandConstants::HEADER_TRANSACTIONID ); - message->setTransactionId( convertTransactionId( transactionId ) ); + if (frame->hasProperty(StompCommandConstants::HEADER_TRANSACTIONID)) { + std::string transactionId = frame->removeProperty(StompCommandConstants::HEADER_TRANSACTIONID); + message->setTransactionId(convertTransactionId(transactionId)); } // Handle JMSX Properties. - if( frame->hasProperty( "JMSXDeliveryCount" ) ) { - message->setRedeliveryCounter( Integer::parseInt( - frame->removeProperty( "JMSXDeliveryCount" ) ) ); - } - if( frame->hasProperty( "JMSXGroupID" ) ) { - message->setGroupID( frame->removeProperty( "JMSXGroupID" ) ); - } - if( frame->hasProperty( "JMSXGroupSeq" ) ) { - message->setGroupSequence( Integer::parseInt( - frame->removeProperty( "JMSXGroupSeq" ) ) ); + if (frame->hasProperty("JMSXDeliveryCount")) { + message->setRedeliveryCounter(Integer::parseInt(frame->removeProperty("JMSXDeliveryCount"))); + } + if (frame->hasProperty("JMSXGroupID")) { + message->setGroupID(frame->removeProperty("JMSXGroupID")); + } + if (frame->hasProperty("JMSXGroupSeq")) { + message->setGroupSequence(Integer::parseInt(frame->removeProperty("JMSXGroupSeq"))); } // Copy the general headers over to the Message. - std::vector< std::pair > properties = frame->getProperties().toArray(); - std::vector< std::pair >::const_iterator iter = properties.begin(); + std::vector > properties = frame->getProperties().toArray(); + std::vector >::const_iterator iter = properties.begin(); - for( ; iter != properties.end(); ++iter ) { - message->getMessageProperties().setString( iter->first, iter->second ); + for (; iter != properties.end(); ++iter) { + message->getMessageProperties().setString(iter->first, iter->second); } } //////////////////////////////////////////////////////////////////////////////// -void StompHelper::convertProperties( const Pointer& message, - const Pointer& frame ) { +void StompHelper::convertProperties(const Pointer& message, const Pointer& frame) { - frame->setProperty( StompCommandConstants::HEADER_DESTINATION, - convertDestination( message->getDestination() ) ); + frame->setProperty(StompCommandConstants::HEADER_DESTINATION, convertDestination(message->getDestination())); - if( message->getCorrelationId() != "" ) { - frame->setProperty( StompCommandConstants::HEADER_CORRELATIONID, - message->getCorrelationId() ); + if (message->getCorrelationId() != "") { + frame->setProperty(StompCommandConstants::HEADER_CORRELATIONID, message->getCorrelationId()); } - frame->setProperty( StompCommandConstants::HEADER_EXPIRES, - Long::toString( message->getExpiration() ) ); + frame->setProperty(StompCommandConstants::HEADER_EXPIRES, Long::toString(message->getExpiration())); - frame->setProperty( StompCommandConstants::HEADER_PERSISTENT, - Boolean::toString( message->isPersistent() ) ); + frame->setProperty(StompCommandConstants::HEADER_PERSISTENT, Boolean::toString(message->isPersistent())); - if( message->getRedeliveryCounter() != 0 ) { - frame->setProperty( StompCommandConstants::HEADER_REDELIVERED, "true" ); + if (message->getRedeliveryCounter() != 0) { + frame->setProperty(StompCommandConstants::HEADER_REDELIVERED, "true"); } - frame->setProperty( StompCommandConstants::HEADER_JMSPRIORITY, - Integer::toString( message->getPriority() ) ); + frame->setProperty(StompCommandConstants::HEADER_JMSPRIORITY, Integer::toString(message->getPriority())); - if( message->getReplyTo() != NULL ) { - frame->setProperty( StompCommandConstants::HEADER_REPLYTO, - convertDestination( message->getReplyTo() ) ); + if (message->getReplyTo() != NULL) { + frame->setProperty(StompCommandConstants::HEADER_REPLYTO, convertDestination(message->getReplyTo())); } - frame->setProperty( StompCommandConstants::HEADER_TIMESTAMP, - Long::toString( message->getTimestamp() ) ); + frame->setProperty(StompCommandConstants::HEADER_TIMESTAMP, Long::toString(message->getTimestamp())); - if( message->getType() != "" ) { - frame->setProperty( StompCommandConstants::HEADER_TYPE, message->getType() ); + if (message->getType() != "") { + frame->setProperty(StompCommandConstants::HEADER_TYPE, message->getType()); } - if( message->getTransactionId() != NULL ) { - frame->setProperty( StompCommandConstants::HEADER_TRANSACTIONID, - convertTransactionId( message->getTransactionId() ) ); + if (message->getTransactionId() != NULL) { + frame->setProperty(StompCommandConstants::HEADER_TRANSACTIONID, convertTransactionId(message->getTransactionId())); } // Handle JMSX Properties. - frame->setProperty( "JMSXDeliveryCount", - Integer::toString( message->getRedeliveryCounter() ) ); - frame->setProperty( "JMSXGroupSeq", - Integer::toString( message->getGroupSequence() ) ); + frame->setProperty("JMSXDeliveryCount", Integer::toString(message->getRedeliveryCounter())); + frame->setProperty("JMSXGroupSeq", Integer::toString(message->getGroupSequence())); - if( message->getGroupID() != "" ) { - frame->setProperty( "JMSXGroupID", message->getGroupID() ); + if (message->getGroupID() != "") { + frame->setProperty("JMSXGroupID", message->getGroupID()); } - Pointer< Iterator > keys(message->getMessageProperties().keySet().iterator()); + Pointer > keys(message->getMessageProperties().keySet().iterator()); while (keys->hasNext()) { std::string key = keys->next(); - frame->setProperty(key, message->getMessageProperties().getString(key) ); + frame->setProperty(key, message->getMessageProperties().getString(key)); } } //////////////////////////////////////////////////////////////////////////////// -std::string StompHelper::convertDestination( const Pointer& destination ) { +std::string StompHelper::convertDestination(const Pointer& destination) { - if( destination == NULL ) { + if (destination == NULL) { return ""; } else { - switch( destination->getDestinationType() ) { + switch (destination->getDestinationType()) { - case cms::Destination::TOPIC: - return std::string( "/topic/" ) + destination->getPhysicalName(); - case cms::Destination::TEMPORARY_TOPIC: - - if( destination->getPhysicalName().find( "/remote-temp-topic/" ) == 0 ) { - return destination->getPhysicalName(); - } else { - return std::string( "/temp-topic/" ) + destination->getPhysicalName(); - } - - case cms::Destination::TEMPORARY_QUEUE: - - if( destination->getPhysicalName().find( "/remote-temp-queue/" ) == 0 ) { - return destination->getPhysicalName(); - } else { - return std::string( "/temp-queue/" ) + destination->getPhysicalName(); - } + case cms::Destination::TOPIC: + return std::string(wireFormat->getTopicPrefix()) + destination->getPhysicalName(); + case cms::Destination::TEMPORARY_TOPIC: + + if (destination->getPhysicalName().find("/remote-temp-topic/") == 0) { + return destination->getPhysicalName(); + } else { + return std::string(wireFormat->getTempTopicPrefix()) + destination->getPhysicalName(); + } + + case cms::Destination::TEMPORARY_QUEUE: + + if (destination->getPhysicalName().find("/remote-temp-queue/") == 0) { + return destination->getPhysicalName(); + } else { + return std::string(wireFormat->getTempQueuePrefix()) + destination->getPhysicalName(); + } - default: - return std::string( "/queue/" ) + destination->getPhysicalName(); + default: + return std::string(wireFormat->getQueuePrefix()) + destination->getPhysicalName(); } } } //////////////////////////////////////////////////////////////////////////////// -Pointer StompHelper::convertDestination( const std::string& destination ) { +Pointer StompHelper::convertDestination(const std::string& destination) { - if( destination == "" ) { + if (destination == "") { return Pointer(); } int type = 0; std::string dest = ""; - if( destination.find( "/queue/" ) == 0 ) { - dest = destination.substr( 7 ); + if (destination.find(wireFormat->getQueuePrefix()) == 0) { + dest = destination.substr(wireFormat->getQueuePrefix().length()); type = cms::Destination::QUEUE; - } else if( destination.find( "/topic/" ) == 0 ) { - dest = destination.substr( 7 ); + } else if (destination.find(wireFormat->getTopicPrefix()) == 0) { + dest = destination.substr(wireFormat->getTopicPrefix().length()); type = cms::Destination::TOPIC; - } else if( destination.find( "/temp-topic/" ) == 0 ) { - dest = destination.substr( 12 ); + } else if (destination.find(wireFormat->getTempTopicPrefix()) == 0) { + dest = destination.substr(wireFormat->getTempTopicPrefix().length()); type = cms::Destination::TEMPORARY_TOPIC; - } else if( destination.find( "/temp-queue/" ) == 0 ) { - dest = destination.substr( 12 ); + } else if (destination.find(wireFormat->getTempQueuePrefix()) == 0) { + dest = destination.substr(wireFormat->getTempQueuePrefix().length()); type = cms::Destination::TEMPORARY_QUEUE; - } else if( destination.find( "/remote-temp-topic/" ) == 0 ) { + } else if (destination.find("/remote-temp-topic/") == 0) { type = cms::Destination::TEMPORARY_TOPIC; - } else if( destination.find( "/remote-temp-queue/" ) == 0 ) { + } else if (destination.find("/remote-temp-queue/") == 0) { type = cms::Destination::TEMPORARY_QUEUE; } - return ActiveMQDestination::createDestination( type, dest ); + return ActiveMQDestination::createDestination(type, dest); } //////////////////////////////////////////////////////////////////////////////// -std::string StompHelper::convertMessageId( const Pointer& messageId ) { +std::string StompHelper::convertMessageId(const Pointer& messageId) { // The Stomp MessageId is always hidden solely in the Producer Id. - std::string result = convertProducerId( messageId->getProducerId() ); + std::string result = convertProducerId(messageId->getProducerId()); return result; } //////////////////////////////////////////////////////////////////////////////// -Pointer StompHelper::convertMessageId( const std::string& messageId ) { +Pointer StompHelper::convertMessageId(const std::string& messageId) { - if( messageId == "" ) { + if (messageId == "") { return Pointer(); } - Pointer id( new MessageId() ); + Pointer id(new MessageId()); - id->setProducerId( convertProducerId( messageId ) ); - id->setProducerSequenceId( this->messageIdGenerator.getNextSequenceId() ); + id->setProducerId(convertProducerId(messageId)); + id->setProducerSequenceId(this->messageIdGenerator.getNextSequenceId()); return id; } //////////////////////////////////////////////////////////////////////////////// -std::string StompHelper::convertConsumerId( const Pointer& consumerId ) { +std::string StompHelper::convertConsumerId(const Pointer& consumerId) { - return consumerId->getConnectionId() + ":" + - Long::toString( consumerId->getSessionId() ) + ":" + - Long::toString( consumerId->getValue() ); + return consumerId->getConnectionId() + ":" + Long::toString(consumerId->getSessionId()) + ":" + Long::toString(consumerId->getValue()); } //////////////////////////////////////////////////////////////////////////////// -Pointer StompHelper::convertConsumerId( const std::string& consumerId ) { +Pointer StompHelper::convertConsumerId(const std::string& consumerId) { - if( consumerId == "" ) { + if (consumerId == "") { return Pointer(); } - Pointer id( new ConsumerId() ); + Pointer id(new ConsumerId()); - StringTokenizer tokenizer( consumerId, ":" ); + StringTokenizer tokenizer(consumerId, ":"); string connectionId; @@ -286,15 +269,15 @@ Pointer StompHelper::convert connectionId += ":"; connectionId += tokenizer.nextToken(); - id->setConnectionId( connectionId ); + id->setConnectionId(connectionId); - while( tokenizer.hasMoreTokens() ){ + while (tokenizer.hasMoreTokens()) { string text = tokenizer.nextToken(); - if( tokenizer.hasMoreTokens() ) { - id->setSessionId( Long::parseLong( text ) ); + if (tokenizer.hasMoreTokens()) { + id->setSessionId(Long::parseLong(text)); } else { - id->setValue( Long::parseLong( text ) ); + id->setValue(Long::parseLong(text)); } } @@ -302,57 +285,57 @@ Pointer StompHelper::convert } //////////////////////////////////////////////////////////////////////////////// -std::string StompHelper::convertProducerId( const Pointer& producerId ) { +std::string StompHelper::convertProducerId(const Pointer& producerId) { return producerId->getConnectionId(); } //////////////////////////////////////////////////////////////////////////////// -Pointer StompHelper::convertProducerId( const std::string& producerId ) { +Pointer StompHelper::convertProducerId(const std::string& producerId) { - if( producerId == "" ) { + if (producerId == "") { return Pointer(); } - Pointer id( new ProducerId() ); + Pointer id(new ProducerId()); - id->setConnectionId( producerId ); - id->setSessionId( -1 ); - id->setValue( -1 ); + id->setConnectionId(producerId); + id->setSessionId(-1); + id->setValue(-1); return id; } //////////////////////////////////////////////////////////////////////////////// -std::string StompHelper::convertTransactionId( const Pointer& transactionId ) { +std::string StompHelper::convertTransactionId(const Pointer& transactionId) { Pointer id = transactionId.dynamicCast(); - std::string result = id->getConnectionId()->getValue() + ":" + Long::toString( id->getValue() ); + std::string result = id->getConnectionId()->getValue() + ":" + Long::toString(id->getValue()); return result; } //////////////////////////////////////////////////////////////////////////////// -Pointer StompHelper::convertTransactionId( const std::string& transactionId ) { +Pointer StompHelper::convertTransactionId(const std::string& transactionId) { - if( transactionId == "" ) { + if (transactionId == "") { return Pointer(); } - Pointer id( new LocalTransactionId() ); - StringTokenizer tokenizer( transactionId, ":" ); + Pointer id(new LocalTransactionId()); + StringTokenizer tokenizer(transactionId, ":"); string connectionIdStr; connectionIdStr += tokenizer.nextToken(); connectionIdStr += ":"; connectionIdStr += tokenizer.nextToken(); - Pointer connectionId( new ConnectionId() ); - connectionId->setValue( connectionIdStr ); - id->setConnectionId( connectionId ); + Pointer connectionId(new ConnectionId()); + connectionId->setValue(connectionIdStr); + id->setConnectionId(connectionId); - while( tokenizer.hasMoreTokens() ){ + while (tokenizer.hasMoreTokens()) { string text = tokenizer.nextToken(); - id->setValue( Long::parseLong( text ) ); + id->setValue(Long::parseLong(text)); } return id; Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompHelper.h URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompHelper.h?rev=1405184&r1=1405183&r2=1405184&view=diff ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompHelper.h (original) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompHelper.h Fri Nov 2 22:23:43 2012 @@ -33,6 +33,8 @@ namespace activemq { namespace wireformat { namespace stomp { + class StompWireFormat; + using decaf::lang::Pointer; using activemq::commands::Message; using activemq::commands::MessageId; @@ -50,10 +52,11 @@ namespace stomp { private: activemq::util::LongSequenceGenerator messageIdGenerator; + StompWireFormat* wireFormat; public: - StompHelper(); + StompHelper(StompWireFormat* wireFormat); virtual ~StompHelper(); @@ -66,7 +69,7 @@ namespace stomp { * @param frame - The frame to extract headers from. * @param message - The message to move the Headers to. */ - void convertProperties( const Pointer& frame, const Pointer& message ); + void convertProperties(const Pointer& frame, const Pointer& message); /** * Converts the Properties in a Message Command to Valid Headers and Properties @@ -75,7 +78,7 @@ namespace stomp { * @param message - The message to move the Headers to. * @param frame - The frame to extract headers from. */ - void convertProperties( const Pointer& message, const Pointer& frame ); + void convertProperties(const Pointer& message, const Pointer& frame); /** * Converts from a Stomp Destination to an ActiveMQDestination @@ -83,7 +86,7 @@ namespace stomp { * @param destination - The Stomp Destination name string. * @returns Pointer to a new ActiveMQDestination. */ - Pointer convertDestination( const std::string& destination ); + Pointer convertDestination(const std::string& destination); /** * Converts from a ActiveMQDestination to a Stomp Destination Name @@ -91,7 +94,7 @@ namespace stomp { * @param destination - The ActiveMQDestination to Convert * @return the Stomp String name that defines the destination. */ - std::string convertDestination( const Pointer& destination ); + std::string convertDestination(const Pointer& destination); /** * Converts a MessageId instance to a Stomp MessageId String. @@ -99,7 +102,7 @@ namespace stomp { * @param messageId - the MessageId instance to convert. * @return a Stomp Message Id String. */ - std::string convertMessageId( const Pointer& messageId ); + std::string convertMessageId(const Pointer& messageId); /** * Converts a Stomp MessageId string to a MessageId @@ -107,7 +110,7 @@ namespace stomp { * @param messageId - the String message Id to convert. * @return Pointer to a new MessageId. */ - Pointer convertMessageId( const std::string& messageId ); + Pointer convertMessageId(const std::string& messageId); /** * Converts a ConsumerId instance to a Stomp ConsumerId String. @@ -115,7 +118,7 @@ namespace stomp { * @param consumerId - the Consumer instance to convert. * @return a Stomp Consumer Id String. */ - std::string convertConsumerId( const Pointer& consumerId ); + std::string convertConsumerId(const Pointer& consumerId); /** * Converts a Stomp ConsumerId string to a ConsumerId @@ -123,7 +126,7 @@ namespace stomp { * @param consumerId - the String Consumer Id to convert. * @return Pointer to a new ConsumerId. */ - Pointer convertConsumerId( const std::string& consumerId ); + Pointer convertConsumerId(const std::string& consumerId); /** * Converts a ProducerId instance to a Stomp ProducerId String. @@ -131,7 +134,7 @@ namespace stomp { * @param producerId - the Producer instance to convert. * @return a Stomp Producer Id String. */ - std::string convertProducerId( const Pointer& producerId ); + std::string convertProducerId(const Pointer& producerId); /** * Converts a Stomp ProducerId string to a ProducerId @@ -139,7 +142,7 @@ namespace stomp { * @param producerId - the String Producer Id to convert. * @return Pointer to a new ProducerId. */ - Pointer convertProducerId( const std::string& producerId ); + Pointer convertProducerId(const std::string& producerId); /** * Converts a TransactionId instance to a Stomp TransactionId String. @@ -147,7 +150,7 @@ namespace stomp { * @param transactionId - the Transaction instance to convert. * @return a Stomp Transaction Id String. */ - std::string convertTransactionId( const Pointer& transactionId ); + std::string convertTransactionId(const Pointer& transactionId); /** * Converts a Stomp TransactionId string to a TransactionId @@ -155,7 +158,7 @@ namespace stomp { * @param transactionId - the String Transaction Id to convert. * @return Pointer to a new TransactionId. */ - Pointer convertTransactionId( const std::string& transactionId ); + Pointer convertTransactionId(const std::string& transactionId); }; Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompWireFormat.cpp URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompWireFormat.cpp?rev=1405184&r1=1405183&r2=1405184&view=diff ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompWireFormat.cpp (original) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompWireFormat.cpp Fri Nov 2 22:23:43 2012 @@ -18,6 +18,7 @@ #include "StompWireFormat.h" #include +#include #include #include #include @@ -70,9 +71,25 @@ namespace stomp { int connectResponseId; + // Prefix used to address Topics (default is /topic/ + std::string topicPrefix; + + // Prefix used to address Queues (default is /queue/ + std::string queuePrefix; + + // Prefix used to address Temporary Topics (default is /temp-topic/ + std::string tempTopicPrefix; + + // Prefix used to address Temporary Queues (default is /temp-queue/ + std::string tempQueuePrefix; + public: - StompWireformatProperties() : connectResponseId(-1) { + StompWireformatProperties() : connectResponseId(-1), + topicPrefix("/topic/"), + queuePrefix("/queue/"), + tempTopicPrefix("/temp-topic/"), + tempQueuePrefix("/temp-queue/") { } @@ -81,15 +98,16 @@ namespace stomp { }}} //////////////////////////////////////////////////////////////////////////////// -StompWireFormat::StompWireFormat() : helper(), clientId(), receiving(), properties(NULL) { - +StompWireFormat::StompWireFormat() : helper(NULL), clientId(), receiving(), properties(NULL) { + this->helper = new StompHelper(this); this->properties = new StompWireformatProperties(); } //////////////////////////////////////////////////////////////////////////////// StompWireFormat::~StompWireFormat() { - try{ + try { + delete this->helper; delete this->properties; } AMQ_CATCHALL_NOTHROW() @@ -233,14 +251,14 @@ Pointer StompWireFormat::unmars // We created a unique id when we registered the subscription for the consumer // now extract it back to a consumer Id so the ActiveMQConnection can dispatch it // correctly. - Pointer consumerId = helper.convertConsumerId(frame->removeProperty(StompCommandConstants::HEADER_SUBSCRIPTION)); + Pointer consumerId = helper->convertConsumerId(frame->removeProperty(StompCommandConstants::HEADER_SUBSCRIPTION)); messageDispatch->setConsumerId(consumerId); if (frame->hasProperty(StompCommandConstants::HEADER_CONTENTLENGTH)) { Pointer message(new ActiveMQBytesMessage()); frame->removeProperty(StompCommandConstants::HEADER_CONTENTLENGTH); - helper.convertProperties(frame, message); + helper->convertProperties(frame, message); message->setContent(frame->getBody()); messageDispatch->setMessage(message); messageDispatch->setDestination(message->getDestination()); @@ -248,7 +266,7 @@ Pointer StompWireFormat::unmars } else { Pointer message(new ActiveMQTextMessage()); - helper.convertProperties(frame, message); + helper->convertProperties(frame, message); message->setText((char*) &(frame->getBody()[0])); messageDispatch->setMessage(message); messageDispatch->setDestination(message->getDestination()); @@ -335,7 +353,7 @@ Pointer StompWireFormat::mar } // Convert the standard headers to the Stomp Format. - helper.convertProperties(message, frame); + helper->convertProperties(message, frame); // Convert the Content try { @@ -366,13 +384,16 @@ Pointer StompWireFormat::mar frame->setCommand(StompCommandConstants::ACK); if (command->isResponseRequired()) { - frame->setProperty(StompCommandConstants::HEADER_RECEIPT_REQUIRED, std::string("ignore:") + Integer::toString(command->getCommandId())); + frame->setProperty(StompCommandConstants::HEADER_RECEIPT_REQUIRED, + std::string("ignore:") + Integer::toString(command->getCommandId())); } - frame->setProperty(StompCommandConstants::HEADER_MESSAGEID, helper.convertMessageId(ack->getLastMessageId())); + frame->setProperty(StompCommandConstants::HEADER_MESSAGEID, + helper->convertMessageId(ack->getLastMessageId())); if (ack->getTransactionId() != NULL) { - frame->setProperty(StompCommandConstants::HEADER_TRANSACTIONID, helper.convertTransactionId(ack->getTransactionId())); + frame->setProperty(StompCommandConstants::HEADER_TRANSACTIONID, + helper->convertTransactionId(ack->getTransactionId())); } return frame; @@ -417,7 +438,8 @@ Pointer StompWireFormat::mar frame->setProperty(StompCommandConstants::HEADER_RECEIPT_REQUIRED, Integer::toString(command->getCommandId())); } - frame->setProperty(StompCommandConstants::HEADER_TRANSACTIONID, helper.convertTransactionId(info->getTransactionId())); + frame->setProperty(StompCommandConstants::HEADER_TRANSACTIONID, + helper->convertTransactionId(info->getTransactionId())); return frame; } @@ -448,7 +470,7 @@ Pointer StompWireFormat::mar try { Pointer id = info->getObjectId().dynamicCast(); - frame->setProperty(StompCommandConstants::HEADER_ID, helper.convertConsumerId(id)); + frame->setProperty(StompCommandConstants::HEADER_ID, helper->convertConsumerId(id)); return frame; } catch (ClassCastException& ex) { } @@ -468,12 +490,12 @@ Pointer StompWireFormat::mar frame->setProperty(StompCommandConstants::HEADER_RECEIPT_REQUIRED, Integer::toString(command->getCommandId())); } - frame->setProperty(StompCommandConstants::HEADER_DESTINATION, helper.convertDestination(info->getDestination())); + frame->setProperty(StompCommandConstants::HEADER_DESTINATION, helper->convertDestination(info->getDestination())); // This creates a unique Id for this consumer using the connection id, session id and // the consumers's id value, when we get a message this Id will be embedded in the // Message's "subscription" property. - frame->setProperty(StompCommandConstants::HEADER_ID, helper.convertConsumerId(info->getConsumerId())); + frame->setProperty(StompCommandConstants::HEADER_ID, helper->convertConsumerId(info->getConsumerId())); if (info->getSubscriptionName() != "") { @@ -535,3 +557,43 @@ Pointer StompWireFormat::mar return frame; } + +//////////////////////////////////////////////////////////////////////////////// +std::string StompWireFormat::getTopicPrefix() const { + return this->properties->topicPrefix; +} + +//////////////////////////////////////////////////////////////////////////////// +void StompWireFormat::setTopicPrefix(const std::string& prefix) { + this->properties->topicPrefix = prefix; +} + +//////////////////////////////////////////////////////////////////////////////// +std::string StompWireFormat::getQueuePrefix() const { + return this->properties->queuePrefix; +} + +//////////////////////////////////////////////////////////////////////////////// +void StompWireFormat::setQueuePrefix(const std::string& prefix) { + this->properties->queuePrefix = prefix; +} + +//////////////////////////////////////////////////////////////////////////////// +std::string StompWireFormat::getTempTopicPrefix() const { + return this->properties->tempTopicPrefix; +} + +//////////////////////////////////////////////////////////////////////////////// +void StompWireFormat::setTempTopicPrefix(const std::string& prefix) { + this->properties->tempTopicPrefix = prefix; +} + +//////////////////////////////////////////////////////////////////////////////// +std::string StompWireFormat::getTempQueuePrefix() const { + return this->properties->tempQueuePrefix; +} + +//////////////////////////////////////////////////////////////////////////////// +void StompWireFormat::setTempQueuePrefix(const std::string& prefix) { + this->properties->tempQueuePrefix = prefix; +} Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompWireFormat.h URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompWireFormat.h?rev=1405184&r1=1405183&r2=1405184&view=diff ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompWireFormat.h (original) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompWireFormat.h Fri Nov 2 22:23:43 2012 @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include @@ -33,15 +32,16 @@ namespace stomp { using decaf::lang::Pointer; using activemq::commands::Command; + class StompHelper; class StompWireformatProperties; class AMQCPP_API StompWireFormat : public WireFormat { private: /** - * Performs conversions for stomp types and canonical types. + * Performs conversions for STOMP types and canonical types. */ - StompHelper helper; + StompHelper* helper; // Stored after we connect to use when validating that a durable subscribe // and unsubscribe are set to use the client Id. @@ -96,7 +96,7 @@ namespace stomp { * Set the Version * @param the version of the wire format */ - virtual void setVersion( int version AMQCPP_UNUSED ) {} + virtual void setVersion(int version AMQCPP_UNUSED) {} /** * Get the Version @@ -107,6 +107,66 @@ namespace stomp { } /** + * Gets the prefix used to address Topics + * + * @return the string prefix used to address Topics. + */ + std::string getTopicPrefix() const; + + /** + * Sets the prefix used to address Topics. + * + * @param prefix + * The prefix to use. + */ + void setTopicPrefix(const std::string& prefix); + + /** + * Gets the prefix used to address Queues + * + * @return the string prefix used to address Queues. + */ + std::string getQueuePrefix() const; + + /** + * Sets the prefix used to address Queues. + * + * @param prefix + * The prefix to use. + */ + void setQueuePrefix(const std::string& prefix); + + /** + * Gets the prefix used to address Temporary Topics + * + * @return the string prefix used to address Temporary Topics. + */ + std::string getTempTopicPrefix() const; + + /** + * Sets the prefix used to address Temporary Topics. + * + * @param prefix + * The prefix to use. + */ + void setTempTopicPrefix(const std::string& prefix); + + /** + * Gets the prefix used to address Temporary Queues + * + * @return the string prefix used to address Temporary Queues. + */ + std::string getTempQueuePrefix() const; + + /** + * Sets the prefix used to address Temporary Queues. + * + * @param prefix + * The prefix to use. + */ + void setTempQueuePrefix(const std::string& prefix); + + /** * Is there a Message being unmarshaled? * * @return true while in the doUnmarshal method. Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompWireFormatFactory.cpp URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompWireFormatFactory.cpp?rev=1405184&r1=1405183&r2=1405184&view=diff ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompWireFormatFactory.cpp (original) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompWireFormatFactory.cpp Fri Nov 2 22:23:43 2012 @@ -26,12 +26,23 @@ using namespace activemq::wireformat::st using namespace activemq::exceptions; //////////////////////////////////////////////////////////////////////////////// -Pointer StompWireFormatFactory::createWireFormat( - const decaf::util::Properties& properties AMQCPP_UNUSED ) { +Pointer StompWireFormatFactory::createWireFormat(const decaf::util::Properties& properties AMQCPP_UNUSED) { - try{ - return Pointer( new StompWireFormat() ); + try { + + Pointer wireFormat(new StompWireFormat()); + + wireFormat->setTopicPrefix( + properties.getProperty("wireFormat.topicPrefix", "/topic/")); + wireFormat->setQueuePrefix( + properties.getProperty("wireFormat.queuePrefix", "/queue/")); + wireFormat->setTempTopicPrefix( + properties.getProperty("wireFormat.tempTopicPrefix", "/temp-topic/")); + wireFormat->setTempQueuePrefix( + properties.getProperty("wireFormat.tempQueuePrefix", "/temp-queue/")); + + return wireFormat; } - AMQ_CATCH_RETHROW( ActiveMQException ) - AMQ_CATCHALL_THROW( ActiveMQException ) + AMQ_CATCH_RETHROW(ActiveMQException) + AMQ_CATCHALL_THROW(ActiveMQException) } Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompWireFormatFactory.h URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompWireFormatFactory.h?rev=1405184&r1=1405183&r2=1405184&view=diff ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompWireFormatFactory.h (original) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompWireFormatFactory.h Fri Nov 2 22:23:43 2012 @@ -43,7 +43,7 @@ namespace stomp { * properties from which it can obtain any optional settings * @param properties - the Properties for this WireFormat */ - virtual Pointer createWireFormat( const decaf::util::Properties& properties ); + virtual Pointer createWireFormat(const decaf::util::Properties& properties); };