Example usage for javax.naming ServiceUnavailableException getMessage

List of usage examples for javax.naming ServiceUnavailableException getMessage

Introduction

In this page you can find the example usage for javax.naming ServiceUnavailableException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.apache.openejb.config.Undeploy.java

public static void main(final String[] args) throws SystemExitException {

    final CommandLineParser parser = new PosixParser();

    // create the Options
    final Options options = new Options();
    options.addOption(Undeploy.option("v", "version", "cmd.deploy.opt.version"));
    options.addOption(Undeploy.option("h", "help", "cmd.undeploy.opt.help")); // TODO this message doesn't exist
    options.addOption(Undeploy.option("s", "server-url", "url", "cmd.deploy.opt.server"));

    CommandLine line = null;//from   ww  w  . ja  v  a 2  s .  c  o  m
    try {
        // parse the command line arguments
        line = parser.parse(options, args);
    } catch (final 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;
    }

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

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

    Deployer deployer = null;
    try {
        final InitialContext ctx = new InitialContext(p);
        deployer = (Deployer) ctx.lookup("openejb/DeployerBusinessRemote");
    } catch (final ServiceUnavailableException e) {
        System.out.println(e.getCause().getMessage());
        System.out.println(Undeploy.messages.format("cmd.deploy.serverOffline"));
        throw new SystemExitException(-1);
    } catch (final 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 (final Object obj : line.getArgList()) {
        final String moduleId = (String) obj;

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

    if (exitCode != 0) {
        throw new SystemExitException(exitCode);
    }
}