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:ma.glasnost.orika.test.converter.CloneableConverterNoSetAccessibleTestCase.java

@Test
public void cloneableConverterWithoutSetAccessible() throws DatatypeConfigurationException {

    final SecurityManager initialSm = System.getSecurityManager();
    try {// w ww. ja va  2  s .com
        System.setSecurityManager(new SecurityManager() {
            public void checkPermission(java.security.Permission perm) {
                if ("suppressAccessChecks".equals(perm.getName())) {
                    for (StackTraceElement ste : new Throwable().getStackTrace()) {
                        if (ste.getClassName().equals(CloneableConverter.class.getCanonicalName())) {
                            throw new SecurityException("not permitted");
                        }
                    }
                }
            }
        });

        CloneableConverter cc = new CloneableConverter(SampleCloneable.class);

        MapperFactory factory = MappingUtil.getMapperFactory();
        factory.getConverterFactory().registerConverter(cc);

        GregorianCalendar cal = new GregorianCalendar();
        cal.add(Calendar.YEAR, 10);
        XMLGregorianCalendar xmlCal = DatatypeFactory.newInstance()
                .newXMLGregorianCalendar((GregorianCalendar) cal);
        cal.add(Calendar.MONTH, 3);

        ClonableHolder source = new ClonableHolder();
        source.value = new SampleCloneable();
        source.value.id = 5L;
        source.date = new Date(System.currentTimeMillis() + 100000);
        source.timestamp = new Timestamp(System.currentTimeMillis() + 50000);
        source.calendar = cal;
        source.xmlCalendar = xmlCal;

        ClonableHolder dest = factory.getMapperFacade().map(source, ClonableHolder.class);
        Assert.assertEquals(source.value, dest.value);
        Assert.assertNotSame(source.value, dest.value);
        Assert.assertEquals(source.date, dest.date);
        Assert.assertNotSame(source.date, dest.date);
        Assert.assertEquals(source.timestamp, dest.timestamp);
        Assert.assertNotSame(source.timestamp, dest.timestamp);
        Assert.assertEquals(source.calendar, dest.calendar);
        Assert.assertNotSame(source.calendar, dest.calendar);
        Assert.assertEquals(source.xmlCalendar, dest.xmlCalendar);
        Assert.assertNotSame(source.xmlCalendar, dest.xmlCalendar);
    } finally {
        System.setSecurityManager(initialSm);
    }
}

From source file:com.chiorichan.factory.ScriptTraceElement.java

public ScriptTraceElement(ScriptingContext context, StackTraceElement ste) {
    this.context = context;
    fileName = ste.getFileName();/*from  w w w .ja v  a2s  .  c  o  m*/
    methodName = ste.getMethodName();
    className = ste.getClassName();
    lineNum = ste.getLineNumber();
    colNum = -1;
}

From source file:com.altoros.layout.JSONLayout.java

/**
 * Converts LoggingEvent Throwable to JSON object
 * @param json/*  w  w w. jav a  2 s.  co  m*/
 * @param event
 * @throws JSONException
 */
protected void writeThrowable(JSONObject json, LoggingEvent event) throws JSONException {
    ThrowableInformation ti = event.getThrowableInformation();
    if (ti != null) {
        Throwable t = ti.getThrowable();
        JSONObject throwable = new JSONObject();

        throwable.put("message", t.getMessage());
        throwable.put("className", t.getClass().getCanonicalName());
        List<JSONObject> traceObjects = new ArrayList<JSONObject>();
        for (StackTraceElement ste : t.getStackTrace()) {
            JSONObject element = new JSONObject();
            element.put("class", ste.getClassName());
            element.put("method", ste.getMethodName());
            element.put("line", ste.getLineNumber());
            element.put("file", ste.getFileName());
            traceObjects.add(element);
        }

        json.put("stackTrace", traceObjects);
        json.put("throwable", throwable);
    }
}

From source file:it.smartcommunitylab.aac.controller.BasicProfileController.java

@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ExceptionHandler(Exception.class)
@ResponseBody//ww  w  .j  ava 2 s  .  c o  m
ErrorInfo handleBadRequest(HttpServletRequest req, Exception ex) {
    StackTraceElement ste = ex.getStackTrace()[0];
    return new ErrorInfo(req.getRequestURL().toString(), ex.getClass().getTypeName(), ste.getClassName(),
            ste.getLineNumber());
}

From source file:org.coinspark.core.CSLogger.java

public String line(String Message, CSLevel Level, int depth) {
    String result = "";

    if (sdf != null) {
        result += sdf.format(new Date()) + "\t";
    }/*from www.j a  va2s. co m*/
    result += Level.getAbbr() + "\t";
    result += Message;

    if (depth > 0) {
        result += "\t";
        StackTraceElement ste = Thread.currentThread().getStackTrace()[depth];
        result += "[" + ste.getClassName() + "." + ste.getMethodName() + ", line " + ste.getLineNumber() + "]";
    }

    return result;
}

From source file:org.openbravo.event.RoleEventHandler.java

/**
 * Returns true if the Initial Client/Organization Setup is in the stack trace
 *//*w ww . java2 s .c o  m*/
private boolean isComingFromInitialClientOrganizationSetup() {
    boolean comeFrom_ICS_IOS = false;
    for (final StackTraceElement ste : Thread.currentThread().getStackTrace()) {
        final String clazz = ste.getClassName();
        if (StringUtils.equals(clazz, InitialOrgSetup_CLASSNAME)
                || StringUtils.equals(clazz, InitialClientSetup_CLASSNAME)) {
            comeFrom_ICS_IOS = true;
            logger.debug(
                    "Coming from Initial Client/Organization Setup. RoleEventHandler will not insert Org Access records");
            break;
        }
    }
    return comeFrom_ICS_IOS;
}

From source file:airbrake.Backtrace.java

private String toBacktrace(final StackTraceElement element) {
    return toBacktrace(element.getClassName(), element.getFileName(), element.getLineNumber(),
            element.getMethodName());/* w ww. j  av a  2s  . co m*/
}

From source file:org.uiautomation.ios.communication.FailedWebDriverLikeResponse.java

private JSONArray serializeStackTrace(StackTraceElement[] els) throws JSONException {
    JSONArray stacktace = new JSONArray();
    for (StackTraceElement el : els) {
        JSONObject stckEl = new JSONObject();
        stckEl.put("fileName", el.getFileName());
        stckEl.put("className", el.getClassName());
        stckEl.put("methodName", el.getMethodName());
        stckEl.put("lineNumber", el.getLineNumber());
        stacktace.put(stckEl);/*from   w  w  w . ja va  2  s. co m*/
    }
    return stacktace;
}

From source file:net.duckling.ddl.service.team.dao.VMTTeamManagerImpl.java

private boolean validateVmtDn(String vmtdn, String uid) {
    if (StringUtils.isEmpty(vmtdn)) {
        StackTraceElement[] s = Thread.currentThread().getStackTrace();
        StringBuilder sb = new StringBuilder();
        if (s != null) {
            for (StackTraceElement st : s) {
                sb.append(st.getClassName());
                sb.append(".");
                sb.append(st.getMethodName() + "(), line " + st.getLineNumber());
                sb.append("/r/n");
            }//from   w  w w. java2s  .  co  m
        }
        LOG.error("UID=" + uid + ";vmtdn=null/r/n" + sb.toString());
        return false;
    }
    return true;
}

From source file:org.siphon.jssp.JsspRunner.java

public void run(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {

    String requestPath = getServletPath(request);
    String jsfile = request.getServletContext().getRealPath(requestPath);
    ScriptObjectMirror d2js = null;/*from   w w  w . java 2  s.  c o  m*/
    try {
        d2js = d2jsManager.getD2js(jsfile, requestPath);
        if (d2js == null) {
            response.setStatus(404);
            PrintWriter out = response.getWriter();
            out.print(request.getServletPath() + " not found");
            out.flush();
            return;
        }
    } catch (Exception e3) {
        logger.error("", e3);
        throw new ServletException(e3);
    }

    JsspRequest jsspRequest = new JsspRequest(request, engine);

    String params;
    try {
        params = getParams(jsspRequest);
    } catch (Exception e3) {
        response.setStatus(500);
        PrintWriter out = response.getWriter();
        out.print("params must be json");
        out.flush();
        return;
    }

    JsspWriter out = null;
    out = new JsspWriter(response, engine);
    JsspSession session = new JsspSession(request.getSession());

    try {
        ((Invocable) engine).invokeFunction("processJsspRequest", jsfile, params, jsspRequest, response,
                session, out);
    } catch (NoSuchMethodException | ScriptException e) {
        if (out.isDirty()) {
            response.setStatus(500);
            for (Throwable throwable = e; throwable != null; throwable = throwable.getCause()) {
                if (e != throwable) {
                    out.print("<br>Caused By: " + throwable.getMessage() + "<br>");
                } else {
                    out.print("<br>" + throwable.getMessage() + "<br>");
                }
                for (StackTraceElement frame : throwable.getStackTrace()) {
                    out.print("&nbsp;&nbsp;&nbsp;&nbsp;at " + frame.getClassName() + "." + frame.getMethodName()
                            + "(" + frame.getFileName() + ":" + frame.getLineNumber() + ")<br>");
                }
            }
        }
        throw new ServletException(e);
    }
}