Example usage for java.lang Throwable getClass

List of usage examples for java.lang Throwable getClass

Introduction

In this page you can find the example usage for java.lang Throwable getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:com.zimbra.cs.account.ProvUtil.java

public static void main(String args[]) throws IOException, ServiceException {
    CliUtil.setCliSoapHttpTransportTimeout();
    ZimbraLog.toolSetupLog4jConsole("INFO", true, false); // send all logs to stderr
    SocketFactories.registerProtocols();

    SoapTransport.setDefaultUserAgent("zmprov", BuildInfo.VERSION);

    ProvUtil pu = new ProvUtil();
    CommandLineParser parser = new PosixParser();
    Options options = new Options();

    options.addOption("h", "help", false, "display usage");
    options.addOption("f", "file", true, "use file as input stream");
    options.addOption("s", "server", true, "host[:port] of server to connect to");
    options.addOption("l", "ldap", false, "provision via LDAP");
    options.addOption("L", "logpropertyfile", true, "log4j property file");
    options.addOption("a", "account", true, "account name (not used with --ldap)");
    options.addOption("p", "password", true, "password for account");
    options.addOption("P", "passfile", true, "filename with password in it");
    options.addOption("z", "zadmin", false,
            "use zimbra admin name/password from localconfig for account/password");
    options.addOption("v", "verbose", false, "verbose mode");
    options.addOption("d", "debug", false, "debug mode (SOAP request and response payload)");
    options.addOption("D", "debughigh", false, "debug mode (SOAP req/resp payload and http headers)");
    options.addOption("m", "master", false, "use LDAP master (has to be used with --ldap)");
    options.addOption("t", "temp", false,
            "write binary values to files in temporary directory specified in localconfig key zmprov_tmp_directory");
    options.addOption("r", "replace", false, "allow replacement of multi-valued attr value");
    options.addOption("fd", "forcedisplay", false, "force display attr value");
    options.addOption(SoapCLI.OPT_AUTHTOKEN);
    options.addOption(SoapCLI.OPT_AUTHTOKENFILE);

    CommandLine cl = null;// w ww.java 2  s . c o  m
    boolean err = false;

    try {
        cl = parser.parse(options, args, true);
    } catch (ParseException pe) {
        printError("error: " + pe.getMessage());
        err = true;
    }

    if (err || cl.hasOption('h')) {
        pu.usage();
    }

    if (cl.hasOption('l') && cl.hasOption('s')) {
        printError("error: cannot specify both -l and -s at the same time");
        System.exit(2);
    }

    pu.setVerbose(cl.hasOption('v'));
    if (cl.hasOption('l')) {
        pu.setUseLdap(true, cl.hasOption('m'));
    }

    if (cl.hasOption('L')) {
        if (cl.hasOption('l')) {
            ZimbraLog.toolSetupLog4j("INFO", cl.getOptionValue('L'));
        } else {
            printError("error: cannot specify -L when -l is not specified");
            System.exit(2);
        }
    }

    if (cl.hasOption('z')) {
        pu.setAccount(LC.zimbra_ldap_user.value());
        pu.setPassword(LC.zimbra_ldap_password.value());
    }

    if (cl.hasOption(SoapCLI.O_AUTHTOKEN) && cl.hasOption(SoapCLI.O_AUTHTOKENFILE)) {
        printError("error: cannot specify " + SoapCLI.O_AUTHTOKEN + " when " + SoapCLI.O_AUTHTOKENFILE
                + " is specified");
        System.exit(2);
    }
    if (cl.hasOption(SoapCLI.O_AUTHTOKEN)) {
        ZAuthToken zat = ZAuthToken.fromJSONString(cl.getOptionValue(SoapCLI.O_AUTHTOKEN));
        pu.setAuthToken(zat);
    }
    if (cl.hasOption(SoapCLI.O_AUTHTOKENFILE)) {
        String authToken = StringUtil.readSingleLineFromFile(cl.getOptionValue(SoapCLI.O_AUTHTOKENFILE));
        ZAuthToken zat = ZAuthToken.fromJSONString(authToken);
        pu.setAuthToken(zat);
    }

    if (cl.hasOption('s')) {
        pu.setServer(cl.getOptionValue('s'));
    }
    if (cl.hasOption('a')) {
        pu.setAccount(cl.getOptionValue('a'));
    }
    if (cl.hasOption('p')) {
        pu.setPassword(cl.getOptionValue('p'));
    }
    if (cl.hasOption('P')) {
        pu.setPassword(StringUtil.readSingleLineFromFile(cl.getOptionValue('P')));
    }

    if (cl.hasOption('d') && cl.hasOption('D')) {
        printError("error: cannot specify both -d and -D at the same time");
        System.exit(2);
    }
    if (cl.hasOption('D')) {
        pu.setDebug(SoapDebugLevel.high);
    } else if (cl.hasOption('d')) {
        pu.setDebug(SoapDebugLevel.normal);
    }

    if (!pu.useLdap() && cl.hasOption('m')) {
        printError("error: cannot specify -m when -l is not specified");
        System.exit(2);
    }

    if (cl.hasOption('t')) {
        pu.setOutputBinaryToFile(true);
    }

    if (cl.hasOption('r')) {
        pu.setAllowMultiValuedAttrReplacement(true);
    }

    if (cl.hasOption("fd")) {
        pu.setForceDisplayAttrValue(true);
    }

    args = recombineDecapitatedAttrs(cl.getArgs(), options, args);

    try {
        if (args.length < 1) {
            pu.initProvisioning();
            InputStream is = null;
            if (cl.hasOption('f')) {
                pu.setBatchMode(true);
                is = new FileInputStream(cl.getOptionValue('f'));
            } else {
                if (LC.command_line_editing_enabled.booleanValue()) {
                    try {
                        CliUtil.enableCommandLineEditing(LC.zimbra_home.value() + "/.zmprov_history");
                    } catch (IOException e) {
                        errConsole.println("Command line editing will be disabled: " + e);
                        if (pu.verboseMode) {
                            e.printStackTrace(errConsole);
                        }
                    }
                }

                // This has to happen last because JLine modifies System.in.
                is = System.in;
            }
            pu.interactive(new BufferedReader(new InputStreamReader(is, "UTF-8")));
        } else {
            Command cmd = pu.lookupCommand(args[0]);
            if (cmd == null) {
                pu.usage();
            }
            if (cmd.isDeprecated()) {
                pu.deprecated();
            }
            if (pu.forceLdapButDontRequireUseLdapOption(cmd)) {
                pu.setUseLdap(true, false);
            }

            if (pu.needProvisioningInstance(cmd)) {
                pu.initProvisioning();
            }

            try {
                if (!pu.execute(args)) {
                    pu.usage();
                }
            } catch (ArgException e) {
                pu.usage();
            }
        }
    } catch (ServiceException e) {
        Throwable cause = e.getCause();
        String errText = "ERROR: " + e.getCode() + " (" + e.getMessage() + ")" + (cause == null ? ""
                : " (cause: " + cause.getClass().getName() + " " + cause.getMessage() + ")");

        printError(errText);

        if (pu.verboseMode) {
            e.printStackTrace(errConsole);
        }
        System.exit(2);
    }
}

From source file:Main.java

public static void onError(String tag, Throwable e) {
    Log.e(tag, e.getClass().getSimpleName() + ": " + e.getLocalizedMessage());
}

From source file:Main.java

public static String getStackTraceAsString(Throwable e) {
    String stackTraceString = e.getClass().getName() + ": " + e.getMessage();
    for (StackTraceElement ste : e.getStackTrace()) {
        stackTraceString += "\n" + ste.toString();
    }/*  ww  w  . j  av  a  2s  .  c o m*/
    return stackTraceString;
}

From source file:Main.java

public static String dumpException(Throwable e) {
    StringWriter sw = new StringWriter(160);
    sw.write(e.getClass().getName());
    sw.write(":\n");
    e.printStackTrace(new PrintWriter(sw));
    return sw.toString();
}

From source file:com.notonthehighstreet.ratel.internal.model.Error.java

public static Error fromException(final Throwable e) {
    return new Error(e.getClass().getName(), e.getMessage(), unwrapStackTrace(e));
}

From source file:Main.java

/**
 * dump the exception to string/*from  w ww  . ja v a 2  s  .c  o  m*/
 */
public static String dumpException(Throwable throwable) {
    StringWriter stringWriter = new StringWriter(160);
    stringWriter.write(throwable.getClass().getName());
    stringWriter.write(":\n");
    throwable.printStackTrace(new PrintWriter(stringWriter));
    return stringWriter.toString();
}

From source file:Main.java

public static String toString(Throwable e) {
    StringWriter w = new StringWriter();
    PrintWriter p = new PrintWriter(w);
    p.print(e.getClass().getName() + ": ");
    if (e.getMessage() != null) {
        p.print(e.getMessage() + "\n");
    }/*  w w  w.ja  v a 2  s.co  m*/
    p.println();
    try {
        e.printStackTrace(p);
        return w.toString();
    } finally {
        p.close();
    }
}

From source file:com.ethercamp.harmony.desktop.DesktopUtil.java

/**
 * Find initial exception by visiting//  ww  w  .  jav a2s .  c  o m
 */
public static Throwable findCauseFromSpringException(Throwable e) {
    final List<Class<? extends Exception>> skipList = Arrays.asList(BeansException.class,
            EmbeddedServletContainerException.class, ApplicationContextException.class);

    for (int i = 0; i < 50; i++) {
        final Throwable inner = e;
        final boolean isSkipped = skipList.stream().anyMatch(c -> c.isAssignableFrom(inner.getClass()));
        if (isSkipped) {
            e = e.getCause();
        } else {
            return e;
        }
    }
    return e;
}

From source file:com.biglakesystems.biglib.quality.Exceptions.java

/**
 * Generate a unique identifier for an exception. Combines the exception class name, identity hash code, and an
 * ever-incrementing sequence value into a string and then performs a SHA-1 hash of that string, returning the hex
 * hash.//from w w w .j  av  a2s .  c  om
 *
 * @param exception the exception.
 * @return {@link String} unique identifier.
 */
private static String newUniqueId(final Throwable exception) {
    final String content = String.format("%s_%08x_%08x", exception.getClass().getName(),
            System.identityHashCode(exception), s_nextIdSequence.getAndIncrement());
    return DigestUtils.sha1Hex(content);
}

From source file:Main.java

public static String toString(Throwable error) {
    StringBuffer buf = new StringBuffer(512);
    while (error != null) {
        buf.append(error.getClass().getName());
        buf.append(error.getMessage() == null ? "" : error.getMessage());
        buf.append("\r\n");
        StackTraceElement[] stack = error.getStackTrace();
        for (int i = 0; i < stack.length; i++) {
            buf.append("   ");
            buf.append(stack[i].toString());
            buf.append("\r\n");
        }// w w  w.j  a  v  a  2  s.  c  o m
        if (error.getCause() != null) {
            buf.append("\r\nCaused by :");
        }
        error = error.getCause();
    }
    return buf.toString();
}