Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[HHQ-4064] Give more informative error when connection properties are…

… not given.
  • Loading branch information...
commit 3c4a222ee36e31b97ecb8e98be9b0c592ada0f2b 1 parent 0077b06
Ryan Morgan authored
Showing with 20 additions and 7 deletions.
  1. +20 −7 src/org/hyperic/hq/hqapi1/tools/Shell.java
View
27 src/org/hyperic/hq/hqapi1/tools/Shell.java
@@ -130,28 +130,36 @@ static void initConnectionProperties(final String[] args) throws Exception {
if (host == null) {
host = clientProps.getProperty(OptionParserFactory.OPT_HOST);
}
- System.setProperty(OptionParserFactory.SYSTEM_PROP_PREFIX + OptionParserFactory.OPT_HOST, host);
-
+ if (host != null) {
+ System.setProperty(OptionParserFactory.SYSTEM_PROP_PREFIX + OptionParserFactory.OPT_HOST, host);
+ }
+
Integer port;
if (options.hasArgument(OptionParserFactory.OPT_PORT)) {
port = (Integer)options.valueOf(OptionParserFactory.OPT_PORT);
} else {
port = Integer.parseInt(clientProps.getProperty(OptionParserFactory.OPT_PORT, "7080"));
}
- System.setProperty(OptionParserFactory.SYSTEM_PROP_PREFIX + OptionParserFactory.OPT_PORT, port.toString());
+ if (port != null) {
+ System.setProperty(OptionParserFactory.SYSTEM_PROP_PREFIX + OptionParserFactory.OPT_PORT, port.toString());
+ }
String user = (String)options.valueOf(OptionParserFactory.OPT_USER);
if (user == null) {
user = clientProps.getProperty(OptionParserFactory.OPT_USER);
}
- System.setProperty(OptionParserFactory.SYSTEM_PROP_PREFIX + OptionParserFactory.OPT_USER, user);
+ if (user != null) {
+ System.setProperty(OptionParserFactory.SYSTEM_PROP_PREFIX + OptionParserFactory.OPT_USER, user);
+ }
+
String password = (String)options.valueOf(OptionParserFactory.OPT_PASS);
if (password == null) {
password = clientProps.getProperty(OptionParserFactory.OPT_PASS);
}
- if (password == null) {
- // Prompt for password
+ if (host != null && port != null && user != null && password == null) {
+ // Prompt for password, but only if other connection properties
+ // have been specified.
try {
char[] passwordArray = PasswordField.getPassword(System.in,
"Enter password: ");
@@ -161,7 +169,11 @@ static void initConnectionProperties(final String[] args) throws Exception {
System.exit(-1);
}
}
- System.setProperty(OptionParserFactory.SYSTEM_PROP_PREFIX + OptionParserFactory.OPT_PASS,password);
+ if (password != null) {
+ System.setProperty(OptionParserFactory.SYSTEM_PROP_PREFIX + OptionParserFactory.OPT_PASS,password);
+ }
+
+
Boolean secure = options.hasArgument(OptionParserFactory.OPT_SECURE[0]) ||
Boolean.valueOf(clientProps.getProperty(OptionParserFactory.OPT_SECURE[1],
"false"));
@@ -196,6 +208,7 @@ public static void main(String[] args) throws Exception {
} catch (Exception e) {
System.err.println("Error parsing command line connection properties. Cause: "
+ e.getMessage());
+ e.printStackTrace(System.err);
System.exit(1);
}
final ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(
Please sign in to comment.
Something went wrong with that request. Please try again.