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 2009/03/03 01:00:06 UTC
svn commit: r749481 - in /activemq/activemq-cpp/trunk/src/main: Makefile.am
activemq/util/CompositeData.cpp activemq/util/CompositeData.h
activemq/util/URISupport.cpp activemq/util/URISupport.h
Author: tabish
Date: Tue Mar 3 00:00:06 2009
New Revision: 749481
URL: http://svn.apache.org/viewvc?rev=749481&view=rev
Log:
http://issues.apache.org/activemq/browse/AMQCPP-100
Add a CompositeData class to house the multiple URI values in a Failover URI and start on adding parsing code in URISupport to handle the Failover URI format.
Added:
activemq/activemq-cpp/trunk/src/main/activemq/util/CompositeData.cpp (with props)
activemq/activemq-cpp/trunk/src/main/activemq/util/CompositeData.h (with props)
Modified:
activemq/activemq-cpp/trunk/src/main/Makefile.am
activemq/activemq-cpp/trunk/src/main/activemq/util/URISupport.cpp
activemq/activemq-cpp/trunk/src/main/activemq/util/URISupport.h
Modified: activemq/activemq-cpp/trunk/src/main/Makefile.am
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/Makefile.am?rev=749481&r1=749480&r2=749481&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/Makefile.am (original)
+++ activemq/activemq-cpp/trunk/src/main/Makefile.am Tue Mar 3 00:00:06 2009
@@ -26,6 +26,7 @@
activemq/util/LongSequenceGenerator.cpp \
activemq/util/URISupport.cpp \
activemq/util/MemoryUsage.cpp \
+ activemq/util/CompositeData.cpp \
activemq/cmsutil/DynamicDestinationResolver.cpp \
activemq/cmsutil/ResourceLifecycleManager.cpp \
activemq/cmsutil/CmsAccessor.cpp \
@@ -228,6 +229,7 @@
activemq/util/URISupport.h \
activemq/util/MemoryUsage.h \
activemq/util/Usage.h \
+ activemq/util/CompositeData.h \
activemq/wireformat/WireFormat.h \
activemq/wireformat/WireFormatNegotiator.h \
activemq/wireformat/WireFormatFactory.h \
Added: activemq/activemq-cpp/trunk/src/main/activemq/util/CompositeData.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/util/CompositeData.cpp?rev=749481&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/util/CompositeData.cpp (added)
+++ activemq/activemq-cpp/trunk/src/main/activemq/util/CompositeData.cpp Tue Mar 3 00:00:06 2009
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "CompositeData.h"
+
+#include <sstream>
+#include <activemq/util/URISupport.h>
+
+using namespace std;
+using namespace activemq;
+using namespace activemq::util;
+using namespace decaf;
+using namespace decaf::net;
+
+////////////////////////////////////////////////////////////////////////////////
+CompositeData::CompositeData() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CompositeData::~CompositeData() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+URI CompositeData::toURI() const throw( decaf::net::URISyntaxException ) {
+
+ ostringstream sb;
+
+ if( scheme != "" ) {
+ sb << scheme << ":";
+ }
+
+ if( host.size() != 0) {
+ sb << host;
+ } else {
+ sb << "(";
+
+ for( std::size_t i = 0; i < components.size(); i++ ) {
+ if( i != 0 ) {
+ sb << ",";
+ }
+ sb << components[i].toString();
+ }
+
+ sb << ")";
+ }
+
+ if( path != "") {
+ sb << "/" << path;
+ }
+
+ if( !parameters.isEmpty() ) {
+ sb << "?" << URISupport::createQueryString( parameters );
+ }
+
+ if( fragment != "" ) {
+ sb << "#" << fragment;
+ }
+
+ return URI( sb.str() );
+}
Propchange: activemq/activemq-cpp/trunk/src/main/activemq/util/CompositeData.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/activemq-cpp/trunk/src/main/activemq/util/CompositeData.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/util/CompositeData.h?rev=749481&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/util/CompositeData.h (added)
+++ activemq/activemq-cpp/trunk/src/main/activemq/util/CompositeData.h Tue Mar 3 00:00:06 2009
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _ACTIVEMQ_UTIL_COMPOSITEDATA_H_
+#define _ACTIVEMQ_UTIL_COMPOSITEDATA_H_
+
+#include <activemq/util/Config.h>
+#include <decaf/util/Properties.h>
+#include <decaf/net/URI.h>
+#include <decaf/net/URISyntaxException.h>
+
+namespace activemq {
+namespace util {
+
+ using decaf::net::URI;
+ using decaf::util::Properties;
+
+ /**
+ * Represents a Composite URI
+ *
+ * @since 3.0
+ */
+ class AMQCPP_API CompositeData {
+ private:
+
+ std::string host;
+ std::string scheme;
+ std::string path;
+ std::vector<URI> components;
+ Properties parameters;
+ std::string fragment;
+
+ public:
+
+ CompositeData();
+ virtual ~CompositeData();
+
+ const std::vector<URI>& getComponents() const {
+ return components;
+ }
+
+ void setComponents( const std::vector<URI>& components ) {
+ this->components = components;
+ }
+
+ std::string getFragment() const {
+ return fragment;
+ }
+
+ void setFragment( const std::string& fragment ) {
+ this->fragment = fragment;
+ }
+
+ const Properties& getParameters() const {
+ return parameters;
+ }
+
+ void setParameters( const Properties& parameters ) {
+ this->parameters = parameters;
+ }
+
+ std::string getScheme() const {
+ return scheme;
+ }
+
+ void setScheme( const std::string& scheme ) {
+ this->scheme = scheme;
+ }
+
+ std::string getPath() const {
+ return path;
+ }
+
+ void setPath( const std::string& path ) {
+ this->path = path;
+ }
+
+ std::string getHost() const {
+ return host;
+ }
+
+ void setHost( const std::string& host ) {
+ this->host = host;
+ }
+
+ URI toURI() const throw( decaf::net::URISyntaxException );
+
+ };
+
+}}
+
+#endif /* _ACTIVEMQ_UTIL_COMPOSITEDATA_H_ */
Propchange: activemq/activemq-cpp/trunk/src/main/activemq/util/CompositeData.h
------------------------------------------------------------------------------
svn:eol-style = native
Modified: activemq/activemq-cpp/trunk/src/main/activemq/util/URISupport.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/util/URISupport.cpp?rev=749481&r1=749480&r2=749481&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/util/URISupport.cpp (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/util/URISupport.cpp Tue Mar 3 00:00:06 2009
@@ -22,11 +22,15 @@
#include <decaf/util/StringTokenizer.h>
#include <decaf/lang/exceptions/IllegalArgumentException.h>
#include <decaf/lang/System.h>
+#include <decaf/net/URLEncoder.h>
+#include <decaf/net/URISyntaxException.h>
+#include <sstream>
using namespace std;
using namespace activemq;
using namespace activemq::util;
using namespace decaf::util;
+using namespace decaf::net;
using namespace decaf::lang;
using namespace decaf::lang::exceptions;
@@ -198,3 +202,38 @@
AMQ_CATCH_EXCEPTION_CONVERT( Exception, IllegalArgumentException )
AMQ_CATCHALL_THROW( IllegalArgumentException )
}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string URISupport::createQueryString( const Properties& options )
+ throw( URISyntaxException ) {
+
+ try {
+
+ if( options.isEmpty() ) {
+
+ ostringstream rc;
+ bool first = true;
+ std::vector< std::pair< std::string, std::string > > values = options.toArray();
+ std::vector< std::pair< std::string, std::string > >::const_iterator iter = values.begin();
+
+ for( ; iter != values.end(); ++iter ) {
+ if( first ) {
+ first = false;
+ } else {
+ rc << "&";
+ }
+
+ rc << URLEncoder::encode( iter->first ) << "="
+ << URLEncoder::encode( iter->second );
+ }
+
+ return rc.str();
+
+ } else {
+ return "";
+ }
+ }
+ AMQ_CATCH_RETHROW( URISyntaxException )
+ AMQ_CATCH_EXCEPTION_CONVERT( Exception, URISyntaxException )
+ AMQ_CATCHALL_THROW( URISyntaxException )
+}
Modified: activemq/activemq-cpp/trunk/src/main/activemq/util/URISupport.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/util/URISupport.h?rev=749481&r1=749480&r2=749481&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/util/URISupport.h (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/util/URISupport.h Tue Mar 3 00:00:06 2009
@@ -19,6 +19,7 @@
#define _ACTIVEMQ_UTIL_URISUPPORT_H_
#include <activemq/util/Config.h>
+#include <activemq/util/CompositeData.h>
#include <decaf/util/Properties.h>
#include <decaf/lang/exceptions/IllegalArgumentException.h>
@@ -60,6 +61,21 @@
decaf::util::Properties* properties )
throw ( decaf::lang::exceptions::IllegalArgumentException );
+ /**
+ * Given a properties object create a string that can be appended to a URI
+ * as a valid Query string.
+ *
+ * @param options
+ * Properties object containing key / value query values.
+ *
+ * @return a valid URI query string.
+ *
+ * @throw URISyntaxException if the string in the Properties object
+ * can't be encoded into a valid URI Query string.
+ */
+ static std::string createQueryString( const Properties& options )
+ throw( decaf::net::URISyntaxException );
+
private:
/**