Allow empty path in AMQP URIs to support using the default vhost.

This commit is contained in:
Scott Frederick
2015-05-11 17:04:29 -05:00
parent 30c40dd0d8
commit 06b9fd1bb4
2 changed files with 14 additions and 8 deletions

View File

@@ -61,15 +61,14 @@ public class AmqpServiceInfo extends UriBasedServiceInfo {
}
String path = uriInfo.getPath();
if (path == null) {
throw new IllegalArgumentException("Missing virtual host in amqp URI: " + uriInfo);
} else {
if (path != null) {
// Check that the path only has a single segment. As we have an authority component
// in the URI, paths always begin with a slash.
if (path.indexOf('/') != -1) {
throw new IllegalArgumentException("Multiple segments in path of amqp URI: " + uriInfo);
}
}
return uriInfo;
}
}

View File

@@ -1,6 +1,7 @@
package org.springframework.cloud.service.rabbit;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import org.junit.Test;
import org.springframework.cloud.service.common.AmqpServiceInfo;
@@ -22,6 +23,17 @@ public class RabbitServiceInfoTest {
assertEquals("myvhost", serviceInfo.getVirtualHost());
}
@Test
public void uriBasedParsingDefaultVhost() {
AmqpServiceInfo serviceInfo = new AmqpServiceInfo("id", "amqp://myuser:mypass@myhost:12345/");
assertEquals("myhost", serviceInfo.getHost());
assertEquals(12345, serviceInfo.getPort());
assertEquals("myuser", serviceInfo.getUserName());
assertEquals("mypass", serviceInfo.getPassword());
assertNull(serviceInfo.getVirtualHost());
}
@Test(expected=IllegalArgumentException.class)
public void missingScheme() {
new AmqpServiceInfo("id", "://myuser:mypass@:12345/myvhost");
@@ -48,11 +60,6 @@ public class RabbitServiceInfoTest {
new AmqpServiceInfo("id", "amqp://myhost:12345/myvhost");
}
@Test(expected=IllegalArgumentException.class)
public void missingVirtualHost() {
new AmqpServiceInfo("id", "amqp://myuser:mypass@myhost:12345");
}
@Test(expected=IllegalArgumentException.class)
public void badVirtualHost() {
new AmqpServiceInfo("id", "amqp://myuser:mypass@myhost:12345/a/b");