activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r1349527 - in /activemq/trunk/activemq-core/src: main/java/org/apache/activemq/util/URISupport.java test/java/org/apache/activemq/util/URISupportTest.java
Date Tue, 12 Jun 2012 21:09:37 GMT
Author: tabish
Date: Tue Jun 12 21:09:37 2012
New Revision: 1349527

URL: http://svn.apache.org/viewvc?rev=1349527&view=rev
Log:
fix for: https://issues.apache.org/jira/browse/AMQ-3828

Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/URISupport.java
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/util/URISupportTest.java

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/URISupport.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/URISupport.java?rev=1349527&r1=1349526&r2=1349527&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/URISupport.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/URISupport.java Tue
Jun 12 21:09:37 2012
@@ -219,6 +219,37 @@ public class URISupport {
         }
     }
 
+    public static int indexOfParenthesisMatch(String str, int first) throws URISyntaxException
{
+        int index = -1;
+
+        if (first < 0 || first > str.length()) {
+            throw new IllegalArgumentException("Invalid position for first parenthesis: "
+ first);
+        }
+
+        if (str.charAt(first) != '(') {
+            throw new IllegalArgumentException("character at indicated position is not a
parenthesis");
+        }
+
+        int depth = 1;
+        char[] array = str.toCharArray();
+        for (index = first + 1; index < array.length; ++index) {
+            char current = array[index];
+            if (current == '(') {
+                depth++;
+            } else if (current == ')') {
+                if (--depth == 0) {
+                    break;
+                }
+            }
+        }
+
+        if (depth != 0) {
+            throw new URISyntaxException(str, "URI did not contain a matching parenthesis.");
+        }
+
+        return index;
+    }
+
     /**
      * @param uri
      * @param rc
@@ -234,16 +265,19 @@ public class URISupport {
         }
 
         int p;
-        int intialParen = ssp.indexOf("(");
-        if (intialParen == 0) {
-            rc.host = ssp.substring(0, intialParen);
+        int initialParen = ssp.indexOf("(");
+        if (initialParen == 0) {
+
+            rc.host = ssp.substring(0, initialParen);
             p = rc.host.indexOf("/");
+
             if (p >= 0) {
                 rc.path = rc.host.substring(p);
                 rc.host = rc.host.substring(0, p);
             }
-            p = ssp.lastIndexOf(")");
-            componentString = ssp.substring(intialParen + 1, p);
+
+            p = indexOfParenthesisMatch(ssp, initialParen);
+            componentString = ssp.substring(initialParen + 1, p);
             params = ssp.substring(p + 1).trim();
 
         } else {
@@ -364,6 +398,7 @@ public class URISupport {
             .getPath(), bindAddr.getQuery(), bindAddr.getFragment());
     }
 
+
     public static boolean checkParenthesis(String str) {
         boolean result = true;
         if (str != null) {
@@ -384,11 +419,4 @@ public class URISupport {
         }
         return result;
     }
-
-    public int indexOfParenthesisMatch(String str) {
-        int result = -1;
-
-        return result;
-    }
-
 }

Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/util/URISupportTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/util/URISupportTest.java?rev=1349527&r1=1349526&r2=1349527&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/util/URISupportTest.java
(original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/util/URISupportTest.java
Tue Jun 12 21:09:37 2012
@@ -22,22 +22,19 @@ import java.util.HashMap;
 import java.util.Map;
 
 import junit.framework.TestCase;
+
 import org.apache.activemq.util.URISupport.CompositeData;
 
-/**
- *
- * 
- */
 public class URISupportTest extends TestCase {
-    
+
     public void testEmptyCompositePath() throws Exception {
         CompositeData data = URISupport.parseComposite(new URI("broker:()/localhost?persistent=false"));
-        assertEquals(0, data.getComponents().length);        
+        assertEquals(0, data.getComponents().length);
     }
-            
+
     public void testCompositePath() throws Exception {
         CompositeData data = URISupport.parseComposite(new URI("test:(path)/path"));
-        assertEquals("path", data.getPath());        
+        assertEquals("path", data.getPath());
         data = URISupport.parseComposite(new URI("test:path"));
         assertNull(data.getPath());
     }
@@ -48,61 +45,79 @@ public class URISupportTest extends Test
     }
 
     public void testComposite() throws Exception {
-        CompositeData data = URISupport.parseComposite(new URI("test:(part1://host,part2://(sub1://part,sube2:part))"));
+        URI uri = new URI("test:(part1://host,part2://(sub1://part,sube2:part))");
+        CompositeData data = URISupport.parseComposite(uri);
         assertEquals(2, data.getComponents().length);
     }
 
-    
+    public void testEmptyCompositeWithParenthesisInParam() throws Exception {
+        URI uri = new URI("failover://()?updateURIsURL=file:/C:/Dir(1)/a.csv");
+        CompositeData data = URISupport.parseComposite(uri);
+        assertEquals(0, data.getComponents().length);
+        assertEquals(1, data.getParameters().size());
+        assertTrue(data.getParameters().containsKey("updateURIsURL"));
+        assertEquals("file:/C:/Dir(1)/a.csv", data.getParameters().get("updateURIsURL"));
+    }
+
+    public void testCompositeWithParenthesisInParam() throws Exception {
+        URI uri = new URI("failover://(test)?updateURIsURL=file:/C:/Dir(1)/a.csv");
+        CompositeData data = URISupport.parseComposite(uri);
+        assertEquals(1, data.getComponents().length);
+        assertEquals(1, data.getParameters().size());
+        assertTrue(data.getParameters().containsKey("updateURIsURL"));
+        assertEquals("file:/C:/Dir(1)/a.csv", data.getParameters().get("updateURIsURL"));
+    }
+
     public void testCompositeWithComponentParam() throws Exception {
         CompositeData data = URISupport.parseComposite(new URI("test:(part1://host?part1=true)?outside=true"));
         assertEquals(1, data.getComponents().length);
         assertEquals(1, data.getParameters().size());
-        Map part1Params = URISupport.parseParameters(data.getComponents()[0]);
+        Map<String, String> part1Params = URISupport.parseParameters(data.getComponents()[0]);
         assertEquals(1, part1Params.size());
         assertTrue(part1Params.containsKey("part1"));
     }
-    
+
     public void testParsingURI() throws Exception {
         URI source = new URI("tcp://localhost:61626/foo/bar?cheese=Edam&x=123");
-        
-        Map map = URISupport.parseParameters(source);
-    
+
+        Map<String, String> map = URISupport.parseParameters(source);
+
         assertEquals("Size: " + map, 2, map.size());
         assertMapKey(map, "cheese", "Edam");
         assertMapKey(map, "x", "123");
-        
+
         URI result = URISupport.removeQuery(source);
-        
+
         assertEquals("result", new URI("tcp://localhost:61626/foo/bar"), result);
     }
-    
-    protected void assertMapKey(Map map, String key, Object expected) {
+
+    protected void assertMapKey(Map<String, String> map, String key, Object expected)
{
         assertEquals("Map key: " + key, map.get(key), expected);
     }
-    
+
     public void testParsingCompositeURI() throws URISyntaxException {
         CompositeData data = URISupport.parseComposite(new URI("broker://(tcp://localhost:61616)?name=foo"));
         assertEquals("one component", 1, data.getComponents().length);
         assertEquals("Size: " + data.getParameters(), 1, data.getParameters().size());
     }
-    
+
     public void testCheckParenthesis() throws Exception {
         String str = "fred:(((ddd))";
         assertFalse(URISupport.checkParenthesis(str));
         str += ")";
         assertTrue(URISupport.checkParenthesis(str));
     }
-    
+
     public void testCreateWithQuery() throws Exception {
         URI source = new URI("vm://localhost");
         URI dest = URISupport.createURIWithQuery(source, "network=true&one=two");
-        
+
         assertEquals("correct param count", 2, URISupport.parseParameters(dest).size());
         assertEquals("same uri, host", source.getHost(), dest.getHost());
         assertEquals("same uri, scheme", source.getScheme(), dest.getScheme());
         assertFalse("same uri, ssp", dest.getQuery().equals(source.getQuery()));
     }
-    
+
     public void testParsingParams() throws Exception {
         URI uri = new URI("static:(http://localhost:61617?proxyHost=jo&proxyPort=90)?proxyHost=localhost&proxyPort=80");
         Map<String,String>parameters = URISupport.parseParameters(uri);
@@ -113,27 +128,27 @@ public class URISupportTest extends Test
         uri = new URI("http://0.0.0.0:61616");
         parameters = URISupport.parseParameters(uri);
     }
-    
+
     public void testCompositeCreateURIWithQuery() throws Exception {
-    	String queryString = "query=value";
-    	URI originalURI = new URI("outerscheme:(innerscheme:innerssp)");
-    	URI querylessURI = originalURI;
-    	assertEquals(querylessURI, URISupport.createURIWithQuery(originalURI, null));
-    	assertEquals(querylessURI, URISupport.createURIWithQuery(originalURI, ""));
-    	assertEquals(new URI(querylessURI + "?" + queryString), URISupport.createURIWithQuery(originalURI,
queryString));
-    	originalURI = new URI("outerscheme:(innerscheme:innerssp)?outerquery=0");
-    	assertEquals(querylessURI, URISupport.createURIWithQuery(originalURI, null));
-    	assertEquals(querylessURI, URISupport.createURIWithQuery(originalURI, ""));
-    	assertEquals(new URI(querylessURI + "?" + queryString), URISupport.createURIWithQuery(originalURI,
queryString));
-    	originalURI = new URI("outerscheme:(innerscheme:innerssp?innerquery=0)");
-    	querylessURI = originalURI;
-    	assertEquals(querylessURI, URISupport.createURIWithQuery(originalURI, null));
-    	assertEquals(querylessURI, URISupport.createURIWithQuery(originalURI, ""));
-    	assertEquals(new URI(querylessURI + "?" + queryString), URISupport.createURIWithQuery(originalURI,
queryString));
-    	originalURI = new URI("outerscheme:(innerscheme:innerssp?innerquery=0)?outerquery=0");
-    	assertEquals(querylessURI, URISupport.createURIWithQuery(originalURI, null));
-    	assertEquals(querylessURI, URISupport.createURIWithQuery(originalURI, ""));
-    	assertEquals(new URI(querylessURI + "?" + queryString), URISupport.createURIWithQuery(originalURI,
queryString));
+        String queryString = "query=value";
+        URI originalURI = new URI("outerscheme:(innerscheme:innerssp)");
+        URI querylessURI = originalURI;
+        assertEquals(querylessURI, URISupport.createURIWithQuery(originalURI, null));
+        assertEquals(querylessURI, URISupport.createURIWithQuery(originalURI, ""));
+        assertEquals(new URI(querylessURI + "?" + queryString), URISupport.createURIWithQuery(originalURI,
queryString));
+        originalURI = new URI("outerscheme:(innerscheme:innerssp)?outerquery=0");
+        assertEquals(querylessURI, URISupport.createURIWithQuery(originalURI, null));
+        assertEquals(querylessURI, URISupport.createURIWithQuery(originalURI, ""));
+        assertEquals(new URI(querylessURI + "?" + queryString), URISupport.createURIWithQuery(originalURI,
queryString));
+        originalURI = new URI("outerscheme:(innerscheme:innerssp?innerquery=0)");
+        querylessURI = originalURI;
+        assertEquals(querylessURI, URISupport.createURIWithQuery(originalURI, null));
+        assertEquals(querylessURI, URISupport.createURIWithQuery(originalURI, ""));
+        assertEquals(new URI(querylessURI + "?" + queryString), URISupport.createURIWithQuery(originalURI,
queryString));
+        originalURI = new URI("outerscheme:(innerscheme:innerssp?innerquery=0)?outerquery=0");
+        assertEquals(querylessURI, URISupport.createURIWithQuery(originalURI, null));
+        assertEquals(querylessURI, URISupport.createURIWithQuery(originalURI, ""));
+        assertEquals(new URI(querylessURI + "?" + queryString), URISupport.createURIWithQuery(originalURI,
queryString));
     }
 
     public void testApplyParameters() throws Exception {
@@ -157,10 +172,10 @@ public class URISupportTest extends Test
         uri = URISupport.applyParameters(uri, parameters, "t.");
         verifyParams(URISupport.parseParameters(uri));
     }
-    
+
     private void verifyParams(Map<String,String> parameters) {
         assertEquals(parameters.get("proxyHost"), "localhost");
         assertEquals(parameters.get("proxyPort"), "80");
     }
-    
+
 }



Mime
View raw message