Search in sources :

Example 6 with SystemExitException

use of org.apache.openejb.cli.SystemExitException in project tomee by apache.

the class Cipher method main.

public static void main(final String[] args) throws SystemExitException {
    final CommandLineParser parser = new PosixParser();
    // create the Options
    final Options options = new Options();
    options.addOption(option("h", "help", "cmd.cipher.opt.help"));
    options.addOption(option("c", "cipher", "c", "cmd.cipher.opt.impl"));
    options.addOption(option("d", "decrypt", "cmd.cipher.opt.decrypt"));
    options.addOption(option("e", "encrypt", "cmd.cipher.opt.encrypt"));
    final CommandLine line;
    try {
        // parse the command line arguments
        line = parser.parse(options, args);
    } catch (final ParseException exp) {
        help(options);
        throw new SystemExitException(-1);
    }
    if (line.hasOption("help")) {
        help(options);
        return;
    }
    String cipherName = "Static3DES";
    if (line.hasOption("cipher")) {
        cipherName = line.getOptionValue("cipher");
    }
    if (line.getArgList().size() != 1) {
        System.out.println("Must specify either a plain text to encrypt or a ciphered value to decrypt.");
        help(options);
        return;
    }
    final PasswordCipher cipher;
    try {
        cipher = PasswordCipherFactory.getPasswordCipher(cipherName);
    } catch (final PasswordCipherException e) {
        System.out.println("Could not load password cipher implementation class. Check your classpath.");
        availableCiphers();
        throw new SystemExitException(-1);
    }
    if (line.hasOption("decrypt")) {
        final String pwdArg = (String) line.getArgList().get(0);
        final char[] encryptdPassword = pwdArg.toCharArray();
        System.out.println(cipher.decrypt(encryptdPassword));
    } else {
        // if option neither encrypt/decrypt is specified, we assume
        // it is encrypt.
        final String plainPassword = (String) line.getArgList().get(0);
        System.out.println(new String(cipher.encrypt(plainPassword)));
    }
}
Also used : Options(org.apache.commons.cli.Options) CommandLine(org.apache.commons.cli.CommandLine) PasswordCipher(org.apache.openejb.cipher.PasswordCipher) PasswordCipherException(org.apache.openejb.cipher.PasswordCipherException) PosixParser(org.apache.commons.cli.PosixParser) SystemExitException(org.apache.openejb.cli.SystemExitException) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException)

Example 7 with SystemExitException

use of org.apache.openejb.cli.SystemExitException in project tomee by apache.

the class EffectiveTomEEXml method parseCommand.

private static CommandLine parseCommand(final String[] args) throws SystemExitException {
    final Options options = new Options();
    options.addOption(OptionBuilder.hasArg(true).withLongOpt("path").withDescription("[openejb|tomee].xml path").create("p"));
    final CommandLine line;
    try {
        line = new PosixParser().parse(options, args);
    } catch (final ParseException exp) {
        help(options);
        throw new SystemExitException(-1);
    }
    if (line.hasOption("help")) {
        help(options);
        return null;
    }
    return line;
}
Also used : Options(org.apache.commons.cli.Options) CommandLine(org.apache.commons.cli.CommandLine) PosixParser(org.apache.commons.cli.PosixParser) SystemExitException(org.apache.openejb.cli.SystemExitException) ParseException(org.apache.commons.cli.ParseException)

Aggregations

CommandLine (org.apache.commons.cli.CommandLine)7 Options (org.apache.commons.cli.Options)7 ParseException (org.apache.commons.cli.ParseException)7 PosixParser (org.apache.commons.cli.PosixParser)7 SystemExitException (org.apache.openejb.cli.SystemExitException)7 CommandLineParser (org.apache.commons.cli.CommandLineParser)5 File (java.io.File)4 Properties (java.util.Properties)3 IOException (java.io.IOException)2 InitialContext (javax.naming.InitialContext)2 NamingException (javax.naming.NamingException)2 ServiceUnavailableException (javax.naming.ServiceUnavailableException)2 OpenEJBException (org.apache.openejb.OpenEJBException)2 UndeployException (org.apache.openejb.UndeployException)2 Deployer (org.apache.openejb.assembler.Deployer)2 Method (java.lang.reflect.Method)1 LinkedList (java.util.LinkedList)1 JarFile (java.util.jar.JarFile)1 DefinitionException (javax.enterprise.inject.spi.DefinitionException)1 NoSuchApplicationException (org.apache.openejb.NoSuchApplicationException)1