This is an automated email from the ASF dual-hosted git repository.
jbertram pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git
The following commit(s) were added to refs/heads/main by this push:
new 604c6d3d90 ARTEMIS-4711 removing the dependency on JMS code by
XmlDataImporter
new 144852b85f This closes #4872
604c6d3d90 is described below
commit 604c6d3d90be437282ce58b33111b48ae193a4cf
Author: Emmanuel Hugonnet <[email protected]>
AuthorDate: Wed Apr 3 11:59:15 2024 +0200
ARTEMIS-4711 removing the dependency on JMS code by XmlDataImporter
Introducing ConnectionConfigurationAbtract to expose the configuration
to connect to a broker without requiring the JMS code.
Signed-off-by: Emmanuel Hugonnet <[email protected]>
---
.../commands/messages/BasicConnectionAbstract.java | 136 +--------------------
...ct.java => ConnectionConfigurationAbtract.java} | 92 ++------------
.../cli/commands/tools/xml/XmlDataImporter.java | 4 +-
3 files changed, 15 insertions(+), 217 deletions(-)
diff --git
a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/BasicConnectionAbstract.java
b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/BasicConnectionAbstract.java
index 90eab63834..7ed9b1ac62 100644
---
a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/BasicConnectionAbstract.java
+++
b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/BasicConnectionAbstract.java
@@ -22,98 +22,9 @@ import javax.jms.JMSException;
import javax.jms.JMSSecurityException;
import org.apache.activemq.artemis.api.core.management.ManagementHelper;
-import org.apache.activemq.artemis.cli.Shell;
-import org.apache.activemq.artemis.cli.commands.ActionContext;
-import org.apache.activemq.artemis.cli.commands.InputAbstract;
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
-import picocli.CommandLine.Option;
-public class BasicConnectionAbstract extends InputAbstract {
- @Option(names = "--url", description = "Connection URL. Default: build URL
from the 'artemis' acceptor defined in the broker.xml or tcp://localhost:61616
if the acceptor cannot be parsed.")
- protected String brokerURL = DEFAULT_BROKER_URL;
-
- @Option(names = "--acceptor", description = "Name used to find the default
connection URL on the acceptor list. If an acceptor with that name cannot be
found the CLI will look for a connector with the same name.")
- protected String acceptor;
-
- @Option(names = "--user", description = "User used to connect.")
- protected String user;
-
- @Option(names = "--password", description = "Password used to connect.")
- protected String password;
-
- protected static ThreadLocal<ConnectionInformation> CONNECTION_INFORMATION
= new ThreadLocal<>();
-
- static class ConnectionInformation {
- String uri, user, password;
-
- private ConnectionInformation(String uri, String user, String password) {
- this.uri = uri;
- this.user = user;
- this.password = password;
- }
- }
-
- public String getBrokerURL() {
- return brokerURL;
- }
-
- public void setBrokerURL(String brokerURL) {
- this.brokerURL = brokerURL;
- }
-
- public String getAcceptor() {
- return acceptor;
- }
-
- public BasicConnectionAbstract setAcceptor(String acceptor) {
- this.acceptor = acceptor;
- return this;
- }
-
- public String getUser() {
- return user;
- }
-
- public BasicConnectionAbstract setUser(String user) {
- this.user = user;
- return this;
- }
-
- public String getPassword() {
- return password;
- }
-
- public BasicConnectionAbstract setPassword(String password) {
- this.password = password;
- return this;
- }
-
- @SuppressWarnings("StringEquality")
- @Override
- public Object execute(ActionContext context) throws Exception {
- super.execute(context);
-
- recoverConnectionInformation();
-
- // it is intentional to make a comparison on the String object here
- // this is to test if the original option was switched or not.
- // we don't care about being .equals at all.
- // as a matter of fact if you pass brokerURL in a way it's equals to
DEFAULT_BROKER_URL,
- // we should not the broker URL Instance
- // and still honor the one passed by parameter.
- // SupressWarnings was added to this method to supress the false
positive here from error-prone.
- if (brokerURL == DEFAULT_BROKER_URL) {
- String brokerURLInstance = getBrokerURLInstance(acceptor);
-
- if (brokerURLInstance != null) {
- brokerURL = brokerURLInstance;
- }
- }
-
- context.out.println("Connection brokerURL = " + brokerURL);
-
- return null;
- }
+public class BasicConnectionAbstract extends ConnectionConfigurationAbtract {
protected ConnectionFactory createConnectionFactory() throws Exception {
recoverConnectionInformation();
@@ -159,31 +70,6 @@ public class BasicConnectionAbstract extends InputAbstract {
}
}
- protected void recoverConnectionInformation() {
- if (CONNECTION_INFORMATION.get() != null) {
- ConnectionInformation connectionInfo = CONNECTION_INFORMATION.get();
- if (this.user == null) {
- this.user = connectionInfo.user;
- }
- if (this.password == null) {
- this.password = connectionInfo.password;
- }
- if (this.brokerURL == null || this.brokerURL == DEFAULT_BROKER_URL) {
- this.brokerURL = connectionInfo.uri;
- }
- }
- }
-
- protected void saveConnectionInfo(String brokerURL, String user, String
password) {
- if (Shell.inShell() && CONNECTION_INFORMATION.get() == null) {
- CONNECTION_INFORMATION.set(new ConnectionInformation(brokerURL, user,
password));
- getActionContext().out.println("CLI connected to broker " + brokerURL
+ ", user:" + user);
- this.brokerURL = brokerURL;
- this.user = user;
- this.password = password;
- }
- }
-
protected void tryConnect(String brokerURL,
String user,
String password,
@@ -193,26 +79,6 @@ public class BasicConnectionAbstract extends InputAbstract {
saveConnectionInfo(brokerURL, user, password);
}
- protected String inputBrokerURL(String defaultValue) {
- return input("--url", "Type in the connection URL for a retry (e.g.
tcp://localhost:61616)", defaultValue);
- }
-
- protected String inputUser(String user) {
- if (user == null) {
- this.user = input("--user", "Type the username for a retry", null);
- return this.user;
- }
- return user;
- }
-
- protected String inputPassword(String password) {
- if (password == null) {
- this.password = inputPassword("--password", "Type the password for a
retry", null);
- return this.password;
- }
- return password;
- }
-
protected void performCoreManagement(ManagementHelper.MessageAcceptor
setup, ManagementHelper.MessageAcceptor ok, ManagementHelper.MessageAcceptor
failed) throws Exception {
try (ActiveMQConnectionFactory factory = (ActiveMQConnectionFactory)
createConnectionFactory()) {
ManagementHelper.doManagement(factory.getServerLocator(), user,
password, setup, ok, failed);
diff --git
a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/BasicConnectionAbstract.java
b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/ConnectionConfigurationAbtract.java
similarity index 53%
copy from
artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/BasicConnectionAbstract.java
copy to
artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/ConnectionConfigurationAbtract.java
index 90eab63834..9d6dd1cb85 100644
---
a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/BasicConnectionAbstract.java
+++
b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/ConnectionConfigurationAbtract.java
@@ -16,29 +16,24 @@
*/
package org.apache.activemq.artemis.cli.commands.messages;
-import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
-import javax.jms.JMSException;
-import javax.jms.JMSSecurityException;
+import static
org.apache.activemq.artemis.cli.commands.ActionAbstract.DEFAULT_BROKER_URL;
-import org.apache.activemq.artemis.api.core.management.ManagementHelper;
import org.apache.activemq.artemis.cli.Shell;
import org.apache.activemq.artemis.cli.commands.ActionContext;
import org.apache.activemq.artemis.cli.commands.InputAbstract;
-import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
-import picocli.CommandLine.Option;
+import picocli.CommandLine;
-public class BasicConnectionAbstract extends InputAbstract {
- @Option(names = "--url", description = "Connection URL. Default: build URL
from the 'artemis' acceptor defined in the broker.xml or tcp://localhost:61616
if the acceptor cannot be parsed.")
+public class ConnectionConfigurationAbtract extends InputAbstract {
+ @CommandLine.Option(names = "--url", description = "Connection URL.
Default: build URL from the 'artemis' acceptor defined in the broker.xml or
tcp://localhost:61616 if the acceptor cannot be parsed.")
protected String brokerURL = DEFAULT_BROKER_URL;
- @Option(names = "--acceptor", description = "Name used to find the default
connection URL on the acceptor list. If an acceptor with that name cannot be
found the CLI will look for a connector with the same name.")
+ @CommandLine.Option(names = "--acceptor", description = "Name used to find
the default connection URL on the acceptor list. If an acceptor with that name
cannot be found the CLI will look for a connector with the same name.")
protected String acceptor;
- @Option(names = "--user", description = "User used to connect.")
+ @CommandLine.Option(names = "--user", description = "User used to connect.")
protected String user;
- @Option(names = "--password", description = "Password used to connect.")
+ @CommandLine.Option(names = "--password", description = "Password used to
connect.")
protected String password;
protected static ThreadLocal<ConnectionInformation> CONNECTION_INFORMATION
= new ThreadLocal<>();
@@ -65,7 +60,7 @@ public class BasicConnectionAbstract extends InputAbstract {
return acceptor;
}
- public BasicConnectionAbstract setAcceptor(String acceptor) {
+ public ConnectionConfigurationAbtract setAcceptor(String acceptor) {
this.acceptor = acceptor;
return this;
}
@@ -74,7 +69,7 @@ public class BasicConnectionAbstract extends InputAbstract {
return user;
}
- public BasicConnectionAbstract setUser(String user) {
+ public ConnectionConfigurationAbtract setUser(String user) {
this.user = user;
return this;
}
@@ -83,7 +78,7 @@ public class BasicConnectionAbstract extends InputAbstract {
return password;
}
- public BasicConnectionAbstract setPassword(String password) {
+ public ConnectionConfigurationAbtract setPassword(String password) {
this.password = password;
return this;
}
@@ -115,50 +110,6 @@ public class BasicConnectionAbstract extends InputAbstract
{
return null;
}
- protected ConnectionFactory createConnectionFactory() throws Exception {
- recoverConnectionInformation();
- return createConnectionFactory(brokerURL, user, password);
- }
-
- protected ConnectionFactory createConnectionFactory(String brokerURL,
- String user,
- String
password) throws Exception {
- recoverConnectionInformation();
-
- ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory(brokerURL,
user, password);
- try {
- tryConnect(brokerURL, user, password, cf);
- return cf;
- } catch (JMSSecurityException e) {
- // if a security exception will get the user and password through an
input
- if (getActionContext() != null) {
- getActionContext().err.println("Connection failed::" +
e.getMessage());
- }
- user = inputUser(user);
- password = inputPassword(password);
- cf = new ActiveMQConnectionFactory(brokerURL, user, password);
- try {
- tryConnect(brokerURL, user, password, cf);
- } catch (Exception e2) {
- }
- return cf;
- } catch (JMSException e) {
- // if a connection exception will ask for the URL, user and password
- if (getActionContext() != null) {
- getActionContext().err.println("Connection failed::" +
e.getMessage());
- }
- brokerURL = inputBrokerURL(brokerURL);
- user = inputUser(user);
- password = inputPassword(password);
- cf = new ActiveMQConnectionFactory(brokerURL, user, password);
- try {
- tryConnect(brokerURL, user, password, cf);
- } catch (Exception e2) {
- }
- return cf;
- }
- }
-
protected void recoverConnectionInformation() {
if (CONNECTION_INFORMATION.get() != null) {
ConnectionInformation connectionInfo = CONNECTION_INFORMATION.get();
@@ -184,19 +135,12 @@ public class BasicConnectionAbstract extends
InputAbstract {
}
}
- protected void tryConnect(String brokerURL,
- String user,
- String password,
- ConnectionFactory cf) throws JMSException {
- Connection connection = cf.createConnection();
- connection.close();
- saveConnectionInfo(brokerURL, user, password);
- }
protected String inputBrokerURL(String defaultValue) {
return input("--url", "Type in the connection URL for a retry (e.g.
tcp://localhost:61616)", defaultValue);
}
+
protected String inputUser(String user) {
if (user == null) {
this.user = input("--user", "Type the username for a retry", null);
@@ -212,16 +156,4 @@ public class BasicConnectionAbstract extends InputAbstract
{
}
return password;
}
-
- protected void performCoreManagement(ManagementHelper.MessageAcceptor
setup, ManagementHelper.MessageAcceptor ok, ManagementHelper.MessageAcceptor
failed) throws Exception {
- try (ActiveMQConnectionFactory factory = (ActiveMQConnectionFactory)
createConnectionFactory()) {
- ManagementHelper.doManagement(factory.getServerLocator(), user,
password, setup, ok, failed);
- }
- }
-
- protected void performCoreManagement(String uri, String user, String
password, ManagementHelper.MessageAcceptor setup,
ManagementHelper.MessageAcceptor ok, ManagementHelper.MessageAcceptor failed)
throws Exception {
- try (ActiveMQConnectionFactory factory = (ActiveMQConnectionFactory)
createConnectionFactory(uri, user, password)) {
- ManagementHelper.doManagement(factory.getServerLocator(), user,
password, setup, ok, failed);
- }
- }
-}
\ No newline at end of file
+}
diff --git
a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/xml/XmlDataImporter.java
b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/xml/XmlDataImporter.java
index 1b69640bd5..538faa6dc3 100644
---
a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/xml/XmlDataImporter.java
+++
b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/xml/XmlDataImporter.java
@@ -50,7 +50,7 @@ import
org.apache.activemq.artemis.api.core.client.ServerLocator;
import org.apache.activemq.artemis.api.core.management.ManagementHelper;
import org.apache.activemq.artemis.api.core.management.ResourceNames;
import org.apache.activemq.artemis.cli.commands.ActionContext;
-import
org.apache.activemq.artemis.cli.commands.messages.BasicConnectionAbstract;
+import
org.apache.activemq.artemis.cli.commands.messages.ConnectionConfigurationAbtract;
import org.apache.activemq.artemis.core.filter.impl.FilterImpl;
import org.apache.activemq.artemis.core.protocol.core.impl.PacketImpl;
import
org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnectorFactory;
@@ -69,7 +69,7 @@ import picocli.CommandLine.Option;
* for speed and simplicity.
*/
@Command(name = "imp", description = "Import all message-data using an XML
that could be interpreted by any system.")
-public final class XmlDataImporter extends BasicConnectionAbstract {
+public final class XmlDataImporter extends ConnectionConfigurationAbtract {
private static final Logger logger =
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());