From 78042ba0e1bfb6be056e1f98ca6d893779a4d3ab Mon Sep 17 00:00:00 2001 From: Clebert Suconic Date: Fri, 9 Dec 2016 12:47:40 -0500 Subject: [PATCH] ARTEMIS-882 Supporting lists on URIs (cherry picked from commit dc472192f41875bd390f3f2f00af0f98b7c08c6c) --- .../api/core/client/ActiveMQClient.java | 2 +- .../core/client/impl/ServerLocatorImpl.java | 4 +- .../serverLocator/TCPServerLocatorSchema.java | 7 +-- .../jms/client/ActiveMQConnectionFactory.java | 2 +- .../tests/integration/jms/URITest.java | 46 +++++++++++++++++++ 5 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/URITest.java diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/client/ActiveMQClient.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/client/ActiveMQClient.java index 0ad80fcb08..a07ef6dd09 100644 --- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/client/ActiveMQClient.java +++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/client/ActiveMQClient.java @@ -289,7 +289,7 @@ public final class ActiveMQClient { */ public static ServerLocator createServerLocator(final String url) throws Exception { ServerLocatorParser parser = new ServerLocatorParser(); - return parser.newObject(new URI(url), null); + return parser.newObject(parser.expandURI(url), null); } /** diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/client/impl/ServerLocatorImpl.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/client/impl/ServerLocatorImpl.java index beb1b13517..949ef90810 100644 --- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/client/impl/ServerLocatorImpl.java +++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/client/impl/ServerLocatorImpl.java @@ -397,7 +397,9 @@ public final class ServerLocatorImpl implements ServerLocatorInternal, Discovery public static ServerLocator newLocator(String uri) { try { - return newLocator(new URI(uri)); + ServerLocatorParser parser = new ServerLocatorParser(); + URI newURI = parser.expandURI(uri); + return parser.newObject(newURI, null); } catch (Exception e) { throw new RuntimeException(e); } diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/uri/schema/serverLocator/TCPServerLocatorSchema.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/uri/schema/serverLocator/TCPServerLocatorSchema.java index 9468a5088a..5a2724ea16 100644 --- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/uri/schema/serverLocator/TCPServerLocatorSchema.java +++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/uri/schema/serverLocator/TCPServerLocatorSchema.java @@ -30,7 +30,8 @@ import org.apache.activemq.artemis.utils.IPV6Util; import org.apache.activemq.artemis.utils.uri.BeanSupport; import org.apache.activemq.artemis.utils.uri.SchemaConstants; -public class TCPServerLocatorSchema extends AbstractServerLocatorSchema { +public class +TCPServerLocatorSchema extends AbstractServerLocatorSchema { @Override public String getSchemaName() { @@ -45,9 +46,9 @@ public class TCPServerLocatorSchema extends AbstractServerLocatorSchema { TransportConfiguration[] tcs = new TransportConfiguration[configurations.size()]; configurations.toArray(tcs); if (options.isHa()) { - return ActiveMQClient.createServerLocatorWithHA(tcs); + return BeanSupport.setData(uri, ActiveMQClient.createServerLocatorWithHA(tcs), query); } else { - return ActiveMQClient.createServerLocatorWithoutHA(tcs); + return BeanSupport.setData(uri, ActiveMQClient.createServerLocatorWithoutHA(tcs), query); } } diff --git a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQConnectionFactory.java b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQConnectionFactory.java index 91dee3cc9b..4d314ce6c6 100644 --- a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQConnectionFactory.java +++ b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQConnectionFactory.java @@ -204,7 +204,7 @@ public class ActiveMQConnectionFactory implements ConnectionFactoryOptions, Exte public ActiveMQConnectionFactory(String url) { ConnectionFactoryParser cfParser = new ConnectionFactoryParser(); try { - URI uri = new URI(url); + URI uri = cfParser.expandURI(url); serverLocator = ServerLocatorImpl.newLocator(uri); cfParser.populateObject(uri, this); } catch (Exception e) { diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/URITest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/URITest.java new file mode 100644 index 0000000000..b66b10b0fc --- /dev/null +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/URITest.java @@ -0,0 +1,46 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.activemq.artemis.tests.integration.jms; + +import org.apache.activemq.artemis.api.core.client.ActiveMQClient; +import org.apache.activemq.artemis.api.core.client.ServerLocator; +import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient; +import org.apache.activemq.artemis.core.client.impl.ServerLocatorImpl; +import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; +import org.junit.Assert; +import org.junit.Test; + +public class URITest { + + @Test + public void testParseURIs() throws Throwable { + ActiveMQConnectionFactory factory = ActiveMQJMSClient.createConnectionFactory("(tcp://localhost:61616,tcp://localhost:61617)?blockOnDurableSend=false", "some name"); + Assert.assertEquals(2, ((ServerLocatorImpl) factory.getServerLocator()).getInitialConnectors().length); + + ActiveMQConnectionFactory factory2 = new ActiveMQConnectionFactory("(tcp://localhost:61614,tcp://localhost:61616)?blockOnDurableSend=false"); + Assert.assertEquals(2, ((ServerLocatorImpl) factory2.getServerLocator()).getInitialConnectors().length); + + ServerLocator locator = ServerLocatorImpl.newLocator("(tcp://localhost:61616,tcp://localhost:61617)?blockOnDurableSend=false"); + Assert.assertEquals(2, ((ServerLocatorImpl) locator).getInitialConnectors().length); + + ServerLocator locator2 = ActiveMQClient.createServerLocator("(tcp://localhost:61616,tcp://localhost:61617)?blockOnDurableSend=false"); + Assert.assertEquals(2, ((ServerLocatorImpl) locator2).getInitialConnectors().length); + + } + +}