Example usage for org.apache.commons.lang3.exception ExceptionUtils getStackTrace

List of usage examples for org.apache.commons.lang3.exception ExceptionUtils getStackTrace

Introduction

In this page you can find the example usage for org.apache.commons.lang3.exception ExceptionUtils getStackTrace.

Prototype

public static String getStackTrace(final Throwable throwable) 

Source Link

Document

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) .

Usage

From source file:com.aurel.track.persist.TStatePeer.java

/**
 * Loads a state by primary key//from  ww w .  ja  va  2  s.  c o  m
 * @param objectID
 * @return
 */
@Override
public TStateBean loadByPrimaryKey(Integer objectID) {
    TState tState = null;
    try {
        tState = retrieveByPK(objectID);
    } catch (Exception e) {
        LOGGER.info("Loading of a state by primary key " + objectID + " failed with " + e.getMessage());
        LOGGER.debug(ExceptionUtils.getStackTrace(e));
    }
    if (tState != null) {
        return tState.getBean();
    }
    return null;
}

From source file:com.aurel.track.admin.customize.category.report.execute.DocxReportExporter.java

/**
 * Export the items in the given output/* w  w  w.j  ava  2s.c  o m*/
 * 
 * @param document W3C XML DOM document
 * @param personBean current user
 * @param locale
 *            current locale
 * @param parameters
 *            the directory of the DOCX template enriched with special placeholders
 * @param os
 *            the output stream to write to
 * @param contextMap
 * @param description
 */
@Override
public void exportReport(Document document, TPersonBean personBean, Locale locale,
        Map<String, Object> parameters, OutputStream os, Map<String, Object> contextMap,
        Map<String, Object> description) throws ReportExportException {

    String format = (String) description.get(IDescriptionAttributes.FORMAT);

    if (format == null || !format.equals(FORMAT_DOCX)) {
        throw new ReportExportException(ERROR_UNKNOWN_FORMAT);
    }

    /* Caution! Because the me
     * based on the template file name, the template has to be uploaded in the wiki!
     */
    String docxTemplatePath = null;
    URL completeURL = (URL) parameters.get(JasperReportExporter.REPORT_PARAMETERS.COMPLETE_URL);
    if (completeURL != null) {
        docxTemplatePath = completeURL.getFile();
        WordprocessingMLPackage wpMLP = AssembleWordprocessingMLPackage.getWordMLPackage(
                MeetingDatasource.WORK_ITEM_BEAN, MeetingDatasource.REPORT_BEANS, docxTemplatePath,
                personBean.getObjectID(), locale);
        try {
            Docx4J.save(wpMLP, os, Docx4J.FLAG_NONE);
        } catch (Exception e) {
            LOGGER.error("Exporting the docx failed with throwable " + e.getMessage());
            LOGGER.debug(ExceptionUtils.getStackTrace(e));
        }
    }

}

From source file:com.aurel.track.admin.server.sendEmail.SendEmailAction.java

@Override
public String execute() throws Exception {
    LOGGER.debug("SendMailAction.execute()");
    subject = "";
    StringBuilder sb = new StringBuilder();
    sb.append("{");
    JSONUtility.appendBooleanValue(sb, JSONUtility.JSON_FIELDS.SUCCESS, true);
    sb.append(JSONUtility.JSON_FIELDS.DATA).append(":{");
    JSONUtility.appendStringValue(sb, "subject", subject, true);
    sb.append("}}");
    try {//from w  w w  . j av  a  2 s .  c o  m
        JSONUtility.prepareServletResponseJSON(ServletActionContext.getResponse());
        PrintWriter out = ServletActionContext.getResponse().getWriter();
        out.println(sb);
    } catch (IOException e) {
        LOGGER.debug(ExceptionUtils.getStackTrace(e));
    }
    return null;
}

From source file:com.aurel.track.screen.dashboard.action.DashboardAction.java

public String executeJSON() {
    String jsonData = executeInternal();
    try {//from   w w  w.  ja  v a  2  s  . com
        JSONUtility.prepareServletResponseJSON(ServletActionContext.getResponse());
        PrintWriter out = ServletActionContext.getResponse().getWriter();
        StringBuilder sb = new StringBuilder();
        sb.append("{\"success\":true,\"data\":").append(jsonData).append("}");
        out.println(sb);
    } catch (IOException e) {
        LOGGER.error(ExceptionUtils.getStackTrace(e));
    }
    return null;
}

From source file:com.linkedin.pinot.pql.parsers.Pql2Compiler.java

@Override
public BrokerRequest compileToBrokerRequest(String expression) throws Pql2CompilationException {
    try {/*from   w ww.j  a v  a 2 s.  c  o m*/
        //
        CharStream charStream = new ANTLRInputStream(expression);
        PQL2Lexer lexer = new PQL2Lexer(charStream);
        lexer.setTokenFactory(new CommonTokenFactory(true));
        lexer.removeErrorListeners();
        lexer.addErrorListener(ERROR_LISTENER);
        TokenStream tokenStream = new UnbufferedTokenStream<CommonToken>(lexer);
        PQL2Parser parser = new PQL2Parser(tokenStream);
        parser.setErrorHandler(new BailErrorStrategy());
        parser.removeErrorListeners();
        parser.addErrorListener(ERROR_LISTENER);

        // Parse
        ParseTree parseTree = parser.root();

        ParseTreeWalker walker = new ParseTreeWalker();
        Pql2AstListener listener = new Pql2AstListener(expression);
        walker.walk(listener, parseTree);

        AstNode rootNode = listener.getRootNode();
        BrokerRequest brokerRequest = new BrokerRequest();
        rootNode.updateBrokerRequest(brokerRequest);
        return brokerRequest;
    } catch (Pql2CompilationException e) {
        throw e;
    } catch (Exception e) {
        throw new Pql2CompilationException(ExceptionUtils.getStackTrace(e));
    }
}

From source file:com.aurel.track.exchange.track.importer.TrackImportAction.java

/**
 * Render the import page//from w  w w . j a v a2  s.  c  o m
 */
@Override

/**
 * Save the zip file and import the data 
 * @return
 */
public String execute() {
    LOGGER.info("Import started");
    InputStream inputStream;
    try {
        inputStream = new FileInputStream(uploadFile);
    } catch (FileNotFoundException e) {
        LOGGER.error("Getting the input stream for the zip failed with " + e.getMessage());
        LOGGER.debug(ExceptionUtils.getStackTrace(e));
        JSONUtility.encodeJSON(servletResponse,
                JSONUtility.encodeJSONFailure(getText("admin.actions.importTp.err.failed")));
        return null;
    }

    /**
     * delete the old temporary attachment directory if exists from previous imports 
     */
    String tempAttachmentDirectory = AttachBL.getAttachDirBase() + File.separator + AttachBL.tmpAttachments;
    AttachBL.deleteDirectory(new File(tempAttachmentDirectory));

    /**
     * extract the zip to a temporary directory
     */
    ZipInputStream zipInputStream = new ZipInputStream(new BufferedInputStream(inputStream));
    final int BUFFER = 2048;
    File unzipTempDirectory = new File(tempAttachmentDirectory);
    if (!unzipTempDirectory.exists()) {
        unzipTempDirectory.mkdirs();
    }
    BufferedOutputStream dest = null;
    ZipEntry zipEntry;
    try {
        while ((zipEntry = zipInputStream.getNextEntry()) != null) {
            File destFile = new File(unzipTempDirectory, zipEntry.getName());
            // grab file's parent directory structure         
            int count;
            byte data[] = new byte[BUFFER];
            // write the files to the disk
            FileOutputStream fos = new FileOutputStream(destFile);
            dest = new BufferedOutputStream(fos, BUFFER);
            while ((count = zipInputStream.read(data, 0, BUFFER)) != -1) {
                dest.write(data, 0, count);
            }
            dest.flush();
            dest.close();
        }
        zipInputStream.close();
    } catch (Exception e) {
        LOGGER.error("Extracting the zip to the temporary directory failed with " + e.getMessage());
        LOGGER.debug(ExceptionUtils.getStackTrace(e));
        JSONUtility.encodeJSON(servletResponse,
                JSONUtility.encodeJSONFailure(getText("admin.actions.importTp.err.failed")), false);
        return null;
    }

    /**
     * get the data file (the only file from the zip which is not an attachment)  
     */
    File importDataFile = new File(tempAttachmentDirectory, ExchangeFieldNames.EXCHANGE_ZIP_ENTRY);
    if (!importDataFile.exists()) {
        LOGGER.error("The file " + ExchangeFieldNames.EXCHANGE_ZIP_ENTRY + " not found in the zip");
        JSONUtility.encodeJSON(servletResponse,
                JSONUtility.encodeJSONFailure(getText("admin.actions.importTp.err.failed")), false);
        return null;
    }

    /**
     * field parser
     */
    LOGGER.debug("Parsing the fields");
    List<ISerializableLabelBean> customFieldsBeans = new ImporterFieldParser().parse(importDataFile);
    Map<Integer, Integer> fieldsMatcherMap = null;
    try {
        fieldsMatcherMap = TrackImportBL.getFieldMatchMap(customFieldsBeans);
    } catch (ImportExceptionList importExceptionList) {
        LOGGER.error("Getting the field match map failed ");
        JSONUtility.encodeJSON(servletResponse,
                ImportJSON.importErrorMessageListJSON(
                        ErrorHandlerJSONAdapter.handleErrorList(importExceptionList.getErrorDataList(), locale),
                        null, true));
        return null;
    }

    /**
     * dropdown parser
     */
    LOGGER.debug("Parsing the external dropdowns");
    SortedMap<String, List<ISerializableLabelBean>> externalDropdowns = new ImporterDropdownParser()
            .parse(importDataFile, fieldsMatcherMap);

    /**
     * data parser
     */
    LOGGER.debug("Parsing the items");
    List<ExchangeWorkItem> externalReportBeansList = new ImporterDataParser().parse(importDataFile,
            fieldsMatcherMap);
    try {
        LOGGER.debug("Importing the items");
        ImportCounts importCounts = TrackImportBL.importWorkItems(externalReportBeansList, externalDropdowns,
                fieldsMatcherMap, personID, locale);
        LOGGER.debug("Imported " + importCounts.getNoOfCreatedIssues() + " new issues " + " modified "
                + importCounts.getNoOfUpdatedIssues());
        JSONUtility.encodeJSON(servletResponse,
                ImportJSON.importMessageJSON(true,
                        getText("admin.actions.importTp.lbl.result",
                                new String[] { Integer.valueOf(importCounts.getNoOfCreatedIssues()).toString(),
                                        Integer.valueOf(importCounts.getNoOfUpdatedIssues()).toString() }),
                        true, locale),
                false);
    } catch (ImportExceptionList importExceptionList) {
        JSONUtility.encodeJSON(servletResponse,
                ImportJSON.importErrorMessageListJSON(
                        ErrorHandlerJSONAdapter.handleErrorList(importExceptionList.getErrorDataList(), locale),
                        null, true),
                false);
        return null;
    } catch (ImportException importException) {
        JSONUtility.encodeJSON(servletResponse,
                ImportJSON.importMessageJSON(false, getText(importException.getMessage()), true, locale),
                false);
        return null;
    } catch (Exception e) {
        JSONUtility.encodeJSON(servletResponse,
                ImportJSON.importMessageJSON(false, getText("admin.actions.importTp.err.failed"), true, locale),
                false);
        return null;
    }
    LOGGER.info("Import done");
    return null;
}

From source file:jp.co.ipublishing.aeskit.notification.gcm.GCMRegister.java

/**
 * ????//from  ww  w . j  a v  a 2  s  .c o  m
 *
 * @param context 
 * @return ??
 */
private static int getAppVersion(@NonNull Context context) {
    try {
        final PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
        return packageInfo.versionCode;
    } catch (PackageManager.NameNotFoundException e) {
        // ?????????
        Log.e(TAG, ExceptionUtils.getStackTrace(e));
        return -1;
    }
}

From source file:impalapayapis.ApiRequestBank.java

public String doPost() {
    CloseableHttpClient httpclient = HttpClients.createDefault();
    StringEntity entity;//from  ww w  .j ava2s. c  om
    String out = "";

    try {
        entity = new StringEntity(params);
        HttpPost httppost = new HttpPost(url);
        httppost.setEntity(entity);
        HttpResponse response = httpclient.execute(httppost);

        // for debugging
        System.out.println(entity.getContentType());
        System.out.println(entity.getContentLength());
        System.out.println(EntityUtils.toString(entity));
        System.out.println(EntityUtils.toByteArray(entity).length);

        //System.out.println(           "----------------------------------------");

        System.out.println(response.getStatusLine());
        System.out.println(url);

        BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
        out = rd.readLine();
        JsonElement root = new JsonParser().parse(out);

        String specificvalue = root.getAsJsonObject().get("replace with key of the value to retrieve")
                .getAsString();
        System.out.println(specificvalue);

        /**
         * String line = ""; while ((line = rd.readLine()) != null) {
         * //System.out.println(line); }
        *
         */

    } catch (UnsupportedEncodingException e) {
        logger.error("UnsupportedEncodingException for URL: '" + url + "'");

        logger.error(ExceptionUtils.getStackTrace(e));
    } catch (ClientProtocolException e) {
        logger.error("ClientProtocolException for URL: '" + url + "'");
        logger.error(ExceptionUtils.getStackTrace(e));
    } catch (IOException e) {
        logger.error("IOException for URL: '" + url + "'");
        logger.error(ExceptionUtils.getStackTrace(e));
    }
    return out;
}

From source file:com.aurel.track.lucene.index.listFields.InternalListIndexer.java

/**
 * //from  w  w  w . ja  v  a2  s  . c o m
 * Adds a ILabelBeans to the non-localized lookup index  
 * @param labelBean
 * @param type
 */
public synchronized void addLabelBean(ILabelBean labelBean, int type, boolean add) {
    if (!LuceneUtil.isUseLucene()) {
        return;
    }
    if (!ClusterBL.indexInstantly()) {
        LOGGER.debug("Index instantly is false");
        return;
    }
    if (labelBean == null || labelBean.getObjectID() == null) {
        LOGGER.warn("Bean or value null by adding a internal list option of type " + type);
        return;
    }
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Save a new " + add + " internal list option of type " + type);
    }
    Document document = createDocument(labelBean, type);
    if (document != null) {
        IndexWriter indexWriter = LuceneIndexer.getIndexWriter(getIndexWriterID());
        if (indexWriter == null) {
            LOGGER.error("IndexWriter null by adding a non-localized list option of type " + type);
            return;
        }
        try {
            indexWriter.addDocument(document);
        } catch (IOException e) {
            LOGGER.error("Adding the document for list option with key " + labelBean.getObjectID()
                    + " and type " + type + " failed with " + e.getMessage());
            LOGGER.debug(ExceptionUtils.getStackTrace(e));
        }
        try {
            indexWriter.commit();
        } catch (IOException e) {
            LOGGER.error("Flushing list option with key " + labelBean.getObjectID() + " and type " + type
                    + " failed with " + e.getMessage());
            LOGGER.debug(ExceptionUtils.getStackTrace(e));
        }
    }
}

From source file:com.aurel.track.util.StringArrayParameterUtils.java

public static String parseStringValue(Map<String, String[]> configParameters, String fieldName,
        String defaultValue) {//  w ww.  j a  v  a2s. c o m
    String result = defaultValue;
    String[] strArr = null;
    if (configParameters != null) {
        try {
            strArr = (String[]) configParameters.get(fieldName);
        } catch (Exception e) {
            LOGGER.info("parseIntValue: converting the " + fieldName + " parameter to String[] failed with "
                    + e.getMessage());
            LOGGER.debug(ExceptionUtils.getStackTrace(e));
        }
    }
    if (strArr != null && strArr.length > 0) {
        String str = strArr[0];
        if (str != null && !"".equals(str)) {
            try {
                result = str;
            } catch (Exception e) {
                LOGGER.info("Converting the value " + str + " for field " + fieldName + " to int failed with "
                        + e.getMessage());
                LOGGER.debug(ExceptionUtils.getStackTrace(e));
            }
        }
    }
    return result;
}