use of org.jboss.as.cli.CliInitializationException in project wildfly-core by wildfly.
the class CliConfigImpl method parse.
private static CliConfigImpl parse(final CommandContext ctx, File f) throws CliInitializationException {
if (f == null) {
throw new CliInitializationException("The file argument is null.");
}
if (!f.exists()) {
// throw new CliInitializationException(f.getAbsolutePath() + " doesn't exist.");
return new CliConfigImpl();
}
CliConfigImpl config = new CliConfigImpl();
BufferedInputStream input = null;
try {
final XMLMapper mapper = XMLMapper.Factory.create();
final XMLElementReader<CliConfigImpl> reader = new CliConfigReader();
for (Namespace current : Namespace.cliValues()) {
mapper.registerRootElement(new QName(current.getUriString(), JBOSS_CLI), reader);
}
FileInputStream is = new FileInputStream(f);
input = new BufferedInputStream(is);
XMLStreamReader streamReader = XMLInputFactory.newInstance().createXMLStreamReader(input);
mapper.parseDocument(config, streamReader);
streamReader.close();
} catch (Throwable t) {
throw new CliInitializationException("Failed to parse " + f.getAbsolutePath(), t);
} finally {
StreamUtils.safeClose(input);
}
return config;
}
use of org.jboss.as.cli.CliInitializationException in project wildfly-core by wildfly.
the class CliLauncher method runcom.
static void runcom(CommandContext ctx) throws CliInitializationException {
File jbossCliRcFile = null;
// system property first
String jbossCliRc = WildFlySecurityManager.getPropertyPrivileged(JBOSS_CLI_RC_PROPERTY, null);
if (jbossCliRc == null) {
// current dir second
String dir = WildFlySecurityManager.getPropertyPrivileged(CURRENT_WORKING_DIRECTORY, null);
File f = new File(dir, JBOSS_CLI_RC_FILE);
if (!f.exists()) {
// WildFly home bin dir third
dir = WildFlySecurityManager.getEnvPropertyPrivileged("JBOSS_HOME", null);
if (dir != null) {
f = new File(dir + File.separatorChar + "bin", JBOSS_CLI_RC_FILE);
if (f.exists()) {
jbossCliRcFile = f;
}
}
} else {
jbossCliRcFile = f;
}
} else {
jbossCliRcFile = new File(jbossCliRc);
if (!jbossCliRcFile.exists()) {
throw new CliInitializationException("Property " + JBOSS_CLI_RC_PROPERTY + " points to a file that doesn't exist: " + jbossCliRcFile.getAbsolutePath());
}
}
if (jbossCliRcFile != null) {
processFile(jbossCliRcFile, ctx);
if (ctx.getExitCode() != 0) {
throw new CliInitializationException("Failed to process " + jbossCliRcFile.getAbsoluteFile());
}
}
}
use of org.jboss.as.cli.CliInitializationException in project wildfly-core by wildfly.
the class CLI method doConnect.
private void doConnect(Callable<CommandContext> callable) {
if (isConnected()) {
throw new IllegalStateException("Already connected to server.");
}
CommandContext newContext = null;
try {
newContext = callable.call();
newContext.connectController();
} catch (Exception ex) {
if (newContext != null) {
newContext.terminateSession();
}
if (ex instanceof CliInitializationException) {
throw new IllegalStateException("Unable to initialize " + "command context.", ex);
}
if (ex instanceof CommandLineException) {
throw new IllegalStateException("Unable to connect " + "to controller.", ex);
}
throw new IllegalStateException(ex);
}
// We have a new connected context, terminate the current one.
terminate();
ctx = newContext;
}
use of org.jboss.as.cli.CliInitializationException in project wildfly-core by wildfly.
the class CommandContextImpl method initBasicConsole.
protected void initBasicConsole(InputStream consoleInput, boolean start) throws CliInitializationException {
// this method shouldn't be called twice during the session
assert console == null : "the console has already been initialized";
Settings settings = createSettings(consoleInput);
try {
this.console = new ReadlineConsole(settings);
} catch (IOException ex) {
throw new CliInitializationException(ex);
}
this.console.setActionCallback((line) -> {
handleSafe(line.trim());
if (console != null) {
console.setPrompt(getPrompt());
}
});
if (start) {
try {
console.start();
} catch (IOException ex) {
throw new CliInitializationException(ex);
}
}
}
use of org.jboss.as.cli.CliInitializationException in project wildfly-core by wildfly.
the class ConnectDialog method createActions.
private void createActions() {
actionConnect = new AbstractAction(TEXT_CONNECT) {
public void actionPerformed(ActionEvent ev) {
if (!isEnabled() || !isVisible()) {
return;
}
String controller = null;
String user = null;
String password = null;
if (tfURL.getText().length() > 0) {
controller = tfURL.getText();
if (tfUserName.getText().length() > 0) {
user = tfUserName.getText();
password = tfPassword.getText();
}
}
try {
final CommandContext cmdCtx;
if (user == null) {
cmdCtx = CommandContextFactory.getInstance().newCommandContext();
} else {
cmdCtx = CommandContextFactory.getInstance().newCommandContext(null, user, password.toCharArray());
}
cmdCtx.connectController(controller);
plugin.init(cmdCtx);
} catch (CliInitializationException e) {
statusBar.setText(e.getMessage());
e.printStackTrace();
return;
} catch (NumberFormatException e) {
statusBar.setText(e.getMessage());
e.printStackTrace();
return;
} catch (CommandLineException e) {
e.printStackTrace();
statusBar.setText(e.getMessage());
return;
}
setVisible(false);
clearStatus();
}
};
}
Aggregations