You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cl...@apache.org on 2016/11/02 19:53:17 UTC
[4/5] activemq-artemis git commit: NO-JIRA small improvement on CLI,
retry with user input
NO-JIRA small improvement on CLI, retry with user input
Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/aa0965c0
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/aa0965c0
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/aa0965c0
Branch: refs/heads/master
Commit: aa0965c0ca7bab4434645b7ed3672316f943e900
Parents: 119476d
Author: Clebert Suconic <cl...@apache.org>
Authored: Wed Nov 2 15:33:06 2016 -0400
Committer: Clebert Suconic <cl...@apache.org>
Committed: Wed Nov 2 15:52:25 2016 -0400
----------------------------------------------------------------------
.../commands/destination/CreateDestination.java | 6 +-
.../commands/destination/DeleteDestination.java | 6 +-
.../commands/destination/DestinationAction.java | 29 ++-------
.../artemis/cli/commands/messages/Browse.java | 2 +-
.../commands/messages/ConnectionAbstract.java | 68 ++++++++++++++++++++
.../artemis/cli/commands/messages/Consumer.java | 2 +-
.../cli/commands/messages/DestAbstract.java | 12 +---
.../artemis/cli/commands/messages/Producer.java | 2 +-
8 files changed, 85 insertions(+), 42 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/aa0965c0/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/destination/CreateDestination.java
----------------------------------------------------------------------
diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/destination/CreateDestination.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/destination/CreateDestination.java
index a0ae4bf..4cbaaa6 100644
--- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/destination/CreateDestination.java
+++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/destination/CreateDestination.java
@@ -58,7 +58,7 @@ public class CreateDestination extends DestinationAction {
}
private void createJmsTopic(final ActionContext context) throws Exception {
- performJmsManagement(brokerURL, user, password, new ManagementCallback<Message>() {
+ performJmsManagement(new ManagementCallback<Message>() {
@Override
public void setUpInvocation(Message message) throws Exception {
JMSManagementHelper.putOperationInvocation(message, "jms.server", "createTopic", getName(), bindings);
@@ -90,7 +90,7 @@ public class CreateDestination extends DestinationAction {
}
private void createCoreQueue(final ActionContext context) throws Exception {
- performCoreManagement(brokerURL, user, password, new ManagementCallback<ClientMessage>() {
+ performCoreManagement(new ManagementCallback<ClientMessage>() {
@Override
public void setUpInvocation(ClientMessage message) throws Exception {
String address = getAddress();
@@ -112,7 +112,7 @@ public class CreateDestination extends DestinationAction {
private void createJmsQueue(final ActionContext context) throws Exception {
- performJmsManagement(brokerURL, user, password, new ManagementCallback<Message>() {
+ performJmsManagement(new ManagementCallback<Message>() {
@Override
public void setUpInvocation(Message message) throws Exception {
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/aa0965c0/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/destination/DeleteDestination.java
----------------------------------------------------------------------
diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/destination/DeleteDestination.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/destination/DeleteDestination.java
index eeb0506..93dbf5e 100644
--- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/destination/DeleteDestination.java
+++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/destination/DeleteDestination.java
@@ -49,7 +49,7 @@ public class DeleteDestination extends DestinationAction {
}
private void deleteJmsTopic(final ActionContext context) throws Exception {
- performJmsManagement(brokerURL, user, password, new ManagementCallback<Message>() {
+ performJmsManagement(new ManagementCallback<Message>() {
@Override
public void setUpInvocation(Message message) throws Exception {
JMSManagementHelper.putOperationInvocation(message, "jms.server", "destroyTopic", getName(), removeConsumers);
@@ -74,7 +74,7 @@ public class DeleteDestination extends DestinationAction {
}
private void deleteJmsQueue(final ActionContext context) throws Exception {
- performJmsManagement(brokerURL, user, password, new ManagementCallback<Message>() {
+ performJmsManagement(new ManagementCallback<Message>() {
@Override
public void setUpInvocation(Message message) throws Exception {
JMSManagementHelper.putOperationInvocation(message, "jms.server", "destroyQueue", getName(), removeConsumers);
@@ -99,7 +99,7 @@ public class DeleteDestination extends DestinationAction {
}
private void deleteCoreQueue(final ActionContext context) throws Exception {
- performCoreManagement(brokerURL, user, password, new ManagementCallback<ClientMessage>() {
+ performCoreManagement(new ManagementCallback<ClientMessage>() {
@Override
public void setUpInvocation(ClientMessage message) throws Exception {
ManagementHelper.putOperationInvocation(message, "core.server", "destroyQueue", getName());
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/aa0965c0/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/destination/DestinationAction.java
----------------------------------------------------------------------
diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/destination/DestinationAction.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/destination/DestinationAction.java
index c128fc5..e161dd3 100644
--- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/destination/DestinationAction.java
+++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/destination/DestinationAction.java
@@ -31,13 +31,12 @@ import org.apache.activemq.artemis.api.core.client.ServerLocator;
import org.apache.activemq.artemis.api.core.management.ManagementHelper;
import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient;
import org.apache.activemq.artemis.api.jms.management.JMSManagementHelper;
-import org.apache.activemq.artemis.cli.commands.InputAbstract;
-import org.apache.activemq.artemis.core.client.impl.ServerLocatorImpl;
+import org.apache.activemq.artemis.cli.commands.messages.ConnectionAbstract;
import org.apache.activemq.artemis.jms.client.ActiveMQConnection;
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
import org.apache.activemq.artemis.jms.client.ActiveMQSession;
-public abstract class DestinationAction extends InputAbstract {
+public abstract class DestinationAction extends ConnectionAbstract {
public static final String JMS_QUEUE = "jms-queue";
public static final String JMS_TOPIC = "topic";
@@ -46,24 +45,12 @@ public abstract class DestinationAction extends InputAbstract {
@Option(name = "--type", description = "type of destination to be created (one of jms-queue, topic and core-queue, default jms-queue")
String destType = JMS_QUEUE;
- @Option(name = "--url", description = "URL towards the broker. (default: tcp://localhost:61616)")
- String brokerURL = "tcp://localhost:61616";
-
- @Option(name = "--user", description = "User used to connect")
- String user;
-
- @Option(name = "--password", description = "Password used to connect")
- String password;
-
@Option(name = "--name", description = "destination name")
String name;
- public static void performJmsManagement(String brokerURL,
- String user,
- String password,
- ManagementCallback<Message> cb) throws Exception {
+ public void performJmsManagement(ManagementCallback<Message> cb) throws Exception {
- try (ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(brokerURL, user, password);
+ try (ActiveMQConnectionFactory factory = createConnectionFactory();
ActiveMQConnection connection = (ActiveMQConnection) factory.createConnection();
ActiveMQSession session = (ActiveMQSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE)) {
@@ -88,12 +75,10 @@ public abstract class DestinationAction extends InputAbstract {
}
}
- public static void performCoreManagement(String brokerURL,
- String user,
- String password,
- ManagementCallback<ClientMessage> cb) throws Exception {
+ public void performCoreManagement(ManagementCallback<ClientMessage> cb) throws Exception {
- try (ServerLocator locator = ServerLocatorImpl.newLocator(brokerURL);
+ try (ActiveMQConnectionFactory factory = createConnectionFactory();
+ ServerLocator locator = factory.getServerLocator();
ClientSessionFactory sessionFactory = locator.createSessionFactory();
ClientSession session = sessionFactory.createSession(user, password, false, true, true, false, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE)) {
session.start();
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/aa0965c0/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/Browse.java
----------------------------------------------------------------------
diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/Browse.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/Browse.java
index 3149708..936fba9 100644
--- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/Browse.java
+++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/Browse.java
@@ -40,7 +40,7 @@ public class Browse extends DestAbstract {
System.out.println("Consumer:: filter = " + filter);
- ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(brokerURL, user, password);
+ ActiveMQConnectionFactory factory = createConnectionFactory();
Destination dest = ActiveMQDestination.createDestination(this.destination, ActiveMQDestination.QUEUE_TYPE);
try (Connection connection = factory.createConnection()) {
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/aa0965c0/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/ConnectionAbstract.java
----------------------------------------------------------------------
diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/ConnectionAbstract.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/ConnectionAbstract.java
new file mode 100644
index 0000000..03bc075
--- /dev/null
+++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/ConnectionAbstract.java
@@ -0,0 +1,68 @@
+/**
+ * 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.cli.commands.messages;
+
+import javax.jms.Connection;
+import javax.jms.JMSException;
+import javax.jms.JMSSecurityException;
+
+import io.airlift.airline.Option;
+import org.apache.activemq.artemis.cli.commands.InputAbstract;
+import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
+
+public class ConnectionAbstract extends InputAbstract {
+ @Option(name = "--url", description = "URL towards the broker. (default: tcp://localhost:61616)")
+ protected String brokerURL = "tcp://localhost:61616";
+
+ @Option(name = "--user", description = "User used to connect")
+ protected String user;
+
+ @Option(name = "--password", description = "Password used to connect")
+ protected String password;
+
+
+ protected ActiveMQConnectionFactory createConnectionFactory() throws Exception {
+ ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory(brokerURL, user, password);
+ try {
+ Connection connection = cf.createConnection();
+ connection.close();
+ return cf;
+ } catch (JMSSecurityException e) {
+ // if a security exception will get the user and password through an input
+ context.err.println("Connection failed::" + e.getMessage());
+ userPassword();
+ return new ActiveMQConnectionFactory(brokerURL, user, password);
+ } catch (JMSException e) {
+ // if a connection exception will ask for the URL, user and password
+ context.err.println("Connection failed::" + e.getMessage());
+ brokerURL = input("--url", "Type in the broker URL for a retry (e.g. tcp://localhost:61616)", brokerURL);
+ userPassword();
+ return new ActiveMQConnectionFactory(brokerURL, user, password);
+ }
+ }
+
+ private void userPassword() {
+ if (user == null) {
+ user = input("--user", "Type the username for a retry", null);
+ }
+ if (password == null) {
+ password = inputPassword("--password", "Type the password for a retry", null);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/aa0965c0/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/Consumer.java
----------------------------------------------------------------------
diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/Consumer.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/Consumer.java
index 71bf40c..ef5aefd 100644
--- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/Consumer.java
+++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/Consumer.java
@@ -49,7 +49,7 @@ public class Consumer extends DestAbstract {
System.out.println("Consumer:: filter = " + filter);
- ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(brokerURL, user, password);
+ ActiveMQConnectionFactory factory = createConnectionFactory();
Destination dest = ActiveMQDestination.createDestination(this.destination, ActiveMQDestination.QUEUE_TYPE);
try (Connection connection = factory.createConnection()) {
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/aa0965c0/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/DestAbstract.java
----------------------------------------------------------------------
diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/DestAbstract.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/DestAbstract.java
index 1e3ac11..95b3c99 100644
--- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/DestAbstract.java
+++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/DestAbstract.java
@@ -18,12 +18,8 @@
package org.apache.activemq.artemis.cli.commands.messages;
import io.airlift.airline.Option;
-import org.apache.activemq.artemis.cli.commands.ActionAbstract;
-public class DestAbstract extends ActionAbstract {
-
- @Option(name = "--url", description = "URL towards the broker. (default: tcp://localhost:61616)")
- String brokerURL = "tcp://localhost:61616";
+public class DestAbstract extends ConnectionAbstract {
@Option(name = "--destination", description = "Destination to be used. it could be prefixed with queue:// or topic:: (Default: queue://TEST")
String destination = "queue://TEST";
@@ -31,12 +27,6 @@ public class DestAbstract extends ActionAbstract {
@Option(name = "--message-count", description = "Number of messages to act on (Default: 1000)")
int messageCount = 1000;
- @Option(name = "--user", description = "User used to connect")
- String user;
-
- @Option(name = "--password", description = "Password used to connect")
- String password;
-
@Option(name = "--sleep", description = "Time wait between each message")
int sleep = 0;
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/aa0965c0/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/Producer.java
----------------------------------------------------------------------
diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/Producer.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/Producer.java
index 1f6a4b1..8f76d31 100644
--- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/Producer.java
+++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/Producer.java
@@ -50,7 +50,7 @@ public class Producer extends DestAbstract {
public Object execute(ActionContext context) throws Exception {
super.execute(context);
- ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(brokerURL, user, password);
+ ActiveMQConnectionFactory factory = createConnectionFactory();
Destination dest = ActiveMQDestination.createDestination(this.destination, ActiveMQDestination.QUEUE_TYPE);
try (Connection connection = factory.createConnection()) {