You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2011/02/10 22:14:35 UTC

svn commit: r1069570 - in /activemq/activemq-cpp/branches/activemq-cpp-3.2.x/activemq-cpp/src: main/activemq/core/ActiveMQConnectionFactory.cpp main/activemq/transport/failover/FailoverTransportFactory.cpp test/activemq/util/URISupportTest.cpp

Author: tabish
Date: Thu Feb 10 21:14:35 2011
New Revision: 1069570

URL: http://svn.apache.org/viewvc?rev=1069570&view=rev
Log:
fix for: https://issues.apache.org/jira/browse/AMQCPP-350

Modified:
    activemq/activemq-cpp/branches/activemq-cpp-3.2.x/activemq-cpp/src/main/activemq/core/ActiveMQConnectionFactory.cpp
    activemq/activemq-cpp/branches/activemq-cpp-3.2.x/activemq-cpp/src/main/activemq/transport/failover/FailoverTransportFactory.cpp
    activemq/activemq-cpp/branches/activemq-cpp-3.2.x/activemq-cpp/src/test/activemq/util/URISupportTest.cpp

Modified: activemq/activemq-cpp/branches/activemq-cpp-3.2.x/activemq-cpp/src/main/activemq/core/ActiveMQConnectionFactory.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/branches/activemq-cpp-3.2.x/activemq-cpp/src/main/activemq/core/ActiveMQConnectionFactory.cpp?rev=1069570&r1=1069569&r2=1069570&view=diff
==============================================================================
--- activemq/activemq-cpp/branches/activemq-cpp-3.2.x/activemq-cpp/src/main/activemq/core/ActiveMQConnectionFactory.cpp (original)
+++ activemq/activemq-cpp/branches/activemq-cpp-3.2.x/activemq-cpp/src/main/activemq/core/ActiveMQConnectionFactory.cpp Thu Feb 10 21:14:35 2011
@@ -29,6 +29,7 @@
 #include <activemq/core/policies/DefaultPrefetchPolicy.h>
 #include <activemq/core/policies/DefaultRedeliveryPolicy.h>
 #include <activemq/util/URISupport.h>
+#include <activemq/util/CompositeData.h>
 #include <memory>
 
 using namespace std;
@@ -94,7 +95,16 @@ namespace core{
 
             this->brokerURL = uri.toString();
             this->properties->clear();
-            activemq::util::URISupport::parseQuery( uri.getQuery(), properties.get() );
+
+            if( uri.getQuery() != "" ) {
+                // Not a composite URI so this works fine.
+                activemq::util::URISupport::parseQuery( uri.getQuery(), properties.get() );
+            } else {
+                // Composite URI won't indicate it has a query even if it does.
+                activemq::util::CompositeData composite = activemq::util::URISupport::parseComposite( uri );
+
+                *this->properties = composite.getParameters();
+            }
 
             // Check the connection options
             this->alwaysSyncSend = Boolean::parseBoolean(

Modified: activemq/activemq-cpp/branches/activemq-cpp-3.2.x/activemq-cpp/src/main/activemq/transport/failover/FailoverTransportFactory.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/branches/activemq-cpp-3.2.x/activemq-cpp/src/main/activemq/transport/failover/FailoverTransportFactory.cpp?rev=1069570&r1=1069569&r2=1069570&view=diff
==============================================================================
--- activemq/activemq-cpp/branches/activemq-cpp-3.2.x/activemq-cpp/src/main/activemq/transport/failover/FailoverTransportFactory.cpp (original)
+++ activemq/activemq-cpp/branches/activemq-cpp-3.2.x/activemq-cpp/src/main/activemq/transport/failover/FailoverTransportFactory.cpp Thu Feb 10 21:14:35 2011
@@ -43,8 +43,7 @@ throw ( activemq::exceptions::ActiveMQEx
 
     try{
 
-        Properties properties =
-            activemq::util::URISupport::parseQuery( location.getQuery() );
+        Properties properties;  // unused but necessary for now.
 
         // Create the initial Transport, then wrap it in the normal Filters
         Pointer<Transport> transport( doCreateComposite( location, properties ) );
@@ -65,8 +64,7 @@ Pointer<Transport> FailoverTransportFact
 
     try{
 
-        Properties properties =
-            activemq::util::URISupport::parseQuery( location.getQuery() );
+        Properties properties;  // unused but necessary for now.
 
         // Create the initial Transport, then wrap it in the normal Filters
         return doCreateComposite( location, properties );
@@ -87,28 +85,30 @@ Pointer<Transport> FailoverTransportFact
         CompositeData data = URISupport::parseComposite( location );
         Pointer<FailoverTransport> transport( new FailoverTransport() );
 
+        Properties topLvlProperties = data.getParameters();
+
         transport->setInitialReconnectDelay(
-            Long::parseLong( properties.getProperty( "initialReconnectDelay", "10" ) ) );
+            Long::parseLong( topLvlProperties.getProperty( "initialReconnectDelay", "10" ) ) );
         transport->setMaxReconnectDelay(
-            Long::parseLong( properties.getProperty( "maxReconnectDelay", "30000" ) ) );
+            Long::parseLong( topLvlProperties.getProperty( "maxReconnectDelay", "30000" ) ) );
         transport->setUseExponentialBackOff(
-            Boolean::parseBoolean( properties.getProperty( "useExponentialBackOff", "true" ) ) );
+            Boolean::parseBoolean( topLvlProperties.getProperty( "useExponentialBackOff", "true" ) ) );
         transport->setMaxReconnectAttempts(
-            Integer::parseInt( properties.getProperty( "maxReconnectAttempts", "0" ) ) );
+            Integer::parseInt( topLvlProperties.getProperty( "maxReconnectAttempts", "0" ) ) );
         transport->setStartupMaxReconnectAttempts(
-            Integer::parseInt( properties.getProperty( "startupMaxReconnectAttempts", "0" ) ) );
+            Integer::parseInt( topLvlProperties.getProperty( "startupMaxReconnectAttempts", "0" ) ) );
         transport->setRandomize(
-            Boolean::parseBoolean( properties.getProperty( "randomize", "true" ) ) );
+            Boolean::parseBoolean( topLvlProperties.getProperty( "randomize", "true" ) ) );
         transport->setBackup(
-            Boolean::parseBoolean( properties.getProperty( "backup", "false" ) ) );
+            Boolean::parseBoolean( topLvlProperties.getProperty( "backup", "false" ) ) );
         transport->setBackupPoolSize(
-            Integer::parseInt( properties.getProperty( "backupPoolSize", "1" ) ) );
+            Integer::parseInt( topLvlProperties.getProperty( "backupPoolSize", "1" ) ) );
         transport->setTimeout(
-            Long::parseLong( properties.getProperty( "timeout", "-1" ) ) );
+            Long::parseLong( topLvlProperties.getProperty( "timeout", "-1" ) ) );
         transport->setTrackMessages(
-            Boolean::parseBoolean( properties.getProperty( "trackMessages", "false" ) ) );
+            Boolean::parseBoolean( topLvlProperties.getProperty( "trackMessages", "false" ) ) );
         transport->setMaxCacheSize(
-            Integer::parseInt( properties.getProperty( "maxCacheSize", "131072" ) ) );
+            Integer::parseInt( topLvlProperties.getProperty( "maxCacheSize", "131072" ) ) );
 
         transport->addURI( data.getComponents() );
 

Modified: activemq/activemq-cpp/branches/activemq-cpp-3.2.x/activemq-cpp/src/test/activemq/util/URISupportTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/branches/activemq-cpp-3.2.x/activemq-cpp/src/test/activemq/util/URISupportTest.cpp?rev=1069570&r1=1069569&r2=1069570&view=diff
==============================================================================
--- activemq/activemq-cpp/branches/activemq-cpp-3.2.x/activemq-cpp/src/test/activemq/util/URISupportTest.cpp (original)
+++ activemq/activemq-cpp/branches/activemq-cpp-3.2.x/activemq-cpp/src/test/activemq/util/URISupportTest.cpp Thu Feb 10 21:14:35 2011
@@ -65,6 +65,26 @@ void URISupportTest::test() {
     } catch(...) {
         CPPUNIT_ASSERT( false );
     }
+
+    string test5 = "failover:(tcp://127.0.0.1:61616)?startupMaxReconnectAttempts=10&initialReconnectDelay=10";
+
+    map = URISupport::parseQuery( test5 );
+
+    CPPUNIT_ASSERT( map.hasProperty( "startupMaxReconnectAttempts" ) == true );
+    CPPUNIT_ASSERT( map.hasProperty( "initialReconnectDelay" ) == true );
+
+    CPPUNIT_ASSERT( map.getProperty( "startupMaxReconnectAttempts", "" ) == "10" );
+    CPPUNIT_ASSERT( map.getProperty( "initialReconnectDelay", "" ) == "10" );
+
+    string test6 = "failover://(tcp://127.0.0.1:61616)?startupMaxReconnectAttempts=10&initialReconnectDelay=10";
+
+    map = URISupport::parseQuery( test6 );
+
+    CPPUNIT_ASSERT( map.hasProperty( "startupMaxReconnectAttempts" ) == true );
+    CPPUNIT_ASSERT( map.hasProperty( "initialReconnectDelay" ) == true );
+
+    CPPUNIT_ASSERT( map.getProperty( "startupMaxReconnectAttempts", "" ) == "10" );
+    CPPUNIT_ASSERT( map.getProperty( "initialReconnectDelay", "" ) == "10" );
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -151,4 +171,26 @@ void URISupportTest::testParseComposite(
     CPPUNIT_ASSERT( data.getComponents().get(0).toString() ==
                     "tcp://localhost:61616?wireformat=openwire" );
 
+    data = URISupport::parseComposite(
+        URI( "broker:(tcp://localhost:61616?wireformat=openwire)?name=foo" ) );
+
+    CPPUNIT_ASSERT( data.getScheme() == "broker" );
+    CPPUNIT_ASSERT( data.getParameters().hasProperty( "name" ) );
+    CPPUNIT_ASSERT( !data.getParameters().hasProperty( "wireformat" ) );
+    CPPUNIT_ASSERT( string( data.getParameters().getProperty( "name" ) ) == "foo" );
+    CPPUNIT_ASSERT( data.getComponents().size() == 1 );
+    CPPUNIT_ASSERT( data.getComponents().get(0).toString() ==
+                    "tcp://localhost:61616?wireformat=openwire" );
+
+    data = URISupport::parseComposite(
+        URI( "broker:(tcp://localhost:61616)?name=foo" ) );
+
+    CPPUNIT_ASSERT( data.getScheme() == "broker" );
+    CPPUNIT_ASSERT( data.getParameters().hasProperty( "name" ) );
+    CPPUNIT_ASSERT( !data.getParameters().hasProperty( "wireformat" ) );
+    CPPUNIT_ASSERT( string( data.getParameters().getProperty( "name" ) ) == "foo" );
+    CPPUNIT_ASSERT( data.getComponents().size() == 1 );
+    CPPUNIT_ASSERT( data.getComponents().get(0).toString() ==
+                    "tcp://localhost:61616" );
+
 }