Allow empty path in AMQP URIs to support using the default vhost.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user