List of usage examples for java.lang StackTraceElement toString
public String toString()
From source file:edu.uiowa.icts.bluebutton.controller.LabTestController.java
@ResponseBody @RequestMapping(value = "datatable", produces = "application/json") public String datatable(HttpServletRequest request, @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(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);// w w w . j a v a 2 s . co 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) { sorts.add(new SortColumn(headers.get(columnIndex).getName(), request.getParameter("order[" + i + "][dir]"))); } } } GenericDaoListOptions options = new GenericDaoListOptions(); if (!individualSearch) { ArrayList<String> searchColumns = new ArrayList<String>(); for (int i = 0; i < columnCount; i++) { if (headers.get(i).getSearchable()) { searchColumns.add(headers.get(i).getName()); } } options.setSearch(search); options.setSearchColumns(searchColumns); } else { Map<String, Object> likes = new HashMap<String, Object>(); for (DataTableHeader header : headers) { if (header.getSearchable() && header.getSearchValue() != null) { for (String splitColumnValue : StringUtils.split(header.getSearchValue().trim(), ' ')) { likes.put(header.getName(), splitColumnValue); } } } options.setIndividualLikes(likes); } Integer count = bluebuttonDaoService.getLabTestService().count(options); options.setLimit(limit); options.setStart(start); options.setSorts(sorts); List<LabTest> labTestList = bluebuttonDaoService.getLabTestService().list(options); ob.put("draw", draw); ob.put("recordsFiltered", count); ob.put("recordsTotal", count); JSONArray jsonArray = new JSONArray(); for (LabTest labTest : labTestList) { JSONArray tableRow = new JSONArray(); for (DataTableHeader header : headers) { String headerName = header.getName(); if (StringUtils.equals("labTestId", headerName)) { tableRow.put(labTest.getLabTestId()); } else if (StringUtils.equals("name", headerName)) { tableRow.put(labTest.getName()); } else if (StringUtils.equals("description", headerName)) { tableRow.put(labTest.getDescription()); } else if (StringUtils.equals("units", headerName)) { tableRow.put(labTest.getUnits()); } else if (StringUtils.equals("loincCode", headerName)) { tableRow.put(labTest.getLoincCode()); } else if (StringUtils.equals("dateCreated", headerName)) { tableRow.put(labTest.getDateCreated()); } else if (StringUtils.equals("dateUpdated", headerName)) { tableRow.put(labTest.getDateUpdated()); } else if (StringUtils.equals("labTestRanges", headerName)) { tableRow.put(labTest.getLabTestRanges().size()); } else if (StringUtils.equals("urls", headerName)) { String urls = ""; if (StringUtils.equals("list", display)) { urls += "<a href=\"show?" + "labTestId=" + labTest.getLabTestId() + "\"><span class=\"glyphicon glyphicon-eye-open\"></a>"; // urls += "<a href=\"edit?"+"labTestId="+labTest.getLabTestId()+"\"><span class=\"glyphicon glyphicon-pencil\"></a>"; urls += "<a href=\"delete?" + "labTestId=" + labTest.getLabTestId() + "\"><span class=\"glyphicon glyphicon-trash\"></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 LabTest", 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 LabTest", je); } } return ob.toString(); }
From source file:be.ppareit.swiftp.server.CmdAbstractStore.java
public void doStorOrAppe(String param, boolean append) { Log.d(TAG, "STOR/APPE executing with append=" + append); File storeFile = inputPathToChrootedFile(sessionThread.getWorkingDir(), param); String errString = null;// ww w . j a v a2 s . com //OutputStream out = null; FileOutputStream out = null; // DedicatedWriter dedicatedWriter = null; // int origPriority = Thread.currentThread().getPriority(); // myLog.l(Log.DEBUG, "STOR original priority: " + origPriority); storing: { // Get a normalized absolute path for the desired file if (violatesChroot(storeFile)) { errString = "550 Invalid name or chroot violation\r\n"; break storing; } if (storeFile.isDirectory()) { errString = "451 Can't overwrite a directory\r\n"; break storing; } if ((sessionThread.offset >= 0) && (append)) { errString = "555 Append can not be used after a REST command\r\n"; break storing; } try { if (storeFile.exists()) { if (!append) { if (!FileUtil.deleteFile(storeFile, App.getAppContext())) { errString = "451 Couldn't truncate file\r\n"; break storing; } // Notify other apps that we just deleted a file MediaUpdater.notifyFileDeleted(storeFile.getPath()); } } if (!storeFile.exists()) { FileUtil.mkfile(storeFile, App.getAppContext()); } out = FileUtil.getOutputStream(storeFile, App.getAppContext()); //file if (sessionThread.offset <= 0) { out.getChannel().position(storeFile.length()); //out = new FileOutputStream(storeFile, append); } else if (sessionThread.offset == storeFile.length()) { out.getChannel().position(storeFile.length()); //out = new FileOutputStream(storeFile, true); } else { out.getChannel().position(sessionThread.offset); // final RandomAccessFile raf = new RandomAccessFile(storeFile, "rw"); // raf.seek(sessionThread.offset); // out = new OutputStream() { // @Override // public void write(int oneByte) throws IOException { // raf.write(oneByte); // } // // @Override // public void close() throws IOException { // raf.close(); // } // }; } } catch (FileNotFoundException e) { Log.e(TAG, "error : ", e); try { errString = "451 Couldn't open file \"" + param + "\" aka \"" + storeFile.getCanonicalPath() + "\" for writing\r\n"; } catch (IOException io_e) { errString = "451 Couldn't open file, nested exception\r\n"; } break storing; } catch (IOException e) { errString = "451 Unable to seek in file to append\r\n"; break storing; } if (!sessionThread.openDataSocket()) { errString = "425 Couldn't open data socket\r\n"; break storing; } Log.d(TAG, "Data socket ready"); sessionThread.writeString("150 Data socket ready\r\n"); byte[] buffer = new byte[SessionThread.DATA_CHUNK_SIZE]; // dedicatedWriter = new DedicatedWriter(out); // dedicatedWriter.start(); // start the writer thread executing // myLog.l(Log.DEBUG, "Started DedicatedWriter"); int numRead; // Thread.currentThread().setPriority(Thread.MIN_PRIORITY); // int newPriority = Thread.currentThread().getPriority(); // myLog.l(Log.DEBUG, "New STOR prio: " + newPriority); if (sessionThread.isBinaryMode()) { Log.d(TAG, "Mode is binary"); } else { Log.d(TAG, "Mode is ascii"); } while (true) { /* * if(dedicatedWriter.checkErrorFlag()) { errString = * "451 File IO problem\r\n"; break storing; } */ switch (numRead = sessionThread.receiveFromDataSocket(buffer)) { case -1: Log.d(TAG, "Returned from final read"); // We're finished reading break storing; case 0: errString = "426 Couldn't receive data\r\n"; break storing; case -2: errString = "425 Could not connect data socket\r\n"; break storing; default: try { // Log.d(TAG, "Enqueueing buffer of " + numRead); // dedicatedWriter.enqueueBuffer(buffer, numRead); if (sessionThread.isBinaryMode()) { out.write(buffer, 0, numRead); } else { // ASCII mode, substitute \r\n to \n int startPos = 0, endPos; for (endPos = 0; endPos < numRead; endPos++) { if (buffer[endPos] == '\r') { out.write(buffer, startPos, endPos - startPos); // Our hacky method is to drop all \r startPos = endPos + 1; } } // Write last part of buffer as long as there was something // left after handling the last \r if (startPos < numRead) { out.write(buffer, startPos, endPos - startPos); } } // Attempted bugfix for transfer stalls. Reopen file periodically. // bytesSinceReopen += numRead; // if(bytesSinceReopen >= Defaults.bytes_between_reopen && // Defaults.do_reopen_hack) { // Log.d(TAG, "Closing and reopening file: " + storeFile); // out.close(); // out = new FileOutputStream(storeFile, true/*append*/); // bytesSinceReopen = 0; // } // Attempted bugfix for transfer stalls. Flush file periodically. // bytesSinceFlush += numRead; // if(bytesSinceFlush >= Defaults.bytes_between_flush && // Defaults.do_flush_hack) { // Log.d(TAG, "Flushing: " + storeFile); // out.flush(); // bytesSinceFlush = 0; // } // If this transfer fails, a later APPEND operation might be // received. In that case, we will need to have flushed the // previous writes in order for the append to work. The // filesystem on my G1 doesn't seem to recognized unflushed // data when appending. //out.flush(); } catch (IOException e) { errString = "451 File IO problem. Device might be full.\r\n"; Log.d(TAG, "Exception while storing: " + e); Log.d(TAG, "Message: " + e.getMessage()); Log.d(TAG, "Stack trace: "); StackTraceElement[] traceElems = e.getStackTrace(); for (StackTraceElement elem : traceElems) { Log.d(TAG, elem.toString()); } break storing; } break; } } } // // Clean up the dedicated writer thread // if(dedicatedWriter != null) { // dedicatedWriter.exit(); // set its exit flag // dedicatedWriter.interrupt(); // make sure it wakes up to process the flag // } // Thread.currentThread().setPriority(origPriority); try { // if(dedicatedWriter != null) { // dedicatedWriter.exit(); // } if (out != null) { out.close(); } } catch (IOException e) { } if (errString != null) { Log.i(TAG, "STOR error: " + errString.trim()); sessionThread.writeString(errString); } else { sessionThread.writeString("226 Transmission complete\r\n"); // Notify the music player (and possibly others) that a few file has // been uploaded. MediaUpdater.notifyFileCreated(storeFile.getPath()); } sessionThread.closeDataSocket(); Log.d(TAG, "STOR finished"); }
From source file:edu.uiowa.icts.bluebutton.controller.PersonController.java
@ResponseBody @RequestMapping(value = "datatable", produces = "application/json") public String datatable(HttpServletRequest request, @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(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);/*from ww w . ja v a 2 s. com*/ } 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) { sorts.add(new SortColumn(headers.get(columnIndex).getName(), request.getParameter("order[" + i + "][dir]"))); } } } GenericDaoListOptions options = new GenericDaoListOptions(); if (!individualSearch) { ArrayList<String> searchColumns = new ArrayList<String>(); for (int i = 0; i < columnCount; i++) { if (headers.get(i).getSearchable()) { searchColumns.add(headers.get(i).getName()); } } options.setSearch(search); options.setSearchColumns(searchColumns); } else { Map<String, List<Object>> likes = new HashMap<String, List<Object>>(); for (DataTableHeader header : headers) { if (header.getSearchable() && header.getSearchValue() != null) { List<Object> values = new ArrayList<Object>(); for (String splitColumnValue : StringUtils.split(header.getSearchValue().trim(), ' ')) { values.add(splitColumnValue.trim()); } likes.put(header.getName(), values); } } options.setLikes(likes); } Integer count = bluebuttonDaoService.getPersonService().count(options); options.setLimit(limit); options.setStart(start); options.setSorts(sorts); List<Person> personList = bluebuttonDaoService.getPersonService().list(options); ob.put("draw", draw); ob.put("recordsFiltered", count); ob.put("recordsTotal", count); JSONArray jsonArray = new JSONArray(); for (Person person : personList) { JSONArray tableRow = new JSONArray(); for (DataTableHeader header : headers) { String headerName = header.getName(); if (StringUtils.equals("personId", headerName)) { tableRow.put(person.getPersonId()); } else if (StringUtils.equals("firstName", headerName)) { tableRow.put(person.getFirstName()); } else if (StringUtils.equals("middleName", headerName)) { tableRow.put(person.getMiddleName()); } else if (StringUtils.equals("lastName", headerName)) { tableRow.put(person.getLastName()); } else if (StringUtils.equals("dateOfBirth", headerName)) { tableRow.put(person.getDateOfBirth()); } else if (StringUtils.equals("addressLineOne", headerName)) { tableRow.put(person.getAddressLineOne()); } else if (StringUtils.equals("addressLineTwo", headerName)) { tableRow.put(person.getAddressLineTwo()); } else if (StringUtils.equals("city", headerName)) { tableRow.put(person.getCity()); } else if (StringUtils.equals("state", headerName)) { tableRow.put(person.getState()); } else if (StringUtils.equals("zipcode", headerName)) { tableRow.put(person.getZipcode()); } else if (StringUtils.equals("country", headerName)) { tableRow.put(person.getCountry()); } else if (StringUtils.equals("email", headerName)) { tableRow.put(person.getEmail()); } else if (StringUtils.equals("registrationDate", headerName)) { tableRow.put(person.getRegistrationDate()); } else if (StringUtils.equals("firstLogin", headerName)) { tableRow.put(person.getFirstLogin()); } else if (StringUtils.equals("lastLogin", headerName)) { tableRow.put(person.getLastLogin()); } else if (StringUtils.equals("lastUpdated", headerName)) { tableRow.put(person.getLastUpdated()); } else if (StringUtils.equals("signature", headerName)) { tableRow.put(person.getSignature()); } else if (StringUtils.equals("clinicalDocuments", headerName)) { tableRow.put(person.getClinicalDocuments().size()); } else if (StringUtils.equals("urls", headerName)) { String urls = ""; if (StringUtils.equals("list", display)) { urls += "<a href=\"show?" + "personId=" + person.getPersonId() + "\"><span class=\"glyphicon glyphicon-eye-open\"></a>"; urls += "<a href=\"edit?" + "personId=" + person.getPersonId() + "\"><span class=\"glyphicon glyphicon-pencil\"></a>"; // urls += "<a href=\"delete?"+"personId="+person.getPersonId()+"\"><span class=\"glyphicon glyphicon-trash\"></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 Person", e); try { String stackTrace = e.getMessage() + String.valueOf('\n'); for (StackTraceElement ste : e.getStackTrace()) { stackTrace += ste.toString() + String.valueOf('\n'); } JSONObject error = new JSONObject(); error.put("draw", draw); error.put("recordsFiltered", 0); error.put("recordsTotal", 0); error.put("error", stackTrace); return error.toString(); } catch (JSONException je) { log.error("error building json error object for Person", je); } } return ob.toString(); }
From source file:com.fanniemae.ezpie.LogManager.java
public void addErrorMessage(Throwable ex, Boolean isInner) { String logGroup = isInner ? "" : "** ERROR **"; String inner = isInner ? "Inner " : ""; if (ex == null) { updateLog(true, "", inner + "Exception Type", "null - no details available."); return;//from w w w. j a v a 2 s . co m } String message = ex.getMessage(); if (StringUtilities.isNullOrEmpty(message)) { message = "See stack trace for error details."; } updateLog(true, logGroup, inner + "Message", message); String exceptionName = ex.getClass().getName(); if (!"java.lang.RuntimeException".equals(exceptionName) && !exceptionName.contains("PieException")) { updateLog(true, "", inner + "Exception Type", exceptionName); } StringBuilder sbStack = new StringBuilder(); boolean addLinebreak = false; for (StackTraceElement ele : ex.getStackTrace()) { if (addLinebreak) { sbStack.append(getNewLineTab()); } sbStack.append(ele.toString()); addLinebreak = true; } updateLog(true, "", inner + "Details", sbStack.toString()); Throwable innerException = ex.getCause(); if (innerException != null) { addErrorMessage(innerException, true); } }
From source file:com.strandls.alchemy.rest.client.AlchemyRestClientFactoryTest.java
/** * Test method for/*from w ww . jav a 2 s. com*/ * {@link com.strandls.alchemy.rest.client.AlchemyRestClientFactory#getInstance(java.lang.Class, java.lang.String, javax.ws.rs.client.Client)} * . * * Test generic exception is relayed correctly without loosing message. * * @throws Exception */ @Test public void testExceptionMapping() throws Exception { final TestWebserviceExceptionHandling service = clientFactory .getInstance(TestWebserviceExceptionHandling.class); try { service.fail(); fail("Should have thrown an exception"); } catch (final Exception e) { assertEquals(TestWebserviceExceptionHandling.EXCEPTION_STRING, e.getMessage()); // ensure the mixin got applied assertNull(e.getCause()); // ensure server stack trace is masked. // will have local stack trace though. final StackTraceElement[] stackTrace = e.getStackTrace(); for (final StackTraceElement stackTraceElement : stackTrace) { assertFalse(stackTraceElement.toString() .contains(TestWebserviceExceptionHandling.class.getName() + ".fail")); } assertEquals(0, e.getSuppressed().length); } }
From source file:com.strandls.alchemy.rest.client.AlchemyRestClientFactoryTest.java
/** * Test method for/*from w w w . ja v a2 s. c om*/ * {@link com.strandls.alchemy.rest.client.AlchemyRestClientFactory#getInstance(java.lang.Class, java.lang.String, javax.ws.rs.client.Client)} * . * * Test custom exception is relayed correctly without loosing message and * internal fields. * * @throws Exception */ @Test public void testExceptionMappingCustomException() throws Exception { final TestWebserviceExceptionHandling service = clientFactory .getInstance(TestWebserviceExceptionHandling.class); try { service.failWithACustomException(); fail("Should have thrown an exception"); } catch (final TestCustomException e) { assertEquals(10, e.getStatusCode()); // ensure the mixin got applied assertNull(e.getCause()); // ensure server stack trace is masked. // will have local stack trace though. final StackTraceElement[] stackTrace = e.getStackTrace(); for (final StackTraceElement stackTraceElement : stackTrace) { assertFalse(stackTraceElement.toString() .contains(TestWebserviceExceptionHandling.class.getName() + ".failWithACustomException")); } assertEquals(0, e.getSuppressed().length); } }
From source file:eu.europa.esig.dss.DSSUtils.java
/** * This method returns the summary of the given exception. The analysis of the stack trace stops when the provided class is found. * * @param exception//from w w w . jav a2s . c o m * {@code Exception} to summarize * @param javaClass * {@code Class} * @return {@code String} containing the summary message */ public static String getSummaryMessage(final Exception exception, final Class<?> javaClass) { final String javaClassName = javaClass.getName(); final StackTraceElement[] stackTrace = exception.getStackTrace(); String message = "See log file for full stack trace.\n"; message += exception.toString() + '\n'; for (StackTraceElement element : stackTrace) { final String className = element.getClassName(); if (className.equals(javaClassName)) { message += element.toString() + '\n'; break; } message += element.toString() + '\n'; } return message; }
From source file:Parallelizer.java
/** * Dump the stack of each running thread. * <p>/*from ww w . j a v a 2 s . c om*/ * If this method throws an error, that * error may be handled and this method * may be called again as it will not re-throw the same * instance of the error. * * @throws Error if any of the running threads has thrown an Error. * * @since ostermillerutils 1.05.00 */ public void dumpStack() { throwFirstError(); synchronized (runningThreads) { for (Thread thread : runningThreads) { for (StackTraceElement stackTraceElement : thread.getStackTrace()) { System.out.println(stackTraceElement.toString()); } throwFirstError(); } } }
From source file:be.wegenenverkeer.common.resteasy.exception.ExceptionUtil.java
/** * Get the stack trace as a string. Filters framework lines from the trace. * * @return stack trace//ww w. j av a2 s . c om */ public String getStackTrace() { StringBuilder sb = new StringBuilder(); Throwable exception = originalException; while (null != exception) { int filteredCount = 0; sb.append(exception.getMessage()).append('\n'); for (StackTraceElement ste : exception.getStackTrace()) { if (shouldDisplay(ste.getClassName())) { sb.append(" "); while (filteredCount > 0) { sb.append(','); filteredCount--; } sb.append(ste.toString()).append('\n'); } else { filteredCount++; } } exception = exception.getCause(); } return sb.toString(); }
From source file:com.evolveum.midpoint.schema.result.OperationResult.java
private static void dumpStackTrace(StringBuilder sb, StackTraceElement[] stackTrace, int indent) { for (int i = 0; i < stackTrace.length; i++) { for (int j = 0; j < indent; j++) { sb.append(INDENT_STRING);//from www . ja v a 2s.co m } StackTraceElement element = stackTrace[i]; sb.append(element.toString()); sb.append("\n"); } }