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:com.qq.tars.tools.SystemUtils.java
public static Pair<Integer, Pair<String, String>> exec(String command) { log.info("start to exec shell, command={}", command); try {//w ww . ja v a 2s . c om Process process = Runtime.getRuntime().exec("/bin/sh"); OutputStream os = process.getOutputStream(); os.write(command.getBytes()); os.close(); final StringBuilder stdout = new StringBuilder(1024); final StringBuilder stderr = new StringBuilder(1024); final BufferedReader stdoutReader = new BufferedReader( new InputStreamReader(process.getInputStream(), "GBK")); final BufferedReader stderrReader = new BufferedReader( new InputStreamReader(process.getErrorStream(), "GBK")); new Thread(() -> { String line; try { while (null != (line = stdoutReader.readLine())) { stdout.append(line).append("\n"); } } catch (IOException e) { log.error("read stdout error", e); } }).start(); new Thread(() -> { String line; try { while (null != (line = stderrReader.readLine())) { stderr.append(line).append("\n"); } } catch (IOException e) { log.error("read stderr error", e); } }).start(); int ret = process.waitFor(); stdoutReader.close(); stderrReader.close(); Pair<String, String> output = Pair.of(stdout.toString(), stderr.toString()); return Pair.of(ret, output); } catch (Exception e) { return Pair.of(-1, Pair.of("", ExceptionUtils.getStackTrace(e))); } }
From source file:android.databinding.tool.util.L.java
public static void e(Throwable t, String msg, Object... args) { String fullMsg = String.format(msg, args); tryToThrowScoped(t, fullMsg);// w w w .ja va 2 s . co m printMessage(Diagnostic.Kind.ERROR, fullMsg + " " + ExceptionUtils.getStackTrace(t)); }
From source file:com.aurel.track.fieldType.types.FieldType.java
/** * Get the FieldType by class name/* ww w.ja v a2s . co m*/ * @param fieldTypeClassName * @return */ public static FieldType fieldTypeFactory(String fieldTypeClassName) { Class fieldTypeClass = null; if (fieldTypeClassName == null) { LOGGER.warn("No fieldType specified "); return null; } try { fieldTypeClass = Class.forName(fieldTypeClassName); } catch (ClassNotFoundException e) { LOGGER.warn("The fieldType class " + fieldTypeClassName + " not found found in the classpath " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } if (fieldTypeClass != null) try { return (FieldType) fieldTypeClass.newInstance(); } catch (Exception e) { LOGGER.warn("Instantiating the fieldType class " + fieldTypeClassName + " failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } return null; }
From source file:com.aurel.track.license.LicenseHelperBL.java
public static String sendPOSTReq(List<BasicNameValuePair> params, String licenseProviderAddress) { String responseStr = ""; try {/*from w ww .j a va 2s .c o m*/ HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(licenseProviderAddress); // Request parameters and other properties. httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8")); //Execute and get the response. HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); if (entity != null) { InputStream instream = entity.getContent(); responseStr = StringArrayParameterUtils.getStringFromInputStream(instream); try { // do something useful } finally { instream.close(); } } } catch (Exception ex) { LOGGER.error(ExceptionUtils.getStackTrace(ex)); } int idx = responseStr.indexOf("}<!DOCTYPE HTML", 0); if (idx > 0) { responseStr = responseStr.substring(0, idx + 1); } return responseStr; }
From source file:com.aurel.track.lucene.index.associatedFields.textExctractor.XMLExtractor.java
/** * Gets the text from file content // ww w.ja va 2 s . c o m * @param file * @param fileExtension * @return */ @Override public String getText(File file, String fileExtension) { try { OOIndexer ooIndexer = new OOIndexer(); return ooIndexer.parseXML(file); } catch (Exception e) { if (LOGGER.isDebugEnabled()) { LOGGER.debug( "Extracting text from the .xml file " + file.getName() + " failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } return null; } }
From source file:com.aurel.track.lucene.index.associatedFields.textExctractor.XLSExtractor.java
/** * Gets the text from file content //ww w . ja v a 2 s . c om * @param file * @param fileExtension * @return */ @Override public String getText(File file, String fileExtension) { FileInputStream fis = null; try { fis = new FileInputStream(file); } catch (FileNotFoundException e) { LOGGER.info("File " + file.getName() + " not found. " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); return null; } try { XLSTextStripper stripper = new XLSTextStripper(fis, fileExtension); return stripper.getText(); } catch (Exception e) { if (LOGGER.isDebugEnabled()) { LOGGER.debug( "Extracting text from the .xls file " + file.getName() + " failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } return null; } finally { if (fis != null) { try { fis.close(); } catch (IOException e) { LOGGER.debug("Closing the file input stream failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } } } }
From source file:com.trackplus.dao.DAOFactory.java
public void executeUpdateStatement(String sqlStatement) { Connection db = null;/* w w w . j a v a 2 s . com*/ try { //get the database name from any peer db = Torque.getConnection(BaseTWorkItemPeer.DATABASE_NAME); // it's the same name for all tables here, so we don't care Statement stmt; stmt = db.createStatement(); stmt.executeUpdate(sqlStatement); } catch (TorqueException e) { LOGGER.error(ExceptionUtils.getStackTrace(e)); } catch (SQLException e) { LOGGER.error(ExceptionUtils.getStackTrace(e)); } finally { Torque.closeConnection(db); } }
From source file:com.aurel.track.lucene.index.associatedFields.textExctractor.OpenOfficeExtractor.java
/** * Gets the text from file content // www .j ava2s . c o m * @param file * @param fileExtension * @return */ @Override public String getText(File file, String fileExtension) { try { OOIndexer ooIndexer = new OOIndexer(); return ooIndexer.parseOpenOffice(file); } catch (Exception e) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Extracting text from the open office file " + file.getName() + " failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } return null; } }
From source file:com.arrow.acs.Loggable.java
public void logError(String method, String message, Throwable throwable) { logger.error(//from ww w .j a va 2s . c om formatLog(method, String.format("%s \n %s", message, ExceptionUtils.getStackTrace(throwable)))); }
From source file:com.aurel.track.persist.TWorkflowCommentPeer.java
@Override public TWorkflowCommentBean loadByPrimaryKey(Integer objectID) { TWorkflowComment tobject = null;/* w w w.j a v a 2s. c o m*/ try { tobject = retrieveByPK(objectID); } catch (Exception e) { LOGGER.warn( "Loading of a workflow Comment by primary key " + objectID + " failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } if (tobject != null) { return tobject.getBean(); } return null; }