Example usage for java.lang Exception fillInStackTrace

List of usage examples for java.lang Exception fillInStackTrace

Introduction

In this page you can find the example usage for java.lang Exception fillInStackTrace.

Prototype

public synchronized Throwable fillInStackTrace() 

Source Link

Document

Fills in the execution stack trace.

Usage

From source file:lab.home.spring.redis.test.SpringRedisTest.java

public static void main(String argv[]) {

    ApplicationContext ctx = new AnnotationConfigApplicationContext(RedisTestConfig.class);
    DictionaryDao ddao = ctx.getBean(DictionaryDao.class);

    try {/*from   www.ja v  a2s . c  o  m*/
        System.out.println("ddao.setValue(\"key1\", \"value1\")");
        ddao.setValue("key1", "value1");
        System.out.println("ddao.setValue(\"testkey\", \"testvalue\")");
        ddao.setValue("testkey", "testvalue");
        System.out.println("getting value for key1 = " + ddao.getValue("key1"));
        System.out.println("getting value for testkey = " + ddao.getValue("testkey"));
    } catch (Exception e) {
        System.out.println(e);
        System.out.println(e.fillInStackTrace());
        System.out.println(e.getCause());
        System.out.println(e.getClass());
        System.out.println(e.getStackTrace());
        e.printStackTrace();
    }
}

From source file:uk.nhs.cfh.dsp.srth.distribution.FileDownloader.java

public static void main(String[] args) {
    FileDownloader fd = new FileDownloader();
    // check there are exactly four arguments
    if (args.length == 4) {
        String packPath = args[0];
        String packName = args[1];
        String userName = args[2];
        String pwd = args[3];// w ww . j a  va  2  s  .  c o m

        TRUDLoginService trudLoginService = new TRUDLoginService();
        fd.setPackPath(packPath);
        try {
            trudLoginService.authenticate(userName, pwd.toCharArray(), null);
            // dont have to validate again, because we checked in previous installation step
            fd.setFtpClient(trudLoginService.getFtpClient());
            // get file from trud
            fd.getFileFromTRUD(packName, System.getProperty("user.dir") + fd.SEPARATOR + "packs");
        } catch (Exception e) {
            logger.warning(ERR_MESSAGE + e.fillInStackTrace());
        }
    } else {
        logger.warning("Illegal number of arguments passed. Expected = 4. Passed = " + args.length);
    }
}

From source file:Main.java

/** Creates an prints a stack trace */
public static void printStackTrace() {
    Exception e = new Exception();
    e.fillInStackTrace();
    e.printStackTrace();// w w w  . j av  a 2s. c  om
}

From source file:org.lilyproject.util.Logs.java

public static void logThreadJoin(Thread thread) {
    Log log = LogFactory.getLog("org.lilyproject.threads.join");
    if (!log.isInfoEnabled()) {
        return;//from  w ww. jav a 2 s. co  m
    }

    String context = "";
    Exception e = new Exception();
    e.fillInStackTrace();
    StackTraceElement[] stackTrace = e.getStackTrace();
    if (stackTrace.length >= 2) {
        context = stackTrace[1].toString();
    }

    log.info("Waiting for thread to die: " + thread + " at " + context);
}

From source file:org.polymap.core.model.Messages.java

public static String getForClass(String keySuffix) {

    Exception e = new Exception();
    e.fillInStackTrace();
    StackTraceElement[] trace = e.getStackTrace();
    StackTraceElement elm = trace[trace.length - 1];

    StringBuffer key = new StringBuffer(64);
    key.append(StringUtils.substringAfterLast(elm.getClassName(), ".")).append("_").append(key);

    ClassLoader cl = Messages.class.getClassLoader();
    // getBundle() caches the bundles
    ResourceBundle bundle = ResourceBundle.getBundle(BUNDLE_NAME, RWT.getLocale(), cl);
    return bundle.getString(key.toString());
}

From source file:org.polymap.core.Messages.java

public static String getForClass(String keySuffix) {
    Exception e = new Exception();
    e.fillInStackTrace();
    StackTraceElement[] trace = e.getStackTrace();
    StackTraceElement elm = trace[trace.length - 1];

    StringBuffer key = new StringBuffer(64);
    key.append(StringUtils.substringAfterLast(elm.getClassName(), ".")).append("_").append(key);

    ClassLoader cl = Messages.class.getClassLoader();
    // getBundle() caches the bundles
    ResourceBundle bundle = ResourceBundle.getBundle(BUNDLE_NAME, RWT.getLocale(), cl);
    return bundle.getString(key.toString());
}

From source file:com.taobao.itest.matcher.AssertPropertiesEquals.java

/**
 * assertPropertiesEquals //www  .j  a v  a2 s. c om
 * Mainly used to compare two objects of the specified attribute value is equal,
 * to support complex type of attribute comparison
 * 
 * <li>Eg: Person class contains a type of property Address: 
 *          address, Address type contains a String property: street.<br>
 *     Then compare two Person objects are equal when the street can be written<br>
 *     AssertUtil.assertPropertiesEquals(person1,person2,"address.street")<br>
 *     Written about the time when the form<br>
 *     AssertUtil.assertPropertiesEquals(person1,person2,"address")<br>
 *     Can compare the address of each property is equal to
 * 
 * @param expect  Expect the object
 * @param actual  actual the object
 * @param propertyNames  Need to compare the property values,
 *           support for complex types, you can enter multiple comma-separated string, 
 *           you can also enter the array
 * 
 */
public static void assertPropertiesEquals(Object expect, Object actual, String... propertyNames) {
    Assert.assertNotNull("bean is null" + expect, expect);
    Assert.assertNotNull("bean is null" + actual, actual);
    //Assert.assertFalse("to compare the property is empty", ArrayUtils.isEmpty(propertyNames));
    Object valueExpect = null;
    Object valueActual = null;
    List<String> errorMessages = new ArrayList<String>();
    /*
     * If the attribute name is empty, then compare the two object
     * the current value of all the fields.
     * This parameter is empty,
     * the situation has in the upper control and verified directly through reflection
     */
    if (ArrayUtils.isEmpty(propertyNames)) {
        PropertyDescriptor[] props = BeanUtilsBean.getInstance().getPropertyUtils()
                .getPropertyDescriptors(expect);
        propertyNames = new String[props.length - 1];
        int j = 0;
        for (int i = 0; i < props.length; i++) {
            if (!props[i].getName().equals("class")) {
                propertyNames[j] = props[i].getName();
                j++;
            }
        }
    }
    //Cycle to compare different properties
    for (int i = 0; i < propertyNames.length; i++) {
        try {

            valueExpect = BeanUtilsBean.getInstance().getPropertyUtils().getProperty(expect, propertyNames[i]);
            valueActual = BeanUtilsBean.getInstance().getPropertyUtils().getProperty(actual, propertyNames[i]);
            if (valueExpect == null || valueActual == null)
                Assert.assertEquals(valueExpect, valueActual);
            else if (valueExpect.getClass().getName().startsWith("java.lang") || valueExpect instanceof Date) {
                Assert.assertEquals(valueExpect, valueActual);
                /*
                 * If taken out of the object is still a complex structure, 
                 * then the recursive call, then the property name set to null, 
                 * compare the value of all the attributes of the object
                 */
            } else {
                assertPropertiesEquals(valueExpect, valueActual);
            }
        } catch (Exception e) {
            throw new RuntimeException("error property" + propertyNames[i], e.fillInStackTrace());
        } catch (AssertionError err) {
            errorMessages.add("\nexpect property" + propertyNames[i] + " value is " + valueExpect
                    + "but actual value is" + valueActual);
            if (StringUtils.isNotBlank(err.getMessage())) {
                errorMessages.add("\ncaused by" + err.getMessage());
            }
        }
    }
    if (errorMessages.size() > 0) {
        throw new ComparisonFailure(errorMessages.toString(), "", "");
    }
}

From source file:com.bigtobster.pgnextractalt.commands.CommandContext.java

/**
 * Logs a severe error in logs/*from w w w . ja v  a  2  s  .c  o m*/
 *
 * @param logger    The erring class's Logger
 * @param message   The message to be logged
 * @param exception The exception causing the error
 */
@SuppressWarnings("SameParameterValue")
private static void logSevereError(@SuppressWarnings("SameParameterValue") final Logger logger,
        final String message, final Exception exception) {
    logger.log(Level.SEVERE, message);
    logger.log(Level.SEVERE, exception.getMessage());
    logger.log(Level.SEVERE, exception.toString(), exception.fillInStackTrace());
}

From source file:com.ailk.oci.ocnosql.tools.load.mutiple.MutipleColumnImportTsv.java

private static Object[] runJob(Configuration conf, String tableName, String inputPath, String tmpOutputPath)
        throws Exception {
    Long everyJobInputLine = 0L;// w w w  .j a  v a 2 s. c o  m
    Long everyJobOutputLine = 0L;
    Long everyJobBadLine = 0L;
    Job job = null;
    try {
        job = createSubmittableJob(conf, tableName, inputPath, tmpOutputPath);
    } catch (Exception e) {
        System.err.println(
                "ERROR:mutiplecolumn bulkload when create submittableJob error is :" + e.fillInStackTrace());
        return new Object[] { false, everyJobInputLine, everyJobOutputLine, everyJobBadLine };
    }
    boolean completion = false;
    try {
        if (job == null)
            return new Object[] { false, everyJobInputLine, everyJobOutputLine, everyJobBadLine };
        completion = job.waitForCompletion(true);
        everyJobBadLine = job.getCounters().getGroup("ImportTsv").findCounter("Bad Lines").getValue();
        everyJobInputLine = job.getCounters().getGroup("ImportTsv").findCounter("total Lines").getValue();
        everyJobOutputLine = everyJobInputLine - everyJobBadLine;
    } catch (Exception e) {
        System.err.println("ERROR:mutiplecolumn bulkload when execute Job error is :" + e.fillInStackTrace());
        return new Object[] { false, everyJobInputLine, everyJobOutputLine, everyJobBadLine };
    }
    try {
        if (completion && !StringUtils.isEmpty(tmpOutputPath)) {
            String[] toolRunnerArgs = new String[] { tmpOutputPath, tableName };
            int ret = ToolRunner.run(new LoadIncrementalHFiles(conf), toolRunnerArgs);
            return new Object[] { ret == 0, everyJobInputLine, everyJobOutputLine, everyJobBadLine };
        } else {
            return new Object[] { false, everyJobInputLine, everyJobOutputLine, everyJobBadLine };
        }
    } catch (Exception e) {
        System.err.println(
                "ERROR:mutiplecolumn bulkload when LoadIncrementalHFiles error is :" + e.fillInStackTrace());
        return new Object[] { false, everyJobInputLine, everyJobOutputLine, everyJobBadLine };
    }
}

From source file:com.ailk.oci.ocnosql.tools.load.single.SingleColumnImportTsv.java

private static boolean runJob(Configuration conf, String tableName, String inputPath, String tmpOutputPath) {
    Job job = null;/*w w w  . j  av a2 s.  c  o m*/
    try {
        job = createSubmittableJob(conf, tableName, inputPath, tmpOutputPath);
    } catch (Exception e) {
        System.err.println(
                "ERROR:singlecolumn bulkload when create submittableJob error is :" + e.fillInStackTrace());
        return false;
    }
    boolean completion = false;
    try {
        if (job == null)
            return false;
        completion = job.waitForCompletion(true);
    } catch (Exception e) {
        System.err.println("ERROR:singlecolumn bulkload when execute Job error is :" + e.fillInStackTrace());
        return false;
    }
    try {
        if (completion && !StringUtils.isEmpty(tmpOutputPath)) {
            String[] toolRunnerArgs = new String[] { tmpOutputPath, tableName };
            int ret = ToolRunner.run(new LoadIncrementalHFiles(conf), toolRunnerArgs);
            return ret == 0;
        } else {
            return false;
        }
    } catch (Exception e) {
        System.err.println(
                "ERROR:singlecolumn bulkload when LoadIncrementalHFiles error is :" + e.fillInStackTrace());
        return false;
    }
}