List of usage examples for org.apache.commons.lang3.exception ExceptionUtils getStackTrace
public static String getStackTrace(final Throwable throwable)
Gets the stack trace from a Throwable as a String.
The result of this method vary by JDK version as this method uses Throwable#printStackTrace(java.io.PrintWriter) .
From source file:io.cloudslang.content.utils.OutputUtilities.java
/** * Creates a Map<String, String> with the RETURN_CODE Failure(-1), RETURN_RESULT the <throwable> message and with EXCEPTION the full stackTrace of the <throwable> * * @param returnResult a specific error message * @param throwable Exception with the message for the RETURN_RESULT and the fullStackTrace for the EXCEPTION of the map * @return a Map<String, String> with the RETURN_CODE Failure(-1), RETURN_RESULT the <throwable> message and with EXCEPTION the full stackTrace of the <throwable> *///from w w w. j ava 2 s . c o m @NotNull public static Map<String, String> getFailureResultsMap(@NotNull final String returnResult, @NotNull final Throwable throwable) { final Map<String, String> results = new HashMap<>(); results.put(OutputNames.RETURN_CODE, ReturnCodes.FAILURE); results.put(OutputNames.RETURN_RESULT, returnResult); results.put(OutputNames.EXCEPTION, ExceptionUtils.getStackTrace(throwable)); return results; }
From source file:ke.co.tawi.babblesms.server.persistence.utils.ContactGroupUtil.java
/** * Assigns groups to contacts/* www . ja va 2 s.co m*/ * */ public void putContactsIntoGroups() { List<Contact> contactList = new LinkedList<>(); List<Group> groupList = new LinkedList<>(); // get all the accounts // get all contactgroup uuids for this account List<String> uuids = new LinkedList<>(); try (Connection conn = dbCredentials.getConnection(); PreparedStatement pstmt = conn.prepareStatement("SELECT uuid FROM contactgroup;");) { ResultSet rset = pstmt.executeQuery(); while (rset.next()) { uuids.add(rset.getString("uuid")); } } catch (SQLException e) { logger.error("SQLException when getting uuids of contactcontactgroup."); logger.error(ExceptionUtils.getStackTrace(e)); } // insert new associations in contactgroup table try (Connection conn = dbCredentials.getConnection(); PreparedStatement pstmt = conn.prepareStatement("INSERT INTO contactgroup " + "(uuid, contactuuid, groupuuid, accountuuid) VALUES (?,?,?,?);");) { groupList = groupDAO.getGroups(account); contactList = contactDAO.getContacts(account); // distribute contacts into groups in the ratio 7:2:1 int contactListSize = contactList.size(); // first portion of the ratio int firstPortion = (int) Math.floor(contactListSize * 0.7);// 7/10 for (int i = 0; i < firstPortion; i++) { pstmt.setString(1, UUID.randomUUID().toString()); pstmt.setString(2, contactList.get(i).getUuid()); pstmt.setString(3, groupList.get(3).getUuid()); pstmt.setString(4, account.getUuid()); pstmt.executeUpdate(); } // second portion of the ratio int secondPortion = firstPortion + (int) Math.floor(contactListSize * 0.2);// 2/10 for (int i = firstPortion; i < secondPortion; i++) { pstmt.setString(1, UUID.randomUUID().toString()); pstmt.setString(2, contactList.get(i).getUuid()); pstmt.setString(3, groupList.get(2).getUuid()); pstmt.setString(4, account.getUuid()); pstmt.executeUpdate(); } // third portion of the ratio for (int i = secondPortion; i < contactListSize; i++) { pstmt.setString(1, UUID.randomUUID().toString()); pstmt.setString(2, contactList.get(i).getUuid()); pstmt.setString(3, groupList.get(0).getUuid()); pstmt.setString(4, account.getUuid()); pstmt.executeUpdate(); } // put some contacts from one group into another group for (int i = firstPortion; i < secondPortion; i++) { pstmt.setString(1, UUID.randomUUID().toString()); pstmt.setString(2, contactList.get(i).getUuid()); pstmt.setString(3, groupList.get(0).getUuid()); pstmt.setString(4, account.getUuid()); pstmt.executeUpdate(); if (i == (secondPortion - 5)) break; } // put from contacts from one group into another group for (int i = secondPortion + 5; i < contactListSize; i++) { pstmt.setString(1, UUID.randomUUID().toString()); pstmt.setString(2, contactList.get(i).getUuid()); pstmt.setString(3, groupList.get(2).getUuid()); pstmt.setString(4, account.getUuid()); pstmt.executeUpdate(); if (i == 20) break; } } catch (SQLException e) { logger.error("SQLException while inserting new association in contactgroup table"); logger.error(ExceptionUtils.getStackTrace(e)); } }
From source file:com.aurel.track.admin.server.dbbackup.RestoreThread.java
@Override public void run() { try {/*from ww w . j a v a 2 s . c om*/ LOGGER.info("Starting RestoreThread..."); Date start = new Date(); if (includeAttachments) { DatabaseBackupBL.restoreDatabase(backupFile, driverClassName, url, user, password, attachmentDir); } else { DatabaseBackupBL.restoreDatabase(backupFile, driverClassName, url, user, password, null); } Date end = new Date(); LOGGER.info("Restore took " + (end.getTime() - start.getTime()) / 1000 + " seconds"); if (person != null) { LOGGER.debug("Sending email to:" + person.getFullName()); sendEmail(person, messageBody.toString()); } } catch (DatabaseBackupBLException e) { LOGGER.debug(ExceptionUtils.getStackTrace(e)); LOGGER.error("Something went wrong during restore: " + e.getMessage()); StringBuffer message = new StringBuffer(); if (e.getLocalizedKey() != null) { message.append( LocalizeUtil.getParametrizedString(e.getLocalizedKey(), e.getLocalizedParams(), locale)); } else { message.append(e.getMessage()); } if (e.getCause() != null) { message.append(":").append(e.getCause().getMessage()); } if (person != null) { sendEmail(person, message.toString()); } } finally { appBean.setRestoreInProgress(false); } }
From source file:com.turn.griffin.GriffinService.java
@RequestMapping(value = { "/localrepo", "/globalrepo" }, method = { RequestMethod.POST, RequestMethod.PUT }) public @ResponseBody String pushToRepo(@RequestParam(value = "blobname", required = true) String blobname, @RequestParam(value = "dest", required = true) String dest, @RequestParam(value = "file", required = true) MultipartFile file) { if (!StringUtils.isNotBlank(blobname)) { return "Blobname cannot be empty\n"; }//from w w w .java 2 s .c om if (!StringUtils.isNotBlank(dest)) { return "Dest cannot be empty\n"; } try { File tempFile = File.createTempFile("gfn", null, null); byte[] bytes = file.getBytes(); BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(tempFile)); stream.write(bytes); stream.close(); module.get().syncBlob(blobname, dest, tempFile.getAbsolutePath()); return String.format("Pushed file as blob %s to destination %s%n", blobname, dest); } catch (Exception e) { logger.error(String.format("POST request failed%n%s%n", ExceptionUtils.getStackTrace(e))); return String.format("Unable to push file as blob %s to destination %s%n", blobname, dest); } // TODO: Delete tempFile }
From source file:com.joyent.manta.exception.OnCloseAggregateException.java
/** * Adds an exception to the list of contextual parameters. * @param e exception to add/*from w w w . ja v a 2 s . c om*/ */ public void aggregateException(final Exception e) { String label = String.format("%03d_exception", count.incrementAndGet()); setContextValue(label, ExceptionUtils.getStackTrace(e)); }
From source file:ke.co.tawi.babblesms.server.persistence.template.MessageTemplateDAO.java
/** * *///from w ww . j av a 2 s . c om @Override public boolean put(MessageTemplate template) { boolean success = true; try (Connection conn = dbCredentials.getConnection(); PreparedStatement pstmt = conn.prepareStatement( "INSERT INTO MessageTemplate (Uuid,title,contents,accountuuid) VALUES (?,?,?,?);"); ) { pstmt.setString(1, template.getUuid()); pstmt.setString(2, template.getTitle()); pstmt.setString(3, template.getContents()); pstmt.setString(4, template.getAccountuuid()); System.out.println(template); pstmt.execute(); } catch (SQLException e) { logger.error("SQL Exception when trying to put messageTemplate: " + template); logger.error(ExceptionUtils.getStackTrace(e)); success = false; } return success; }
From source file:ke.co.tawi.babblesms.server.persistence.contacts.GroupDAO.java
/** * @see ke.co.tawi.babblesms.server.persistence.contacts.BabbleGroupDAO#getGroup(java.lang.String) */// www . ja va2 s . c om @Override public Group getGroup(String uuid) { Group group = null; try (Connection conn = dbCredentials.getConnection(); PreparedStatement pstmt = conn.prepareStatement("SELECT * FROM groups WHERE Uuid = ?;");) { pstmt.setString(1, uuid); try (ResultSet rset = pstmt.executeQuery()) { if (rset.next()) { group = beanProcessor.toBean(rset, Group.class); } } } catch (SQLException e) { logger.error("SQL Exception when getting Group with uuid: " + uuid); logger.error(ExceptionUtils.getStackTrace(e)); } return group; }
From source file:com.aurel.track.persist.TFilterCategoryPeer.java
/** * Loads a filterCategoryBean by primary key * @param objectID//from w w w. j a v a2 s . c o m * @return */ @Override public TFilterCategoryBean loadByPrimaryKey(Integer objectID) { TFilterCategory filterCategory = null; try { filterCategory = retrieveByPK(objectID); } catch (Exception e) { LOGGER.warn( "Loading of a filterCategory by primary key " + objectID + " failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } if (filterCategory != null) { return filterCategory.getBean(); } return null; }
From source file:com.aurel.track.fieldType.runtime.matchers.converter.DoubleMatcherConverter.java
/** * Convert the xml string to object value after load * @param value/*from w ww. j ava2 s .c o m*/ * @param matcherRelation * @return */ @Override public Object fromXMLString(String value, Integer matcherRelation) { if (value == null || "".equals(value) || matcherRelation == null) { return null; } switch (matcherRelation.intValue()) { case MatchRelations.EQUAL: case MatchRelations.NOT_EQUAL: case MatchRelations.GREATHER_THAN: case MatchRelations.GREATHER_THAN_EQUAL: case MatchRelations.LESS_THAN: case MatchRelations.LESS_THAN_EQUAL: try { return new Double(value); } catch (Exception e) { LOGGER.warn("Converting the " + value + " to Double from xml string failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } } return null; }
From source file:com.aurel.track.util.HTMLDiff.java
public static String makeDiff(String newValue, String oldValue, Locale locale) throws URISyntaxException { boolean htmlOut = true; if (newValue == null) { newValue = ""; } else {/*from ww w . ja v a 2 s . c o m*/ newValue = newValue.replaceAll(" ", " "); } if (oldValue == null || (oldValue != null && oldValue.length() == 0)) { return newValue; } else { oldValue = oldValue.replaceAll(" ", " "); } try { SAXTransformerFactory tf = (SAXTransformerFactory) TransformerFactory.newInstance(); TransformerHandler result = tf.newTransformerHandler(); StringWriter stringWriter = new StringWriter(); result.setResult(new StreamResult(stringWriter)); XslFilter filter = new XslFilter(); ContentHandler postProcess = htmlOut ? filter.xsl(result, "com/aurel/track/util/htmlheader.xsl") : result; String prefix = "diff"; HtmlCleaner cleaner = new HtmlCleaner(); InputSource oldSource = new InputSource(new StringReader(oldValue)); InputSource newSource = new InputSource(new StringReader(newValue)); DomTreeBuilder oldHandler = new DomTreeBuilder(); cleaner.cleanAndParse(oldSource, oldHandler); TextNodeComparator leftComparator = new TextNodeComparator(oldHandler, locale); DomTreeBuilder newHandler = new DomTreeBuilder(); cleaner.cleanAndParse(newSource, newHandler); TextNodeComparator rightComparator = new TextNodeComparator(newHandler, locale); postProcess.startDocument(); postProcess.startElement("", "diffreport", "diffreport", new AttributesImpl()); postProcess.startElement("", "diff", "diff", new AttributesImpl()); HtmlSaxDiffOutput output = new HtmlSaxDiffOutput(postProcess, prefix); HTMLDiffer differ = new HTMLDiffer(output); differ.diff(leftComparator, rightComparator); postProcess.endElement("", "diff", "diff"); postProcess.endElement("", "diffreport", "diffreport"); postProcess.endDocument(); return stringWriter.toString(); } catch (Exception e) { LOGGER.error(ExceptionUtils.getStackTrace(e)); if (e.getCause() != null) { LOGGER.error(ExceptionUtils.getStackTrace(e.getCause())); } if (e instanceof SAXException) { LOGGER.error(ExceptionUtils.getStackTrace(((SAXException) e).getException())); } } return null; }