qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c...@apache.org
Subject svn commit: r1651773 - /qpid/trunk/qpid/cpp/examples/messaging/server.cpp
Date Wed, 14 Jan 2015 18:54:00 GMT
Author: chug
Date: Wed Jan 14 18:54:00 2015
New Revision: 1651773

URL: http://svn.apache.org/r1651773
Log:
QPID-6308: Preserve request string encoding in response string.
Non-string requests are echoed as utf8 strings.


Modified:
    qpid/trunk/qpid/cpp/examples/messaging/server.cpp

Modified: qpid/trunk/qpid/cpp/examples/messaging/server.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/examples/messaging/server.cpp?rev=1651773&r1=1651772&r2=1651773&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/examples/messaging/server.cpp (original)
+++ qpid/trunk/qpid/cpp/examples/messaging/server.cpp Wed Jan 14 18:54:00 2015
@@ -52,10 +52,24 @@ int main(int argc, char** argv) {
             const Address& address = request.getReplyTo();
             if (address) {
                 Sender sender = session.createSender(address);
-                std::string s = request.getContentObject();
-                std::transform(s.begin(), s.end(), s.begin(), toupper);
                 Message response;
-                response.setContentObject(s);
+
+                qpid::types::Variant requestObj = request.getContentObject();
+                if (requestObj.getType() == qpid::types::VAR_STRING) {
+                    // Received a string.
+                    // Server returns request string in upper case with same encoding.
+                    std::string s = requestObj;
+                    std::transform(s.begin(), s.end(), s.begin(), toupper);
+                    qpid::types::Variant responseObj(s);
+                    responseObj.setEncoding( requestObj.getEncoding() );
+                    response.setContentObject( responseObj );
+                } else {
+                    // Received something other than a string.
+                    // Server echos received object as a utf8 string.
+                    qpid::types::Variant responseObj( requestObj.asString() );
+                    responseObj.setEncoding( "utf8" );
+                    response.setContentObject( requestObj );
+                }
                 sender.send(response);
                 std::cout << "Processed request: "
                           << request.getContentObject()



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message