Example usage for java.lang StackTraceElement getClassName

List of usage examples for java.lang StackTraceElement getClassName

Introduction

In this page you can find the example usage for java.lang StackTraceElement getClassName.

Prototype

public String getClassName() 

Source Link

Document

Returns the fully qualified name of the class containing the execution point represented by this stack trace element.

Usage

From source file:com.opentable.jaxrs.exceptions.JsonMessageReaderMapper.java

@Override
public Response toResponse(JsonParseException exception) {
    for (StackTraceElement e : exception.getStackTrace()) {
        if (CLASS_NAMES.contains(e.getClassName())) {
            final Map<String, String> response = ImmutableMap.of("code", "400", "requestid",
                    MoreObjects.firstNonNull(MDC.get("requestid"), ""), "message",
                    MoreObjects.firstNonNull(exception.getMessage(), "(no message)"));

            return Response.status(400).entity(response).type(MediaType.APPLICATION_JSON_TYPE).build();
        }/*from  w w w  .  j  av a 2s  .co m*/
    }

    return super.toResponse(exception);
}

From source file:com.google.gdt.eclipse.designer.model.widgets.support.GwtState.java

/**
 * Extracts from stack trace name of class and method of test which creates this {@link GwtState}.
 *//* w ww .j a  v  a  2  s  .c  om*/
private static String findTestQualifiedName() {
    for (StackTraceElement element : Thread.currentThread().getStackTrace()) {
        String methodName = element.getMethodName();
        if (methodName.startsWith("test_")) {
            return element.getClassName() + "." + methodName;
        }
    }
    return "noTestMethod";
}

From source file:tools.datasync.db2db.util.ExceptionHandler.java

public void handle(Throwable ex, Level level, String message, Object... params) {

    // TODO: Log all caused by messages also...
    // TODO: Search tools.datasync.db2db package method and log 'at' here...
    StackTraceElement[] stackTraceElements = ex.getStackTrace();
    StackTraceElement top = stackTraceElements[0];

    String clazz = top.getClassName();
    String method = top.getMethodName();
    int line = top.getLineNumber();

    StringBuffer sb = new StringBuffer();
    sb.append(clazz);/*from ww w . j  av a2 s.c om*/
    sb.append('.');
    sb.append(method);
    sb.append('(');
    sb.append(line);
    sb.append(") : ");
    sb.append(message);
    sb.append(". ");
    sb.append(ex.getMessage());
    sb.append('\n');

    logger.log(level, sb.toString());
}

From source file:com.nesscomputing.jersey.exceptions.JsonMessageReaderMapper.java

@Override
public Response toResponse(JsonParseException exception) {
    for (StackTraceElement e : exception.getStackTrace()) {
        if (CLASS_NAMES.contains(e.getClassName())) {
            final Map<String, String> response = ImmutableMap.of("code", "400", "trace",
                    ObjectUtils.toString(MDC.get("track")), "message",
                    ObjectUtils.toString(exception.getMessage(), "(no message)"));

            return Response.status(400).entity(response).type(MediaType.APPLICATION_JSON_TYPE).build();
        }/*w ww . j  a  v  a 2s  . co m*/
    }

    return super.toResponse(exception);
}

From source file:com.dinstone.ut.faststub.internal.StubMethodInvocation.java

private String getResourcePath(Method method, StackTraceElement callTrace) {
    return callTrace.getClassName().replace('.', '/') + "/" + callTrace.getMethodName() + "/"
            + stubClass.getSimpleName() + ".xml";
}

From source file:org.gradle.util.TemporaryFolder.java

private String determinePrefix() {
    StackTraceElement[] stackTrace = new RuntimeException().getStackTrace();
    for (StackTraceElement element : stackTrace) {
        if (element.getClassName().endsWith("Test")) {
            return StringUtils.substringAfterLast(element.getClassName(), ".") + "/unknown-test";
        }/*ww  w .ja v a 2  s.c  om*/
    }
    return "unknown-test-class";
}

From source file:org.eclipse.epp.internal.logging.aeri.ui.log.StandInStacktraceProvider.java

private int findCutOffIndex(StackTraceElement[] stackframes, Set<String> blacklistedClassNames) {
    for (int i = 0; i < stackframes.length; i++) {
        StackTraceElement current = stackframes[i];
        if (!blacklistedClassNames.contains(current.getClassName())) {
            return i;
        }//from   w ww  . j  a v a2s  .  co m
    }
    return 0;
}

From source file:com.cloud.utils.log.CglibThrowableRenderer.java

/**
 * This method adds the stack traces retrieved from {@link Throwable#getStackTrace()}
 * The maxNumberOfStack attribute indicates the number of stacks that will be added,
 * if that value is 0, then all of the stack traces will be added, otherwise the stack traces will be limited to that number
 * @param th//from   w  w  w  .jav a  2s  . c  o  m
 * @param lines
 * @param maxNumberOfStack
 */
private void addStackTraceToList(Throwable th, List<String> lines, int maxNumberOfStack) {
    StackTraceElement[] elements = th.getStackTrace();
    if (maxNumberOfStack == 0 || maxNumberOfStack > elements.length) {
        maxNumberOfStack = elements.length;
    }
    for (int i = 0; i < maxNumberOfStack; i++) {
        StackTraceElement element = elements[i];
        if (StringUtils.contains(element.getClassName(), "net.sf.cglib.proxy")) {
            continue;
        }
        lines.add("\tat " + element.toString());
    }
    if (maxNumberOfStack < elements.length) {
        lines.add("\t... " + (elements.length - maxNumberOfStack) + " more");
    }
}

From source file:com.krawler.portal.util.ByteArrayMaker.java

private void _getInfo(Throwable t) {
    _initSize = buf.length;/*w  ww.  ja v a  2 s.  c o m*/

    StackTraceElement[] elements = t.getStackTrace();

    if (elements.length > 1) {
        StackTraceElement el = elements[1];

        _caller = el.getClassName() + StringPool.PERIOD + el.getMethodName() + StringPool.COLON
                + el.getLineNumber();
    }
}

From source file:com.dinstone.ut.faststub.internal.StubMethodInvocation.java

private StackTraceElement findCaller() {
    StackTraceElement[] stackTraces = Thread.currentThread().getStackTrace();
    for (StackTraceElement trace : stackTraces) {
        if (trace.getClassName().endsWith("Test") && trace.getMethodName().startsWith("test")) {
            return trace;
        }/*from   w w  w  .  java 2  s . c om*/
    }

    throw new RuntimeException(
            "Test class name must be 'Test' as a suffix, the test method must start with 'test' prefix.");
}