Example usage for javax.naming ServiceUnavailableException printStackTrace

List of usage examples for javax.naming ServiceUnavailableException printStackTrace

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:org.apache.openejb.assembler.classic.cmd.Info2Properties.java

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

    final CommandLineParser parser = new PosixParser();

    // create the Options
    final Options options = new Options();
    options.addOption(option("v", "version", "cmd.properties.opt.version"));
    options.addOption(option("h", "help", "cmd.properties.opt.help"));
    options.addOption(option("s", "server-url", "url", "cmd.properties.opt.server"));

    CommandLine line = null;//w  ww .  j  a va 2s .  c o m
    try {
        // parse the command line arguments
        line = parser.parse(options, args);
    } catch (final ParseException exp) {
        help(options);
        System.exit(-1);
    }

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

    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);

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

    File tempFile = null;
    try {
        try {
            tempFile = File.createTempFile("configrequest", "txt");
        } catch (final Throwable e) {
            final File tmp = new File("tmp");
            if (!tmp.exists() && !tmp.mkdirs()) {
                throw new IOException("Failed to create local tmp directory: " + tmp.getAbsolutePath());
            }

            tempFile = File.createTempFile("configrequest", "txt", tmp);

        }
        if (!tempFile.exists()) {
            throw new IllegalStateException("Failed to create tmp file: " + tempFile.getAbsolutePath());
        }
    } catch (final Exception e) {
        System.err.println("Temp file creation failed.");
        e.printStackTrace();
        System.exit(1);
    }

    OpenEjbConfiguration configuration = null;
    try {
        configuration = configInfo.getOpenEjbConfiguration(tempFile);
    } catch (final ConfigurationInfo.UnauthorizedException e) {
        System.err.println(
                "This tool is currently crippled to only work with server's on the same physical machine.  See this JIRA issue for details: http://issues.apache.org/jira/browse/OPENEJB-621");
        System.exit(10);
    }

    printConfig(configuration);
}