List of usage examples for java.lang StackTraceElement getFileName
public String getFileName()
From source file:com.bstek.dorado.view.task.LongTaskThread.java
public ExceptionInfo(Exception e) { Throwable throwable = e;/*from www . j a v a2 s . co m*/ // while (throwable.getCause() != null) { // throwable = throwable.getCause(); // } message = throwable.getMessage(); if (message == null) { message = throwable.getClass().getSimpleName(); } StackTraceElement[] stackTraceElements = throwable.getStackTrace(); stackTrace = new String[stackTraceElements.length]; int i = 0; for (StackTraceElement stackTraceElement : stackTraceElements) { stackTrace[i] = stackTraceElement.getClassName() + '.' + stackTraceElement.getMethodName() + '(' + stackTraceElement.getFileName() + ':' + stackTraceElement.getLineNumber() + ')'; i++; } }
From source file:org.openflamingo.remote.thrift.thriftfs.ThriftHandlerBase.java
/** * Return a list of threads that currently exist with their stack traces *//*w w w.j a v a 2s . c o m*/ public List<ThreadStackTrace> getThreadDump(RequestContext ctx) { List<ThreadStackTrace> dump = new ArrayList<ThreadStackTrace>(); Map<Thread, StackTraceElement[]> traces = Thread.getAllStackTraces(); for (Map.Entry<Thread, StackTraceElement[]> entry : traces.entrySet()) { final Thread t = entry.getKey(); final StackTraceElement[] frames = entry.getValue(); ThreadStackTrace tst = new ThreadStackTrace(); tst.threadName = t.getName(); tst.threadStringRepresentation = String.valueOf(t); tst.isDaemon = t.isDaemon(); tst.stackTrace = new ArrayList<StackTraceElement>(); for (StackTraceElement ste : frames) { StackTraceElement tFrame = new StackTraceElement(); tFrame.className = ste.getClassName(); tFrame.fileName = ste.getFileName(); tFrame.lineNumber = ste.getLineNumber(); tFrame.methodName = ste.getMethodName(); tFrame.isNativeMethod = ste.isNativeMethod(); tFrame.stringRepresentation = String.valueOf(ste); tst.stackTrace.add(tFrame); } dump.add(tst); } return dump; }
From source file:org.stenerud.kscrash.KSCrash.java
/** Report a Java exception. * * @param exception The exception./*from w w w . j a va 2 s . com*/ */ public void reportJavaException(Throwable exception) { try { JSONArray array = new JSONArray(); for (StackTraceElement element : exception.getStackTrace()) { JSONObject object = new JSONObject(); object.put("file", element.getFileName()); object.put("line", element.getLineNumber()); object.put("class", element.getClassName()); object.put("method", element.getMethodName()); object.put("native", element.isNativeMethod()); array.put(object); } reportUserException(exception.getClass().getName(), exception.getMessage(), "java", exception.getStackTrace()[0].getFileName(), exception.getStackTrace()[0].getLineNumber(), array, false, false); } catch (JSONException e) { e.printStackTrace(); } }
From source file:org.vulpe.controller.struts.interceptor.VulpeExceptionMappingInterceptor.java
/** * * @param invocation// ww w .j a va2s.c om * @param exception * @return */ protected String treatExceptionMessage(final ActionInvocation invocation, final Throwable exception) { final VulpeStrutsController<?, ?> action = (VulpeStrutsController<?, ?>) invocation.getAction(); final Throwable cause = getCause(exception); String message = cause.getMessage(); String key = exception.getClass().getName(); if (cause instanceof JspException) { key = cause.getClass().getName(); } else if (cause instanceof SQLException) { key = cause.getClass().getName(); } message = action.vulpe.controller().text(key); final String contactAdministratorMessageKey = "vulpe.error.contact.system.administrator"; message += action.vulpe.controller().text(contactAdministratorMessageKey); if (isDebug(action)) { final String errorOccurrenceDebugKey = "vulpe.error.occurrence.debug"; message += action.vulpe.controller().text(errorOccurrenceDebugKey); if (exception instanceof NullPointerException) { final StackTraceElement ste = exception.getStackTrace()[0]; final String fileName = ste.getFileName().replace(".java", ""); final String methodName = ste.getMethodName(); final int lineNumber = ste.getLineNumber(); message += action.vulpe.controller().text(key + ".debug", fileName, methodName, lineNumber); } else { message += "<i>" + (exception instanceof VulpeValidationException ? "entity" : cause.getMessage()) + "</i>"; } } return message; }
From source file:org.openmrs.module.privilegehelper.PrivilegeLogger.java
/** * Inspects the stack trace to find a place where the privilege was checked * /*w w w . j a va 2 s . co m*/ * @return the class.method or <code>null</code> if it cannot be found */ private StackTraceInfo inspectStackTrace() { final StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace(); boolean requiredPrivilege = false; for (int i = 0; i < stackTrace.length; i++) { final StackTraceElement unrelatedElement = stackTrace[i]; if (UserContext.class.getName().equals(unrelatedElement.getClassName()) && "hasPrivilege".equals(unrelatedElement.getMethodName())) { for (int j = i + 1; j < stackTrace.length; j++) { final StackTraceElement element = stackTrace[j]; if (element.getFileName() != null && element.getFileName().endsWith("_jsp")) { String jsp = element.getFileName(); int indexOfView = jsp.indexOf("view"); if (indexOfView > 0) { jsp = jsp.substring(indexOfView); } jsp = jsp.replace(".", "/"); jsp = jsp.replace("_", "."); return new StackTraceInfo(jsp, requiredPrivilege); } if (!element.getClassName().startsWith("org.openmrs")) { continue; } //Determine if it is a required privilege or a simple check if (RequireTag.class.getName().equals(element.getClassName())) { requiredPrivilege = true; continue; } if (PrivilegeTag.class.getName().equals(element.getClassName())) { requiredPrivilege = false; continue; } if (AuthorizationAdvice.class.getName().equals(element.getClassName())) { requiredPrivilege = true; continue; } if (Context.class.getName().equals(element.getClassName())) { if ("requirePrivilege".equals(element.getMethodName())) { requiredPrivilege = true; } continue; } try { final Class<?> clazz = OpenmrsClassLoader.getInstance().loadClass(element.getClassName()); if (clazz.isAnnotationPresent(Controller.class)) { String url = ""; final RequestMapping clazzRequestMapping = clazz.getAnnotation(RequestMapping.class); if (clazzRequestMapping != null) { url = clazzRequestMapping.value()[0]; } final Method[] methods = clazz.getMethods(); for (Method method : methods) { if (method.getName().equals(element.getMethodName())) { final RequestMapping requestMapping = method .getAnnotation(RequestMapping.class); if (requestMapping != null) { url += requestMapping.value()[0]; } break; } } if (url.isEmpty()) { return new StackTraceInfo(element.toString(), requiredPrivilege); } else { return new StackTraceInfo(element.toString() + ", URL: " + url, requiredPrivilege); } } } catch (ClassNotFoundException e) { } return new StackTraceInfo(element.toString(), requiredPrivilege); } } } return null; }
From source file:org.collectionspace.chain.csp.webui.main.StreamUIRequest.java
private void exception_to_text_internal(StringBuffer buf, Throwable e) { buf.append("Exception " + e.getClass() + " thrown message=\"" + e.getMessage() + "\"\n"); for (StackTraceElement el : e.getStackTrace()) { buf.append(el.getClassName() + " " + el.getMethodName() + " (" + el.getFileName() + ":" + el.getLineNumber() + ")\n"); }//from w w w . j a v a2s . c om Throwable next = e.getCause(); if (next != null && next != e) { buf.append("Caused by:\n"); exception_to_text_internal(buf, next); } }
From source file:org.jtrfp.trcl.flow.GameShell.java
private void throwable2StringBuilder(Throwable e, StringBuilder sb) { assert e != null; assert sb != null; sb.append(e.getClass().getName() + " " + e.getLocalizedMessage() + "\n"); final StackTraceElement[] stackTraceElements = e.getStackTrace(); for (StackTraceElement ste : stackTraceElements) sb.append("\tat " + ste.getClassName() + "." + ste.getMethodName() + "(" + ste.getFileName() + ":" + ste.getLineNumber() + ")\n"); }
From source file:com.chenxin.authority.common.logback.DBAppender.java
void bindCallerDataWithPreparedStatement(PreparedStatement stmt, StackTraceElement[] callerDataArray) throws SQLException { StackTraceElement callerData = callerDataArray[0]; if (callerData != null) { stmt.setString(CALLER_FILENAME_INDEX, callerData.getFileName()); stmt.setString(CALLER_CLASS_INDEX, callerData.getClassName()); stmt.setString(CALLER_METHOD_INDEX, callerData.getMethodName()); stmt.setString(CALLER_LINE_INDEX, Integer.toString(callerData.getLineNumber())); }//from w ww .j a v a 2 s . c o m }
From source file:adalid.core.XS1.java
static boolean checkAccess() { String method;/*w w w .j a va 2s . c o m*/ String caller = null; final StackTraceElement[] stack = Thread.currentThread().getStackTrace(); for (StackTraceElement element : stack) { method = element.getClassName() + "." + element.getMethodName(); if (caller == null) { if (method.startsWith(ROOT_PACKAGE) && !method.startsWith(THIS_CLASS)) { caller = method; } } else if (method.startsWith(ROOT_PACKAGE)) { break; } else { String message = "illegal invocation of \"" + StringUtils.substringAfterLast(caller, ".") + "\""; message += " at " + method + "(" + element.getFileName() + ":" + element.getLineNumber() + ")"; throw new IllegalAccessRuntimeException(message); } } return caller != null; }
From source file:com.altoros.layout.JSONLayout.java
/** * Converts LoggingEvent Throwable to JSON object * @param json/*from w w w .j a va 2 s . c o 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); } }