mirror of https://github.com/apache/activemq.git
https://issues.apache.org/activemq/browse/AMQ-2598 - URISupport.parseParameters() now supports composite urls
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@984826 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
317bee8f6f
commit
784b93df4d
|
@ -327,7 +327,7 @@ public class BrokerService implements Service {
|
|||
public NetworkConnector addNetworkConnector(NetworkConnector connector) throws Exception {
|
||||
connector.setBrokerService(this);
|
||||
URI uri = getVmConnectorURI();
|
||||
Map<String, String> map = new HashMap<String, String>(URISupport.parseParamters(uri));
|
||||
Map<String, String> map = new HashMap<String, String>(URISupport.parseParameters(uri));
|
||||
map.put("network", "true");
|
||||
uri = URISupport.createURIWithQuery(uri, URISupport.createQueryString(map));
|
||||
connector.setLocalUri(uri);
|
||||
|
@ -2065,7 +2065,7 @@ public class BrokerService implements Service {
|
|||
setTransportConnectors(al);
|
||||
}
|
||||
URI uri = getVmConnectorURI();
|
||||
Map<String, String> map = new HashMap<String, String>(URISupport.parseParamters(uri));
|
||||
Map<String, String> map = new HashMap<String, String>(URISupport.parseParameters(uri));
|
||||
map.put("network", "true");
|
||||
map.put("async", "false");
|
||||
uri = URISupport.createURIWithQuery(uri, URISupport.createQueryString(map));
|
||||
|
|
|
@ -1201,7 +1201,7 @@ public class TransportConnection implements Connection, Task, CommandVisitor {
|
|||
IntrospectionSupport.setProperties(config, props, "");
|
||||
config.setBrokerName(broker.getBrokerName());
|
||||
URI uri = broker.getVmConnectorURI();
|
||||
HashMap<String, String> map = new HashMap<String, String>(URISupport.parseParamters(uri));
|
||||
HashMap<String, String> map = new HashMap<String, String>(URISupport.parseParameters(uri));
|
||||
map.put("network", "true");
|
||||
map.put("async", "false");
|
||||
uri = URISupport.createURIWithQuery(uri, URISupport.createQueryString(map));
|
||||
|
|
|
@ -63,12 +63,7 @@ public class DiscoveryNetworkConnector extends NetworkConnector implements Disco
|
|||
public void setUri(URI discoveryURI) throws IOException {
|
||||
setDiscoveryAgent(DiscoveryAgentFactory.createDiscoveryAgent(discoveryURI));
|
||||
try {
|
||||
CompositeData data = URISupport.parseComposite(discoveryURI);
|
||||
parameters = new HashMap<String, String>();
|
||||
parameters.putAll(data.getParameters());
|
||||
for (URI uri : data.getComponents()) {
|
||||
parameters.putAll(URISupport.parseParamters(uri));
|
||||
}
|
||||
parameters = URISupport.parseParameters(discoveryURI);
|
||||
// allow discovery agent to grab it's parameters
|
||||
IntrospectionSupport.setProperties(getDiscoveryAgent(), parameters);
|
||||
} catch (URISyntaxException e) {
|
||||
|
@ -102,6 +97,7 @@ public class DiscoveryNetworkConnector extends NetworkConnector implements Disco
|
|||
}
|
||||
URI connectUri = uri;
|
||||
try {
|
||||
connectUri = URISupport.removeQuery(connectUri);
|
||||
connectUri = URISupport.applyParameters(connectUri, parameters);
|
||||
} catch (URISyntaxException e) {
|
||||
LOG.warn("could not apply query parameters: " + parameters + " to: " + connectUri, e);
|
||||
|
|
|
@ -136,7 +136,7 @@ public abstract class TransportFactory {
|
|||
|
||||
public Transport doConnect(URI location) throws Exception {
|
||||
try {
|
||||
Map<String, String> options = new HashMap<String, String>(URISupport.parseParamters(location));
|
||||
Map<String, String> options = new HashMap<String, String>(URISupport.parseParameters(location));
|
||||
WireFormat wf = createWireFormat(options);
|
||||
Transport transport = createTransport(location, wf);
|
||||
Transport rc = configure(transport, wf, options);
|
||||
|
@ -151,7 +151,7 @@ public abstract class TransportFactory {
|
|||
|
||||
public Transport doCompositeConnect(URI location) throws Exception {
|
||||
try {
|
||||
Map<String, String> options = new HashMap<String, String>(URISupport.parseParamters(location));
|
||||
Map<String, String> options = new HashMap<String, String>(URISupport.parseParameters(location));
|
||||
WireFormat wf = createWireFormat(options);
|
||||
Transport transport = createTransport(location, wf);
|
||||
Transport rc = compositeConfigure(transport, wf, options);
|
||||
|
|
|
@ -46,7 +46,7 @@ public class MulticastDiscoveryAgentFactory extends DiscoveryAgentFactory {
|
|||
|
||||
// allow MDA's params to be set via query arguments
|
||||
// (e.g., multicast://default?group=foo
|
||||
Map options = URISupport.parseParamters(uri);
|
||||
Map options = URISupport.parseParameters(uri);
|
||||
IntrospectionSupport.setProperties(mda, options);
|
||||
|
||||
return mda;
|
||||
|
|
|
@ -30,7 +30,7 @@ public class RendezvousDiscoveryAgentFactory extends DiscoveryAgentFactory {
|
|||
|
||||
protected DiscoveryAgent doCreateDiscoveryAgent(URI uri) throws IOException {
|
||||
try {
|
||||
Map options = URISupport.parseParamters(uri);
|
||||
Map options = URISupport.parseParameters(uri);
|
||||
RendezvousDiscoveryAgent rc = new RendezvousDiscoveryAgent();
|
||||
rc.setGroup(uri.getHost());
|
||||
IntrospectionSupport.setProperties(rc, options);
|
||||
|
|
|
@ -69,7 +69,7 @@ public class PeerTransportFactory extends TransportFactory {
|
|||
broker = ID_GENERATOR.generateSanitizedId();
|
||||
}
|
||||
|
||||
final Map<String, String> brokerOptions = new HashMap<String, String>(URISupport.parseParamters(location));
|
||||
final Map<String, String> brokerOptions = new HashMap<String, String>(URISupport.parseParameters(location));
|
||||
if (!brokerOptions.containsKey("persistent")) {
|
||||
brokerOptions.put("persistent", "false");
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ public class SslTransportFactory extends TcpTransportFactory {
|
|||
*/
|
||||
public TransportServer doBind(final URI location) throws IOException {
|
||||
try {
|
||||
Map<String, String> options = new HashMap<String, String>(URISupport.parseParamters(location));
|
||||
Map<String, String> options = new HashMap<String, String>(URISupport.parseParameters(location));
|
||||
|
||||
ServerSocketFactory serverSocketFactory = createServerSocketFactory();
|
||||
SslTransportServer server = new SslTransportServer(this, location, (SSLServerSocketFactory)serverSocketFactory);
|
||||
|
|
|
@ -49,7 +49,7 @@ public class TcpTransportFactory extends TransportFactory {
|
|||
|
||||
public TransportServer doBind(final URI location) throws IOException {
|
||||
try {
|
||||
Map<String, String> options = new HashMap<String, String>(URISupport.parseParamters(location));
|
||||
Map<String, String> options = new HashMap<String, String>(URISupport.parseParameters(location));
|
||||
|
||||
ServerSocketFactory serverSocketFactory = createServerSocketFactory();
|
||||
TcpTransportServer server = createTcpTransportServer(location, serverSocketFactory);
|
||||
|
|
|
@ -53,7 +53,7 @@ public class UdpTransportFactory extends TransportFactory {
|
|||
|
||||
public TransportServer doBind(final URI location) throws IOException {
|
||||
try {
|
||||
Map<String, String> options = new HashMap<String, String>(URISupport.parseParamters(location));
|
||||
Map<String, String> options = new HashMap<String, String>(URISupport.parseParameters(location));
|
||||
if (options.containsKey("port")) {
|
||||
throw new IllegalArgumentException("The port property cannot be specified on a UDP server transport - please use the port in the URI syntax");
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ public class VMTransportFactory extends TransportFactory {
|
|||
// form
|
||||
try {
|
||||
host = extractHost(location);
|
||||
options = URISupport.parseParamters(location);
|
||||
options = URISupport.parseParameters(location);
|
||||
String config = (String)options.remove("brokerConfig");
|
||||
if (config != null) {
|
||||
brokerURI = new URI(config);
|
||||
|
|
|
@ -124,8 +124,21 @@ public class URISupport {
|
|||
}
|
||||
}
|
||||
|
||||
public static Map<String, String> parseParamters(URI uri) throws URISyntaxException {
|
||||
public static Map<String, String> parseParameters(URI uri) throws URISyntaxException {
|
||||
if (uri.getQuery() != null) {
|
||||
return uri.getQuery() == null ? emptyMap() : parseQuery(stripPrefix(uri.getQuery(), "?"));
|
||||
} else {
|
||||
CompositeData data = URISupport.parseComposite(uri);
|
||||
Map<String, String> parameters = new HashMap<String, String>();
|
||||
parameters.putAll(data.getParameters());
|
||||
for (URI component : data.getComponents()) {
|
||||
parameters.putAll(component.getQuery() == null ? emptyMap() : parseQuery(stripPrefix(component.getQuery(), "?")));
|
||||
}
|
||||
if (parameters.isEmpty())
|
||||
parameters = emptyMap();
|
||||
|
||||
return parameters;
|
||||
}
|
||||
}
|
||||
|
||||
public static URI applyParameters(URI uri, Map<String, String> queryParameters) throws URISyntaxException {
|
||||
|
|
|
@ -131,7 +131,7 @@ public class DiscoveryTransportNoBrokerTest extends CombinationTestSupport {
|
|||
assertEquals("expected added URI after discovery event", compositeTransport.getTransportURIs().length, 1);
|
||||
|
||||
URI discoveredServiceURI = compositeTransport.getTransportURIs()[0];
|
||||
Map<String, String> parameters = URISupport.parseParamters(discoveredServiceURI);
|
||||
Map<String, String> parameters = URISupport.parseParameters(discoveredServiceURI);
|
||||
assertTrue("unable to add parameter to discovered service", parameters.containsKey(extraParameterName));
|
||||
assertEquals("incorrect value for parameter added to discovered service", parameters.get(extraParameterName), extraParameterValue);
|
||||
}
|
||||
|
|
|
@ -80,7 +80,7 @@ public class TcpFaultyTransportFactory extends TcpTransportFactory {
|
|||
|
||||
public TransportServer doBind(final URI location) throws IOException {
|
||||
try {
|
||||
Map<String, String> options = new HashMap<String, String>(URISupport.parseParamters(location));
|
||||
Map<String, String> options = new HashMap<String, String>(URISupport.parseParameters(location));
|
||||
|
||||
ServerSocketFactory serverSocketFactory = createServerSocketFactory();
|
||||
TcpFaultyTransportServer server = createTcpFaultyTransportServer(location, serverSocketFactory);
|
||||
|
|
|
@ -56,7 +56,7 @@ public class URISupportTest extends TestCase {
|
|||
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.parseParamters(data.getComponents()[0]);
|
||||
Map part1Params = URISupport.parseParameters(data.getComponents()[0]);
|
||||
assertEquals(1, part1Params.size());
|
||||
assertTrue(part1Params.containsKey("part1"));
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ public class URISupportTest extends TestCase {
|
|||
public void testParsingURI() throws Exception {
|
||||
URI source = new URI("tcp://localhost:61626/foo/bar?cheese=Edam&x=123");
|
||||
|
||||
Map map = URISupport.parseParamters(source);
|
||||
Map map = URISupport.parseParameters(source);
|
||||
|
||||
assertEquals("Size: " + map, 2, map.size());
|
||||
assertMapKey(map, "cheese", "Edam");
|
||||
|
@ -96,10 +96,24 @@ public class URISupportTest extends TestCase {
|
|||
URI source = new URI("vm://localhost");
|
||||
URI dest = URISupport.createURIWithQuery(source, "network=true&one=two");
|
||||
|
||||
assertEquals("correct param count", 2, URISupport.parseParamters(dest).size());
|
||||
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=localhost&proxyPort=80)");
|
||||
Map<String,String>parameters = URISupport.parseParameters(uri);
|
||||
verifyParams(parameters);
|
||||
uri = new URI("static://http://localhost:61617?proxyHost=localhost&proxyPort=80");
|
||||
parameters = URISupport.parseParameters(uri);
|
||||
verifyParams(parameters);
|
||||
}
|
||||
|
||||
private void verifyParams(Map<String,String> parameters) {
|
||||
assertEquals(parameters.get("proxyHost"), "localhost");
|
||||
assertEquals(parameters.get("proxyPort"), "80");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ public class HTTPDiscoveryAgentFactory extends DiscoveryAgentFactory {
|
|||
protected DiscoveryAgent doCreateDiscoveryAgent(URI uri) throws IOException {
|
||||
try {
|
||||
|
||||
Map options = URISupport.parseParamters(uri);
|
||||
Map options = URISupport.parseParameters(uri);
|
||||
uri = URISupport.removeQuery(uri);
|
||||
|
||||
HTTPDiscoveryAgent rc = new HTTPDiscoveryAgent();
|
||||
|
|
Loading…
Reference in New Issue