ARTEMIS-3886 fix CLI operation retry
Commit f8b045bd2d
broke the operation
retry as it introduced local variables named "user" and "password" which
overried the class-level variables of the same name. Therefore, when the
user re-enters the username and password on the command-line those
values won't actually be used when attempting to reconnect.
This commit is contained in:
parent
1c0a6d4091
commit
597953b6e2
|
@ -163,8 +163,7 @@ public class ConnectionAbstract extends InputAbstract {
|
|||
} catch (JMSSecurityException e) {
|
||||
// if a security exception will get the user and password through an input
|
||||
context.err.println("Connection failed::" + e.getMessage());
|
||||
userPassword();
|
||||
cf = new JmsConnectionFactory(user, password, brokerURL);
|
||||
cf = new JmsConnectionFactory(inputUser(user), inputPassword(password), brokerURL);
|
||||
if (clientID != null) {
|
||||
cf.setClientID(clientID);
|
||||
}
|
||||
|
@ -172,9 +171,7 @@ public class ConnectionAbstract extends InputAbstract {
|
|||
} 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();
|
||||
cf = new JmsConnectionFactory(user, password, brokerURL);
|
||||
cf = new JmsConnectionFactory(inputUser(user), inputPassword(password), inputBrokerURL(brokerURL));
|
||||
if (clientID != null) {
|
||||
cf.setClientID(clientID);
|
||||
}
|
||||
|
@ -204,8 +201,7 @@ public class ConnectionAbstract extends InputAbstract {
|
|||
if (context != null) {
|
||||
context.err.println("Connection failed::" + e.getMessage());
|
||||
}
|
||||
userPassword();
|
||||
cf = new ActiveMQConnectionFactory(brokerURL, user, password);
|
||||
cf = new ActiveMQConnectionFactory(brokerURL, inputUser(user), inputPassword(password));
|
||||
if (clientID != null) {
|
||||
cf.setClientID(clientID);
|
||||
}
|
||||
|
@ -215,9 +211,7 @@ public class ConnectionAbstract extends InputAbstract {
|
|||
if (context != null) {
|
||||
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();
|
||||
cf = new ActiveMQConnectionFactory(brokerURL, user, password);
|
||||
cf = new ActiveMQConnectionFactory(inputBrokerURL(brokerURL), inputUser(user), inputPassword(password));
|
||||
if (clientID != null) {
|
||||
cf.setClientID(clientID);
|
||||
}
|
||||
|
@ -225,13 +219,21 @@ public class ConnectionAbstract extends InputAbstract {
|
|||
}
|
||||
}
|
||||
|
||||
private void userPassword() {
|
||||
private String inputBrokerURL(String defaultValue) {
|
||||
return input("--url", "Type in the broker URL for a retry (e.g. tcp://localhost:61616)", defaultValue);
|
||||
}
|
||||
|
||||
private String inputUser(String user) {
|
||||
if (user == null) {
|
||||
user = input("--user", "Type the username for a retry", null);
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
private String inputPassword(String password) {
|
||||
if (password == null) {
|
||||
password = inputPassword("--password", "Type the password for a retry", null);
|
||||
}
|
||||
return password;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@ import java.io.BufferedWriter;
|
|||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
|
@ -1266,6 +1267,37 @@ public class ArtemisTest extends CliTestBase {
|
|||
testSimpleRun("server");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOperationRetry() throws Exception {
|
||||
File instanceFolder = temporaryFolder.newFolder("server");
|
||||
setupAuth(instanceFolder);
|
||||
Run.setEmbedded(true);
|
||||
Artemis.main("create", instanceFolder.getAbsolutePath(), "--verbose", "--force", "--silent", "--no-web", "--queues", "q1", "--no-autotune", "--require-login", "--default-port", "61616");
|
||||
System.setProperty("artemis.instance", instanceFolder.getAbsolutePath());
|
||||
|
||||
try {
|
||||
Artemis.internalExecute("run");
|
||||
InputStream in = new ByteArrayInputStream("admin\n".getBytes());
|
||||
ActionContext context = new ActionContext(in, System.out, System.err);
|
||||
|
||||
/*
|
||||
* This operation should fail the first time and then prompt the user to re-enter the username which
|
||||
* it will read from the InputStream in the ActionContext. It can't read the password since it's using
|
||||
* System.console.readPassword() for that.
|
||||
*/
|
||||
assertEquals(Integer.valueOf(100), Artemis.internalExecute(null, null, new String[] {"producer", "--destination", "queue://q1", "--message-count", "100", "--password", "admin"}, context));
|
||||
|
||||
/*
|
||||
* This is the same as above except it will prompt the user to re-enter both the URL and the username.
|
||||
*/
|
||||
in = new ByteArrayInputStream("tcp://localhost:61616\nadmin\n".getBytes());
|
||||
context = new ActionContext(in, System.out, System.err);
|
||||
assertEquals(Integer.valueOf(100), Artemis.internalExecute(null, null, new String[] {"producer", "--destination", "queue://q1", "--message-count", "100", "--password", "admin", "--url", "tcp://badhost:11111"}, context));
|
||||
} finally {
|
||||
stopServer();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWeirdCharacter() throws Exception {
|
||||
testSimpleRun("test%26%26x86_6");
|
||||
|
|
Loading…
Reference in New Issue