git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1367620 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Timothy A. Bish 2012-07-31 15:43:59 +00:00
parent c9b49d8b07
commit 79bce92c33
2 changed files with 37 additions and 10 deletions

View File

@ -205,18 +205,12 @@ public class URISupport {
} }
public static boolean isCompositeURI(URI uri) { public static boolean isCompositeURI(URI uri) {
if (uri.getQuery() != null) { String ssp = stripPrefix(uri.getRawSchemeSpecificPart().trim(), "//").trim();
return false;
} else { if (ssp.indexOf('(') == 0 && checkParenthesis(ssp)) {
String ssp = stripPrefix(uri.getRawSchemeSpecificPart().trim(), "(").trim();
ssp = stripPrefix(ssp, "//").trim();
try {
new URI(ssp);
} catch (URISyntaxException e) {
return false;
}
return true; return true;
} }
return false;
} }
public static int indexOfParenthesisMatch(String str, int first) throws URISyntaxException { public static int indexOfParenthesisMatch(String str, int first) throws URISyntaxException {

View File

@ -178,4 +178,37 @@ public class URISupportTest extends TestCase {
assertEquals(parameters.get("proxyPort"), "80"); assertEquals(parameters.get("proxyPort"), "80");
} }
public void testIsCompositeURIWithQueryNoSlashes() throws URISyntaxException {
URI[] compositeURIs = new URI[] { new URI("test:(part1://host?part1=true)?outside=true"), new URI("broker:(tcp://localhost:61616)?name=foo") };
for (URI uri : compositeURIs) {
assertTrue(uri + " must be detected as composite URI", URISupport.isCompositeURI(uri));
}
}
public void testIsCompositeURIWithQueryAndSlashes() throws URISyntaxException {
URI[] compositeURIs = new URI[] { new URI("test://(part1://host?part1=true)?outside=true"), new URI("broker://(tcp://localhost:61616)?name=foo") };
for (URI uri : compositeURIs) {
assertTrue(uri + " must be detected as composite URI", URISupport.isCompositeURI(uri));
}
}
public void testIsCompositeURINoQueryNoSlashes() throws URISyntaxException {
URI[] compositeURIs = new URI[] { new URI("test:(part1://host,part2://(sub1://part,sube2:part))"), new URI("test:(path)/path") };
for (URI uri : compositeURIs) {
assertTrue(uri + " must be detected as composite URI", URISupport.isCompositeURI(uri));
}
}
public void testIsCompositeURINoQueryNoSlashesNoParentheses() throws URISyntaxException {
assertFalse("test:part1" + " must be detected as non-composite URI", URISupport.isCompositeURI(new URI("test:part1")));
}
public void testIsCompositeURINoQueryWithSlashes() throws URISyntaxException {
URI[] compositeURIs = new URI[] { new URI("failover://(tcp://bla:61616,tcp://bla:61617)"),
new URI("failover://(tcp://localhost:61616,ssl://anotherhost:61617)") };
for (URI uri : compositeURIs) {
assertTrue(uri + " must be detected as composite URI", URISupport.isCompositeURI(uri));
}
}
} }