Package org.apache.openejb.cli

Examples of org.apache.openejb.cli.SystemExitException


        CommandLine line = null;
        try {
            line = parser.parse(options, args);
        } catch (ParseException exp) {
            AppValidator.help(options);
            throw new SystemExitException(-1);
        }

        if (line.hasOption("help")) {
            AppValidator.help(options);
            return;
View Full Code Here


        try {
            // parse the command line arguments
            line = parser.parse(options, args);
        } catch (ParseException exp) {
            help(options);
            throw new SystemExitException(-1);
        }

        if (line.hasOption("help")) {
            help(options);
            return;
        } else if (line.hasOption("version")) {
            OpenEjbVersion.get().print(System.out);
            return;
        }

        if (line.getArgList().size() == 0) {
            System.out.println("Must specify an archive to deploy.");
            help(options);
            return;
        }
       
        // make sure that the modules given on the command line are accessible
        List<?> modules = line.getArgList();
        for (Object module : modules) {
            String path = (String) module;
            File file = new File(path);
            try {
                checkSource(file);
            } catch (DeploymentTerminatedException e) {
                System.out.println(e.getMessage());
                // TODO: What is it for?
                throw new SystemExitException(-100);
            }
        }

        boolean offline = line.hasOption("offline");

        File apps;
        try {
            String dir = line.getOptionValue("dir", "apps");
            apps = SystemInstance.get().getBase().getDirectory(dir);
        } catch (IOException e) {
            throw new SystemExitException(-1);
        }

        if (!apps.exists()) {
            System.out.println("Directory does not exist: " + apps.getAbsolutePath());
        }

        Deployer deployer = null;
        if (!offline) {
            Properties p = new Properties();
            p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.RemoteInitialContextFactory");

            String serverUrl = defaultServerUrl;
            if (line.hasOption(serverUrl)) {
                serverUrl = line.getOptionValue("serverUrl");
            }
            p.put(Context.PROVIDER_URL, serverUrl);

            try {
                InitialContext ctx = new InitialContext(p);
                deployer = (Deployer) ctx.lookup("openejb/DeployerBusinessRemote");
            } catch (javax.naming.ServiceUnavailableException e) {
                System.out.println(e.getCause().getMessage());
                System.out.println(messages.format("cmd.deploy.serverOffline"));
                throw new SystemExitException(-1);
            } catch (javax.naming.NamingException e) {
                System.out.println("openejb/DeployerBusinessRemote does not exist in server '" + serverUrl
                        + "', check the server logs to ensure it exists and has not been removed.");
                throw new SystemExitException(-2);
            }
        }

        boolean undeploy = line.hasOption("undeploy");

        // We increment the exit code once for every failed deploy
        int exitCode = 0;
        for (Object obj : line.getArgList()) {
            String path = (String) obj;

            File file = new File(path);

            File destFile = new File(apps, file.getName());

            try {
                if (shouldUnpack(file)) {
                    File unpacked = unpackedLocation(file, apps);
                    if (undeploy) {
                        undeploy(offline, unpacked, path, deployer);
                    }
                    destFile = unpack(file, unpacked);
                } else {
                    if (undeploy){
                        undeploy(offline, destFile, path, deployer);
                    }
                    checkDest(destFile, file);
                    copyFile(file, destFile);
                }

                if (offline) {
                    System.out.println(messages.format("cmd.deploy.offline", path, apps.getAbsolutePath()));
                    continue;
                }

                String location;
                try {
                    location = destFile.getCanonicalPath();
                } catch (IOException e) {
                    throw new OpenEJBException(messages.format("cmd.deploy.fileNotFound", path));
                }
                AppInfo appInfo = deployer.deploy(location);

                System.out.println(messages.format("cmd.deploy.successful", path, appInfo.jarPath));

                if (line.hasOption("quiet")) {
                    continue;
                }

                print(appInfo);

            } catch (UndeployException e) {
                System.out.println(messages.format("cmd.undeploy.failed", path));
                e.printStackTrace(System.out);
                exitCode++;
            } catch (DeploymentTerminatedException e) {
                System.out.println(e.getMessage());
                exitCode++;
            } catch (ValidationFailedException e) {
                System.out.println(messages.format("cmd.deploy.validationFailed", path));
                int level = 2;
                if (line.hasOption("debug")){
                    level = 3;
                }
                AppValidator appValidator = new AppValidator(level, false, true, false);
                appValidator.printResults(e);
                exitCode++;
                if (!delete(destFile)){
                    System.out.println(messages.format("cmd.deploy.cantDelete.deploy", destFile.getAbsolutePath()));
                }
            } catch (OpenEJBException e) {
                System.out.println(messages.format("cmd.deploy.failed", path));
                e.printStackTrace(System.out);
                exitCode++;
                if (!delete(destFile)){
                    System.out.println(messages.format("cmd.deploy.cantDelete.deploy", destFile.getAbsolutePath()));
                }
            }
        }

        if (exitCode != 0){
            throw new SystemExitException(exitCode);
        }
    }
View Full Code Here

        try {
            // parse the command line arguments
            line = parser.parse(options, args);
        } catch (ParseException exp) {
            help(options);
            throw new SystemExitException(-1);
        }

        if (line.hasOption("help")) {
            help(options);
            return;
        } else if (line.hasOption("version")) {
            OpenEjbVersion.get().print(System.out);
            return;
        } else if (line.hasOption("examples")) {
            try {
                String text = finder.findString("org.apache.openejb.cli/start.examples");
                System.out.println(text);
                return;
            } catch (IOException e) {
                System.err.println("Unable to print examples:");
                e.printStackTrace();
                throw new SystemExitException(-2);
            }
        }

        Properties props = SystemInstance.get().getProperties();
View Full Code Here

        try {
            // parse the command line arguments
            line = parser.parse(options, args);
        } catch (ParseException exp) {
            Undeploy.help(options);
            throw new SystemExitException(-1);
        }

        if (line.hasOption("help")) {
            Undeploy.help(options);
            return;
        } else if (line.hasOption("version")) {
            OpenEjbVersion.get().print(System.out);
            return;
        }

        if (line.getArgList().size() == 0) {
            System.out.println("Must specify an module id.");
            help(options);
            return;
        }

        Properties p = new Properties();
        p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.RemoteInitialContextFactory");

        String serverUrl = Undeploy.defaultServerUrl;
        if (line.hasOption(serverUrl)) {
            serverUrl = line.getOptionValue("serverUrl");
        }
        p.put(Context.PROVIDER_URL, serverUrl);

        Deployer deployer = null;
        try {
            InitialContext ctx = new InitialContext(p);
            deployer = (Deployer) ctx.lookup("openejb/DeployerBusinessRemote");
        } catch (javax.naming.ServiceUnavailableException e) {
            System.out.println(e.getCause().getMessage());
            System.out.println(Undeploy.messages.format("cmd.deploy.serverOffline"));
            throw new SystemExitException(-1);
        } catch (javax.naming.NamingException e) {
            System.out.println("DeployerEjb does not exist in server '" + serverUrl + "', check the server logs to ensure it exists and has not been removed.");
            throw new SystemExitException(-2);
        }

        int exitCode = 0;
        for (Object obj : line.getArgList()) {
            String moduleId = (String) obj;

            try {
                undeploy(moduleId, deployer);
            } catch (DeploymentTerminatedException e) {
                System.out.println(e.getMessage());
                exitCode++;
            } catch (UndeployException e) {
                System.out.println(messages.format("cmd.undeploy.failed", moduleId));
                e.printStackTrace(System.out);
                exitCode++;
            } catch (NoSuchApplicationException e) {
                // TODO make this message
                System.out.println(messages.format("cmd.undeploy.noSuchModule", moduleId));
                exitCode++;
            }
        }

        if (exitCode != 0){
            throw new SystemExitException(exitCode);
        }
    }
View Full Code Here

        CommandLine line = null;
        try {
            line = parser.parse(options, args);
        } catch (ParseException exp) {
            AppValidator.help(options);
            throw new SystemExitException(-1);
        }

        if (line.hasOption("help")) {
            AppValidator.help(options);
            return;
View Full Code Here

        try {
            // parse the command line arguments
            line = parser.parse(options, args);
        } catch (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;
        }

        try {
            PasswordCipher cipher = BasicDataSourceUtil.getPasswordCipher(cipherName);

            if (line.hasOption("decrypt")) {
                String pwdArg = (String) line.getArgList().get(0);
                char[] encryptdPassword = pwdArg.toCharArray();
                System.out.println(cipher.decrypt(encryptdPassword));

            } else { // if option neither encrypt/decrypt is specified, we assume
                     // it is encrypt.
                String plainPassword = (String) line.getArgList().get(0);
                System.out.println(new String(cipher.encrypt(plainPassword)));
            }

        } catch (SQLException e) {
            System.out.println("Could not load password cipher implementation class. Check your classpath.");

            availableCiphers();

            throw new SystemExitException(-1);
        }

    }
View Full Code Here

        try {
            // parse the command line arguments
            line = parser.parse(options, args);
        } catch (ParseException exp) {
            Undeploy.help(options);
            throw new SystemExitException(-1);
        }

        if (line.hasOption("help")) {
            Undeploy.help(options);
            return;
        } else if (line.hasOption("version")) {
            OpenEjbVersion.get().print(System.out);
            return;
        }

        if (line.getArgList().size() == 0) {
            System.out.println("Must specify an module id.");
            Undeploy.help(options);
        }

        Properties p = new Properties();
        p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.RemoteInitialContextFactory");

        String serverUrl = Undeploy.defaultServerUrl;
        if (line.hasOption(serverUrl)) {
            serverUrl = line.getOptionValue("serverUrl");
        }
        p.put(Context.PROVIDER_URL, serverUrl);

        Deployer deployer = null;
        try {
            InitialContext ctx = new InitialContext(p);
            deployer = (Deployer) ctx.lookup("openejb/DeployerBusinessRemote");
        } catch (javax.naming.ServiceUnavailableException e) {
            System.out.println(e.getCause().getMessage());
            System.out.println(Undeploy.messages.format("cmd.deploy.serverOffline"));
            throw new SystemExitException(1);
        } catch (javax.naming.NamingException e) {
            System.out.println("DeployerEjb does not exist in server '" + serverUrl + "', check the server logs to ensure it exists and has not been removed.");
            throw new SystemExitException(2);
        }

        int exitCode = 0;
        for (Object obj : line.getArgList()) {
            String moduleId = (String) obj;

            try {
                deployer.undeploy(moduleId);

                // TODO make this message
                System.out.println(messages.format("cmd.undeploy.successful", moduleId));
            } catch (UndeployException e) {
                // TODO make this message
                // TODO Maybe brush up this excpetion handling
                System.out.println(messages.format("cmd.undeploy.failed", moduleId));
                e.printStackTrace(System.out);
                exitCode += 100;
            } catch (NoSuchApplicationException e) {
                // TODO make this message
                System.out.println(messages.format("cmd.undeploy.noSuchModule", moduleId));
                exitCode += 100;
            }
        }

        if (exitCode != 0){
            throw new SystemExitException(exitCode);
        }
    }
View Full Code Here

        try {
            // parse the command line arguments
            line = parser.parse(options, args);
        } catch (ParseException exp) {
            help(options);
            throw new SystemExitException(-1);
        }

        if (line.hasOption("help")) {
            help(options);
            return;
        } else if (line.hasOption("version")) {
            OpenEjbVersion.get().print(System.out);
            return;
        }

        if (line.getArgList().size() == 0) {
            System.out.println("Must specify an archive to deploy.");
            help(options);
        }


        boolean offline = line.hasOption("offline");

        File apps = null;
        try {
            String dir = line.getOptionValue("dir", "apps");
            apps = SystemInstance.get().getBase().getDirectory(dir);
        } catch (IOException e) {
            throw new SystemExitException(-1);
        }

        if (!apps.exists()) {
            System.out.println("Directory does not exist: " + apps.getAbsolutePath());
        }

        Properties p = new Properties();
        p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.RemoteInitialContextFactory");

        String serverUrl = defaultServerUrl;
        if (line.hasOption(serverUrl)) {
            serverUrl = line.getOptionValue("serverUrl");
        }
        p.put(Context.PROVIDER_URL, serverUrl);

        Deployer deployer = null;
        try {
            InitialContext ctx = new InitialContext(p);
            deployer = (Deployer) ctx.lookup("openejb/DeployerBusinessRemote");
        } catch (javax.naming.ServiceUnavailableException e) {
            System.out.println(e.getCause().getMessage());
            System.out.println(messages.format("cmd.deploy.serverOffline"));
            throw new SystemExitException(1);
        } catch (javax.naming.NamingException e) {
            System.out.println("DeployerEjb does not exist in server '" + serverUrl + "', check the server logs to ensure it exists and has not been removed.");
            throw new SystemExitException(2);
        }

        int exitCode = 0;
        for (Object obj : line.getArgList()) {
            String path = (String) obj;

            try {
                File file = new File(path);

                checkSource(file);

                File destFile = new File(apps, file.getName());

                checkDest(destFile, file);

                copyFile(file, destFile);

                if (offline) {
                    System.out.println(messages.format("cmd.deploy.offline", path, apps.getAbsolutePath()));
                    continue;
                }

                AppInfo appInfo = deployer.deploy(file.getAbsolutePath());

                System.out.println(messages.format("cmd.deploy.successful", path, appInfo.jarPath));

                if (line.hasOption("quiet")) {
                    continue;
                }

                System.out.println("App(id=" + appInfo.jarPath + ")");

                for (EjbJarInfo info : appInfo.ejbJars) {
                    System.out.println("    EjbJar(id=" + info.moduleId + ", path=" + info.jarPath + ")");
                    for (EnterpriseBeanInfo beanInfo : info.enterpriseBeans) {
                        System.out.println("        Ejb(ejb-name=" + beanInfo.ejbName + ", id=" + beanInfo.ejbDeploymentId + ")");
                        for (String name : beanInfo.jndiNames) {
                            System.out.println("            Jndi(name=" + name + ")");
                        }
                        System.out.println("");
                    }
                    for (InterceptorInfo interceptorInfo : info.interceptors) {
                        System.out.println("        Interceptor(class=" + interceptorInfo.clazz + ")");
                    }
                    System.out.println("");
                }
                for (ClientInfo clientInfo : appInfo.clients) {
                    System.out.println("    Client(main-class=" + clientInfo.mainClass + ", id=" + clientInfo.moduleId + ", path=" + clientInfo.codebase + ")");
                    System.out.println("");
                }
                for (ConnectorInfo connectorInfo : appInfo.connectors) {
                    System.out.println("    Connector(id=" + connectorInfo.moduleId + ", path=" + connectorInfo.codebase + ")");
                    System.out.println("");
                }
                for (WebAppInfo webAppInfo : appInfo.webApps) {
                    System.out.println("    WebApp(context-root=" + webAppInfo.contextRoot + ", id=" + webAppInfo.moduleId + ", path=" + webAppInfo.codebase + ")");
                    System.out.println("");
                }
                for (PersistenceUnitInfo persistenceUnitInfo : appInfo.persistenceUnits) {
                    System.out.println("    PersistenceUnit(name=" + persistenceUnitInfo.name + ", provider=" + persistenceUnitInfo.provider+ ")");
                    System.out.println("");
                }
            } catch (DeploymentTerminatedException e) {
                System.out.println(e.getMessage());
                exitCode += 100;
            } catch (ValidationFailedException e) {
                System.out.println(messages.format("cmd.deploy.validationFailed", path));
                int level = 2;
                if (line.hasOption("debug")){
                    level = 3;
                }
                AppValidator appValidator = new AppValidator(level, false, true, false);
                appValidator.printResults(e);
                exitCode += 100;
            } catch (OpenEJBException e) {
                System.out.println(messages.format("cmd.deploy.failed", path));
                e.printStackTrace(System.out);
                exitCode += 100;
            }
        }

        if (exitCode != 0){
            throw new SystemExitException(exitCode);
        }
    }
View Full Code Here

        try {
            // parse the command line arguments
            line = parser.parse(options, args);
        } catch (ParseException exp) {
            help(options);
            throw new SystemExitException(-1);
        }

        if (line.hasOption("help")) {
            help(options);
            return;
        } else if (line.hasOption("version")) {
            OpenEjbVersion.get().print(System.out);
            return;
        } else if (line.hasOption("examples")) {
            try {
                String text = finder.findString("org.apache.openejb.cli/start.examples");
                System.out.println(text);
                return;
            } catch (Exception e) {
                System.err.println("Unable to print examples:");
                e.printStackTrace(System.err);
                throw new SystemExitException(-2);
            }
        }

        Properties props = SystemInstance.get().getProperties();
View Full Code Here

        try {
            // parse the command line arguments
            line = parser.parse(options, args);
        } catch (ParseException exp) {
            help(options);
            throw new SystemExitException(-1);
        }

        if (line.hasOption("help")) {
            help(options);
            return;
        } else if (line.hasOption("version")) {
            OpenEjbVersion.get().print(System.out);
            return;
        }

        if (line.getArgList().size() == 0) {
            System.out.println("Must specify an archive to deploy.");
            help(options);
            return;
        }
       
        // make sure that the modules given on the command line are accessible
        List<?> modules = line.getArgList();
        for (Object module : modules) {
            String path = (String) module;
            File file = new File(path);
            try {
                checkSource(file);
            } catch (DeploymentTerminatedException e) {
                System.out.println(e.getMessage());
                // TODO: What is it for?
                throw new SystemExitException(-100);
            }
        }

        boolean offline = line.hasOption("offline");

        File apps;
        try {
            String dir = line.getOptionValue("dir", "apps");
            apps = SystemInstance.get().getBase().getDirectory(dir);
        } catch (IOException e) {
            throw new SystemExitException(-1);
        }

        if (!apps.exists()) {
            System.out.println("Directory does not exist: " + apps.getAbsolutePath());
        }

        Deployer deployer = null;
        if (!offline) {
            Properties p = new Properties();
            p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.RemoteInitialContextFactory");

            String serverUrl = line.getOptionValue("server-url", defaultServerUrl);
            p.put(Context.PROVIDER_URL, serverUrl);

            try {
                InitialContext ctx = new InitialContext(p);
                deployer = (Deployer) ctx.lookup("openejb/DeployerBusinessRemote");
            } catch (javax.naming.ServiceUnavailableException e) {
                System.out.println(e.getCause().getMessage());
                System.out.println(messages.format("cmd.deploy.serverOffline"));
                throw new SystemExitException(-1);
            } catch (javax.naming.NamingException e) {
                System.out.println("openejb/DeployerBusinessRemote does not exist in server '" + serverUrl
                        + "', check the server logs to ensure it exists and has not been removed.");
                throw new SystemExitException(-2);
            }
        }

        boolean undeploy = line.hasOption("undeploy");

        // We increment the exit code once for every failed deploy
        int exitCode = 0;
        for (Object obj : line.getArgList()) {
            String path = (String) obj;

            File file = new File(path);

            File destFile = new File(apps, file.getName());

            try {
                if (shouldUnpack(file)) {
                    File unpacked = unpackedLocation(file, apps);
                    if (undeploy) {
                        undeploy(offline, unpacked, path, deployer);
                    }
                    destFile = unpack(file, unpacked);
                } else {
                    if (undeploy){
                        undeploy(offline, destFile, path, deployer);
                    }
                    checkDest(destFile, file);
                    copyFile(file, destFile);
                }

                if (offline) {
                    System.out.println(messages.format("cmd.deploy.offline", path, apps.getAbsolutePath()));
                    continue;
                }

                String location;
                try {
                    location = destFile.getCanonicalPath();
                } catch (IOException e) {
                    throw new OpenEJBException(messages.format("cmd.deploy.fileNotFound", path));
                }
                AppInfo appInfo = deployer.deploy(location);

                System.out.println(messages.format("cmd.deploy.successful", path, appInfo.path));

                if (line.hasOption("quiet")) {
                    continue;
                }

                print(appInfo);

            } catch (UndeployException e) {
                System.out.println(messages.format("cmd.undeploy.failed", path));
                e.printStackTrace(System.out);
                exitCode++;
            } catch (DeploymentTerminatedException e) {
                System.out.println(e.getMessage());
                exitCode++;
            } catch (ValidationFailedException e) {
                System.out.println(messages.format("cmd.deploy.validationFailed", path));
                int level = 2;
                if (line.hasOption("debug")){
                    level = 3;
                }
                AppValidator appValidator = new AppValidator(level, false, true, false);
                appValidator.printResults(e);
                exitCode++;
                if (!delete(destFile)){
                    System.out.println(messages.format("cmd.deploy.cantDelete.deploy", destFile.getAbsolutePath()));
                }
            } catch (Throwable e) {
                System.out.println(messages.format("cmd.deploy.failed", path));
                e.printStackTrace(System.out);
                exitCode++;
                if (!delete(destFile)){
                    System.out.println(messages.format("cmd.deploy.cantDelete.deploy", destFile.getAbsolutePath()));
                }
            }
        }

        if (exitCode != 0){
            throw new SystemExitException(exitCode);
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.openejb.cli.SystemExitException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.