List of usage examples for java.lang StackTraceElement toString
public String toString()
From source file:com.quinsoft.zeidon.dbhandler.PessimisticLockingViaDb.java
/** * Adds a string to the locking table that is a partial call stack. * * @param cursor//from w w w .j ava 2 s . c om */ private void addCallStack(EntityCursor cursor) { EntityDef zeidonLock = cursor.getEntityDef(); AttributeDef callStackAttr = zeidonLock.getAttribute("CallStack", false); if (callStackAttr == null || callStackAttr.isHidden()) return; StringBuilder sb = new StringBuilder(); int count = 0; StackTraceElement[] stack = new RuntimeException().getStackTrace(); for (StackTraceElement element : stack) { String classname = element.getClassName(); if (classname.startsWith("com.quinsoft.zeidon")) continue; sb.append(element.toString()).append("\n"); if (++count > 5) break; } // Make sure the string lenth isn't too long. int lth = cursor.getAttribute("CallStack").getAttributeDef().getLength(); if (sb.length() > lth) sb.setLength(lth); cursor.getAttribute("CallStack").setValue(sb.toString()); }
From source file:at.tugraz.ist.catroweb.BaseTest.java
private String getCalleeName() { StackTraceElement[] stack = Thread.currentThread().getStackTrace(); for (StackTraceElement item : stack) { String entry = item.toString(); if (entry.matches("at.tugraz.ist.catroweb.*") && !entry.matches("at.tugraz.ist.catroweb.BaseTest.*")) { return item.getMethodName(); }// w w w .j a v a2 s .c o m } return null; }
From source file:at.ac.tuwien.infosys.jcloudscale.server.JCloudScaleServer.java
void logException(Throwable e) { StackTraceElement[] trace = e.getStackTrace(); StringBuilder sb = new StringBuilder(); sb.append("Exception Trace\n"); sb.append(e.getClass().getName() + ": "); if (e.getMessage() != null) sb.append(e.getMessage() + "\n"); for (StackTraceElement el : trace) { sb.append("\tat " + el.toString()); sb.append("\n"); }// w w w .java 2 s . c o m this.log.severe(sb.toString()); }
From source file:org.apache.tajo.worker.TajoWorker.java
public void dumpThread(Writer writer) { PrintWriter stream = new PrintWriter(writer); int STACK_DEPTH = 20; boolean contention = threadBean.isThreadContentionMonitoringEnabled(); long[] threadIds = threadBean.getAllThreadIds(); stream.println("Process Thread Dump: Tajo Worker"); stream.println(threadIds.length + " active threads"); for (long tid : threadIds) { ThreadInfo info = threadBean.getThreadInfo(tid, STACK_DEPTH); if (info == null) { stream.println(" Inactive"); continue; }/* w ww .j a va 2s . co m*/ stream.println("Thread " + getThreadTaskName(info.getThreadId(), info.getThreadName()) + ":"); Thread.State state = info.getThreadState(); stream.println(" State: " + state + ", Blocked count: " + info.getBlockedCount() + ", Waited count: " + info.getWaitedCount()); if (contention) { stream.println( " Blocked time: " + info.getBlockedTime() + ", Waited time: " + info.getWaitedTime()); } if (state == Thread.State.WAITING) { stream.println(" Waiting on " + info.getLockName()); } else if (state == Thread.State.BLOCKED) { stream.println(" Blocked on " + info.getLockName() + ", Blocked by " + getThreadTaskName(info.getLockOwnerId(), info.getLockOwnerName())); } stream.println(" Stack:"); for (StackTraceElement frame : info.getStackTrace()) { stream.println(" " + frame.toString()); } stream.println(""); } }
From source file:de.eonas.opencms.parserimpl.RelativePortalURLImpl.java
/** * Converts to a string representing the portal URL. * * @return a string representing the portal URL. * @see PortalURLParserImpl#toString(org.apache.pluto.driver.url.PortalURL) *///from w w w . j a v a2 s . co m public String toURL(boolean absolute) { if (urlParser == null) { if (stackTrace != null) { StringBuilder sb = new StringBuilder(); for (StackTraceElement element : stackTrace) { sb.append(element.toString()); sb.append("\n"); } System.out.println("Recorded construction-trace: " + sb.toString()); } else { System.out.println("No stack trace recorded."); } urlParser = PortalURLParserImpl.getParser(); } return urlParser.toString(this); }
From source file:edu.uiowa.icts.bluebutton.controller.ClinicalDocumentController.java
@ResponseBody @RequestMapping(value = "datatable", produces = "application/json") public String datatable(HttpServletRequest request, @RequestParam(value = "personId", required = false) Integer personId, @RequestParam(value = "length", required = false) Integer limit, @RequestParam(value = "start", required = false) Integer start, @RequestParam(value = "draw", required = false) String draw, @RequestParam(value = "search[regex]", required = false, defaultValue = "false") Boolean searchRegularExpression, @RequestParam(value = "search[value]", required = false) String search, @RequestParam(value = "columnCount", required = false, defaultValue = "0") Integer columnCount, @RequestParam(value = "individualSearch", required = false, defaultValue = "false") Boolean individualSearch, @RequestParam(value = "display", required = false, defaultValue = "list") String display) { List<DataTableHeader> headers = new ArrayList<DataTableHeader>(); for (int i = 0; i < columnCount; i++) { DataTableHeader dth = new DataTableHeader(); dth.setData(Integer.valueOf(request.getParameter("columns[" + i + "][data]"))); dth.setName(request.getParameter("columns[" + i + "][name]")); dth.setOrderable(Boolean.valueOf(request.getParameter("columns[" + i + "][orderable]"))); dth.setSearchable(Boolean.valueOf(request.getParameter("columns[" + i + "][searchable]"))); dth.setSearchValue(request.getParameter("columns[" + i + "][search][value]")); dth.setSearchRegex(Boolean.valueOf(request.getParameter("columns[" + i + "][search][regex]"))); headers.add(dth);//ww w. j av a 2 s.c o m } ArrayList<SortColumn> sorts = new ArrayList<SortColumn>(); JSONObject ob = new JSONObject(); try { for (int i = 0; i < columnCount; i++) { Integer columnIndex = null; String columnIndexString = request.getParameter("order[" + i + "][column]"); if (columnIndexString != null) { try { columnIndex = Integer.parseInt(columnIndexString); } catch (NumberFormatException e) { continue; } if (columnIndex != null) { if (StringUtils.equalsIgnoreCase("person", headers.get(columnIndex).getName())) { sorts.add(new SortColumn("person.lastName", request.getParameter("order[" + i + "][dir]"))); sorts.add(new SortColumn("person.firstName", request.getParameter("order[" + i + "][dir]"))); } else { sorts.add(new SortColumn(headers.get(columnIndex).getName(), request.getParameter("order[" + i + "][dir]"))); } } } } GenericDaoListOptions options = new GenericDaoListOptions(); List<Alias> aliases = new ArrayList<Alias>(); aliases.add(new Alias("person", "person")); options.setAliases(aliases); Map<String, Object> individualEquals = new HashMap<String, Object>(); if (personId != null) { individualEquals.put("person.personId", personId); } options.setIndividualEquals(individualEquals); if (!individualSearch) { ArrayList<String> searchColumns = new ArrayList<String>(); for (int i = 0; i < columnCount; i++) { if (headers.get(i).getSearchable()) { if (StringUtils.equalsIgnoreCase("person", headers.get(i).getName())) { searchColumns.add("person.lastName"); searchColumns.add("person.firstName"); } else { searchColumns.add(headers.get(i).getName()); } } } options.setSearch(search); options.setSearchColumns(searchColumns); } else { List<Junction> disjunctions = new ArrayList<Junction>(); for (DataTableHeader header : headers) { if (header.getSearchable() && header.getSearchValue() != null && !StringUtils.equals("", header.getSearchValue().trim())) { for (String splitColumnValue : StringUtils.split(header.getSearchValue().trim(), ' ')) { Disjunction disjunction = Restrictions.disjunction(); if (StringUtils.equalsIgnoreCase("person", header.getName())) { disjunction .add(Restrictions.ilike("person.lastName", "%" + splitColumnValue + "%")); disjunction .add(Restrictions.ilike("person.firstName", "%" + splitColumnValue + "%")); } else { disjunction.add(Restrictions.ilike(header.getName(), "%" + splitColumnValue + "%")); } disjunctions.add(disjunction); } } } options.setJunctions(disjunctions); } Integer count = bluebuttonDaoService.getClinicalDocumentService().count(options); options.setLimit(limit); options.setStart(start); options.setSorts(sorts); List<ClinicalDocument> clinicalDocumentList = bluebuttonDaoService.getClinicalDocumentService() .list(options); ob.put("draw", draw); ob.put("recordsFiltered", count); ob.put("recordsTotal", count); JSONArray jsonArray = new JSONArray(); for (ClinicalDocument clinicalDocument : clinicalDocumentList) { JSONArray tableRow = new JSONArray(); for (DataTableHeader header : headers) { String headerName = header.getName(); if (StringUtils.equals("clinicalDocumentId", headerName)) { tableRow.put(clinicalDocument.getClinicalDocumentId()); } else if (StringUtils.equals("document", headerName)) { tableRow.put(clinicalDocument.getDocument()); } else if (StringUtils.equals("name", headerName)) { tableRow.put(clinicalDocument.getName()); } else if (StringUtils.equals("source", headerName)) { tableRow.put(clinicalDocument.getSource()); } else if (StringUtils.equals("description", headerName)) { tableRow.put(clinicalDocument.getDescription()); } else if (StringUtils.equals("dateUploaded", headerName)) { tableRow.put(clinicalDocument.getDateUploaded()); } else if (StringUtils.equals("jsonParserVersion", headerName)) { tableRow.put(clinicalDocument.getJsonParserVersion()); } else if (StringUtils.equals("person", headerName)) { String toPut = ""; if (clinicalDocument.getPerson() != null) { toPut = clinicalDocument.getPerson().getLastName() + ", " + clinicalDocument.getPerson().getFirstName(); } tableRow.put(toPut); } else if (StringUtils.equals("urls", headerName)) { String urls = ""; if (StringUtils.equals("list", display)) { urls += "<a href=\"show?" + "clinicalDocumentId=" + clinicalDocument.getClinicalDocumentId() + "\"><span class=\"glyphicon glyphicon-eye-open\"></a> "; urls += "<a href=\"edit?" + "clinicalDocumentId=" + clinicalDocument.getClinicalDocumentId() + "\"><span class=\"glyphicon glyphicon-pencil\"></a> "; urls += "<a href=\"delete?" + "clinicalDocumentId=" + clinicalDocument.getClinicalDocumentId() + "\"><span class=\"glyphicon glyphicon-trash\"></a>"; } else if (StringUtils.equals("person", display)) { urls += "<a href=\"" + request.getContextPath() + "/clinicaldocument/show.html?clinicalDocumentId=" + clinicalDocument.getClinicalDocumentId() + "\">[view]</a>"; } else { } tableRow.put(urls); } else { tableRow.put("[error: column " + headerName + " not supported]"); } } jsonArray.put(tableRow); } ob.put("data", jsonArray); } catch (Exception e) { log.error("error builing datatable json object for ClinicalDocument", e); try { String stackTrace = e.getMessage() + String.valueOf('\n'); for (StackTraceElement ste : e.getStackTrace()) { stackTrace += ste.toString() + String.valueOf('\n'); } ob = new JSONObject(); ob.put("draw", draw); ob.put("recordsFiltered", 0); ob.put("recordsTotal", 0); ob.put("error", stackTrace); } catch (JSONException je) { log.error("error building json error object for ClinicalDocument", je); } } return ob.toString(); }
From source file:org.sugarcrm.voodoodriver.Reporter.java
/** * Log the exception only./*w ww .ja va2s. c o m*/ * * This helper routine is needed since some of the Reporter methods * could need to report an exception. * */ private void justReportTheException(Exception e) { this.Exceptions += 1; if (e.getMessage() == null) { this._log("(!)ReportException: Exception message is null!"); } else { this._log("(!)" + e.getMessage().replaceAll("\\n", " ")); } String bt = "--Exception Backtrace: "; for (StackTraceElement el : e.getStackTrace()) { bt += "--" + el.toString(); } this._log("(!)" + bt); }
From source file:org.jahia.tools.jvm.ThreadMonitor.java
private void printThreadInfo(ThreadInfo ti, StringBuilder dump) { // print thread information printThread(ti, dump);/* w w w .j a v a2 s . c om*/ // print stack trace with locks StackTraceElement[] stacktrace = ti.getStackTrace(); for (int i = 0; i < stacktrace.length; i++) { StackTraceElement ste = stacktrace[i]; dump.append(INDENT + "at " + ste.toString()); dump.append("\n"); } dump.append("\n"); }
From source file:edu.umn.cs.spatialHadoop.nasa.ShahedServer.java
private void reportError(HttpServletResponse response, String msg, Exception e) throws IOException { if (e != null) e.printStackTrace();/*from w w w . j a v a 2 s. c o m*/ LOG.error(msg); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); response.getWriter().println("{\"message\": '" + msg + "',"); if (e != null) { response.getWriter().println("\"error\": '" + e.getMessage() + "',"); response.getWriter().println("\"stacktrace\": ["); for (StackTraceElement trc : e.getStackTrace()) { response.getWriter().println("'" + trc.toString() + "',"); } response.getWriter().println("]"); } response.getWriter().println("}"); }
From source file:org.ScripterRon.JavaBitcoin.RpcHandler.java
/** * Process 'getstacktraces' request//from w w w.j a va 2s . c o m * * Response parameters: * locks - An array of lock objects for locks with waiters * threads - An array of thread objects * * Lock object: * name - Lock class name * hash - Lock identity hash code * thread - Identifier of thread holding the lock * * Monitor object: * name - Monitor class name * hash - Monitor identity hash * depth - Stack depth where monitor locked * trace - Stack element where monitor locked * * Thread object: * blocked - Lock object if thread is waiting on a lock * id - Thread identifier * locks - Array of monitor objects for locks held by this thread * name - Thread name * state - Thread state * trace - Array of stack trace elements * * @return Response as a JSONObject */ private JSONObject getStackTraces() { JSONArray threadsJSON = new JSONArray(); JSONArray locksJSON = new JSONArray(); ThreadMXBean tmxBean = ManagementFactory.getThreadMXBean(); boolean tmxMI = tmxBean.isObjectMonitorUsageSupported(); ThreadInfo[] tList = tmxBean.dumpAllThreads(tmxMI, false); // // Generate the response // for (ThreadInfo tInfo : tList) { JSONObject threadJSON = new JSONObject(); // // General thread information // threadJSON.put("id", tInfo.getThreadId()); threadJSON.put("name", tInfo.getThreadName()); threadJSON.put("state", tInfo.getThreadState().toString()); // // Gather lock usage // if (tmxMI) { MonitorInfo[] mList = tInfo.getLockedMonitors(); if (mList.length > 0) { JSONArray monitorsJSON = new JSONArray(); for (MonitorInfo mInfo : mList) { JSONObject lockJSON = new JSONObject(); lockJSON.put("name", mInfo.getClassName()); lockJSON.put("hash", mInfo.getIdentityHashCode()); lockJSON.put("depth", mInfo.getLockedStackDepth()); lockJSON.put("trace", mInfo.getLockedStackFrame().toString()); monitorsJSON.add(lockJSON); } threadJSON.put("locks", monitorsJSON); } if (tInfo.getThreadState() == Thread.State.BLOCKED) { LockInfo lInfo = tInfo.getLockInfo(); if (lInfo != null) { JSONObject lockJSON = new JSONObject(); lockJSON.put("name", lInfo.getClassName()); lockJSON.put("hash", lInfo.getIdentityHashCode()); lockJSON.put("thread", tInfo.getLockOwnerId()); threadJSON.put("blocked", lockJSON); boolean addLock = true; for (Object lock : locksJSON) { if (((String) ((JSONObject) lock).get("name")).equals(lInfo.getClassName())) { addLock = false; break; } } if (addLock) locksJSON.add(lockJSON); } } } // // Add the stack trace // StackTraceElement[] elements = tInfo.getStackTrace(); JSONArray traceJSON = new JSONArray(); for (StackTraceElement element : elements) traceJSON.add(element.toString()); threadJSON.put("trace", traceJSON); // // Add the thread to the response // threadsJSON.add(threadJSON); } // // Return the response // JSONObject response = new JSONObject(); response.put("threads", threadsJSON); response.put("locks", locksJSON); return response; }