Search in sources :

Example 1 with CliInitializationException

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;
}
Also used : XMLMapper(org.jboss.staxmapper.XMLMapper) XMLStreamReader(javax.xml.stream.XMLStreamReader) BufferedInputStream(java.io.BufferedInputStream) QName(javax.xml.namespace.QName) CliInitializationException(org.jboss.as.cli.CliInitializationException) FileInputStream(java.io.FileInputStream)

Example 2 with CliInitializationException

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());
        }
    }
}
Also used : CliInitializationException(org.jboss.as.cli.CliInitializationException) File(java.io.File)

Example 3 with CliInitializationException

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;
}
Also used : CommandContext(org.jboss.as.cli.CommandContext) CliInitializationException(org.jboss.as.cli.CliInitializationException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) CliInitializationException(org.jboss.as.cli.CliInitializationException) CommandLineException(org.jboss.as.cli.CommandLineException) CommandLineException(org.jboss.as.cli.CommandLineException)

Example 4 with CliInitializationException

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);
        }
    }
}
Also used : CliInitializationException(org.jboss.as.cli.CliInitializationException) IOException(java.io.IOException) Settings(org.jboss.as.cli.impl.ReadlineConsole.Settings)

Example 5 with CliInitializationException

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();
        }
    };
}
Also used : CommandContext(org.jboss.as.cli.CommandContext) ActionEvent(java.awt.event.ActionEvent) CliInitializationException(org.jboss.as.cli.CliInitializationException) AbstractAction(javax.swing.AbstractAction) CommandLineException(org.jboss.as.cli.CommandLineException)

Aggregations

CliInitializationException (org.jboss.as.cli.CliInitializationException)5 IOException (java.io.IOException)2 CommandContext (org.jboss.as.cli.CommandContext)2 CommandLineException (org.jboss.as.cli.CommandLineException)2 ActionEvent (java.awt.event.ActionEvent)1 BufferedInputStream (java.io.BufferedInputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 URISyntaxException (java.net.URISyntaxException)1 AbstractAction (javax.swing.AbstractAction)1 QName (javax.xml.namespace.QName)1 XMLStreamReader (javax.xml.stream.XMLStreamReader)1 Settings (org.jboss.as.cli.impl.ReadlineConsole.Settings)1 XMLMapper (org.jboss.staxmapper.XMLMapper)1