Example usage for java.lang Exception getStackTrace

List of usage examples for java.lang Exception getStackTrace

Introduction

In this page you can find the example usage for java.lang Exception getStackTrace.

Prototype

public StackTraceElement[] getStackTrace() 

Source Link

Document

Provides programmatic access to the stack trace information printed by #printStackTrace() .

Usage

From source file:org.alfresco.repo.search.impl.noindex.NoIndexSearchService.java

private void trace() {
    if (s_logger.isTraceEnabled()) {
        Exception e = new Exception();
        e.fillInStackTrace();//from  w ww .ja  va2 s.com

        StringBuilder sb = new StringBuilder(1024);
        StackTraceUtil.buildStackTrace("Search trace ...", e.getStackTrace(), sb, -1);
        s_logger.trace(sb);
    }
}

From source file:Data.c_PriceDB.java

public boolean loadPricesDB(ActionListener listener) {
    boolean success = true;
    try {//from  w ww.ja  v  a2 s  .c  o  m
        FileUtils.copyURLToFile(new URL("http://www.magictraders.com/pricelists/current-magic-excel.txt"),
                new File(PRICES_FILE));
        listener.actionPerformed(new ActionEvent(this, Action.ACTION_FILE_LOAD_DONE, ""));
        success = updatePrices(listener, PRICES_FILE);
    } catch (Exception ex) {
        for (StackTraceElement elem : ex.getStackTrace()) {
            System.err.print(elem.toString() + "\n");
        }
        success = false;
    }
    return success;
}

From source file:controllerTas.controller.TasController.java

public void consumeStats(Set<HashMap<String, PublishAttribute>> jmx, Set<HashMap<String, PublishAttribute>> mem)
        throws PublishAttributeException, Tas2Exception {

    if (state.testAndSetMaskInterrupt(false, true)) {
        try {//www .j a va2s  . c  o  m
            double timeWindow = state.getLastTimeWindow() / 1e3;
            state.resetTimeWindow();
            log.info("Analyzing stats relevant to the last " + timeWindow + " sec");
            DSTMScenarioTas2 scenario = factory.buildScenario(jmx, mem, timeWindow,
                    state.getCurrentScale().getNumThreads());
            if (!state.isStable((int) scenario.getWorkParams().getWriteOpsPerTx())) {
                return;
            }
            log.trace("BuiltScenario\n" + scenario.toString());
            Set<KPI> kpis = analyzer.computeKPI(scenario);
            log.trace("KPIs " + kpis.toString());
            ThroughputPlotter gnu = new ThroughputPlotter(config.getGnuplotConfig());
            gnu.plot(kpis);
            //this.throughputMaximizer.computeMaxThroughputScale(scenario);
        } catch (Tas2Exception t) {
            log.warn(t);
            log.trace(Arrays.toString(t.getStackTrace()));
            log.trace("Skipping");
        } catch (GnuplotException g) {
            log.warn(g.getMessage());
        } catch (Exception e) {
            log.fatal(e.getMessage());
            log.fatal(Arrays.toString(e.getStackTrace()));
        } finally {
            log.trace("Resetting maskInterrupt");
            state.atomicSetMaskInterrupt(false);
        }
    } else {
        state.resetTimeWindow();
        log.trace("Masked interrupt");
    }
}

From source file:cop.maven.plugins.AbstractRestToRamlMojo.java

@Override
public final void execute() {
    if ("pom".equalsIgnoreCase(project.getPackaging()) || skip)
        return;//from w w  w .  j  av a  2s . c  om

    LOCK.lock();

    try {
        executeWithExceptionsHandled();
    } catch (Exception e) {
        getLog().error("error on execute: " + e.getStackTrace()[0], e);
    } finally {
        LOCK.unlock();
    }
}

From source file:com.poscoict.license.web.controller.PhotoUploadController.java

@RequestMapping(value = { "PhotoUpload" }, method = { RequestMethod.GET, RequestMethod.POST })
public String PhotoUpload(HttpServletRequest request, HttpServletResponse response, PhotoFile upFile)
        throws Exception {
    String return1 = request.getParameter("callback");
    String return2 = "?callback_func=" + request.getParameter("callback_func");
    String return3 = "";
    String name = "";
    String serverPath = request.getContextPath();
    System.out.println("_________________________IMG Controller");
    try {/*w ww .j av a2 s.  co m*/
        if (upFile.getFiledata() != null && upFile.getFiledata().getOriginalFilename() != null
                && !upFile.getFiledata().getOriginalFilename().equals("")) {
            name = upFile.getFiledata().getOriginalFilename()
                    .substring(upFile.getFiledata().getOriginalFilename().lastIndexOf(File.separator) + 1);
            String filename_ext = name.substring(name.lastIndexOf(".") + 1);
            filename_ext = filename_ext.toLowerCase();
            String[] allow_file = { "jpg", "png", "bmp", "gif" };
            int cnt = 0;
            for (int i = 0; i < allow_file.length; i++) {
                if (filename_ext.equals(allow_file[i])) {
                    cnt++;
                }
            }
            if (cnt == 0) {
                return3 = "&errstr=" + name;
            } else {
                String dftFilePath = request.getSession().getServletContext().getRealPath("/");
                String folderPath = new SimpleDateFormat("yyyyMMdd").format(new java.util.Date());
                String filePath = dftFilePath + "editor" + File.separator + "upload" + File.separator
                        + folderPath + File.separator;
                File file = new File(filePath);
                if (!file.exists()) {
                    file.mkdirs();
                }

                String realFileNm = "";
                SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
                String today = formatter.format(new java.util.Date());
                realFileNm = today + UUID.randomUUID().toString() + name.substring(name.lastIndexOf("."));
                String rlFileNm = filePath + realFileNm;

                upFile.getFiledata().transferTo(new File(rlFileNm));

                //backup
                file = new File(backupFolder + folderPath + File.separator);
                if (!file.exists()) {
                    file.mkdirs();
                }
                fileCopy(rlFileNm, backupFolder + folderPath + File.separator + realFileNm);

                return3 += "&bNewLine=true";
                return3 += "&sFileName=" + name;
                return3 += "&sFileURL=" + serverPath + "/editor/upload/" + folderPath + "/" + realFileNm;
            }
        } else {
            return3 += "&errstr=error";
        }
    } catch (Exception e) {
        e.getStackTrace();
    }

    System.out.println("______________return1+return2+return3: " + return1 + return2 + return3);
    return "redirect:/photoUploadCallback" + return2 + return3;
}

From source file:fi.csc.emrex.ncp.JsonController.java

@RequestMapping(value = "/api/elmo", method = RequestMethod.GET)
@ResponseBody/*from w ww  .ja v  a 2  s.  co m*/
public String getElmoJSON(@RequestParam(value = "courses", required = false) String[] courses)
        throws Exception {
    if (courses != null) {
        String courseIdList = "";
        for (int i = 0; i < courses.length; i++) {
            courseIdList += courses[i] + ", ";
        }
        log.info("Courses: " + courseIdList);
    }

    try {

        ElmoParser parser = (ElmoParser) context.getSession().getAttribute("elmo");
        String xmlString;
        if (courses != null) {
            log.debug("Courses count: {}", courses.length);
            List<String> courseList = Arrays.asList(courses);
            xmlString = parser.getCourseData(courseList);
        } else {
            log.debug("Courses count: null");
            xmlString = parser.getCourseData(null);
        }

        log.trace(xmlString);
        JSONObject json = XML.toJSONObject(xmlString);
        return json.toString();
    } catch (Exception e) {
        log.error("Failed to get Elmo JSON", e);
        StackTraceElement elements[] = e.getStackTrace();
        Map<String, Object> error = new HashMap<String, Object>();
        Map<String, Object> log = new HashMap<String, Object>();
        error.put("message", e.getMessage());
        for (int i = 0, n = elements.length; i < n; i++) {
            log.put(elements[i].getFileName() + " " + elements[i].getLineNumber(), elements[i].getMethodName());
        }
        error.put("stack", log);
        return new JSONObject(error).toString();
    }
}

From source file:edu.psu.citeseerx.myciteseer.web.AppidGenerationController.java

public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
    Account account = MCSUtils.getLoginAccount();
    String errMsg = null;/*from w  ww . j a  v a 2s.  c o  m*/
    boolean error = false;

    if (null == account) {
        error = true;
        errMsg = "Imposible to get the account information";
        System.err.println(
                "Imposible to get the account information " + "while trying to generate an application key");
    }

    String appKey = null;
    if (!error) {
        // Generate the key
        appKey = generateKey(account.getUsername(), account.getEmail());
        account.setAppid(appKey);
        try {
            myciteseer.changeAppid(account);
        } catch (Exception e) {
            error = true;
            errMsg = "A problem occurred while saving the application key";
            System.err.println(e.getStackTrace());
        }
    }

    if (error) {
        return MCSUtils.errorPage(errMsg);
    } else {
        HashMap<String, String> model = new HashMap<String, String>();
        model.put("name", account.getFirstName());
        model.put("apikey", appKey);
        return new ModelAndView(view, model);
    }
}

From source file:com.poscoict.license.web.controller.PhotoUploadController.java

@RequestMapping(value = { "PhotoUploadHTML5" }, method = { RequestMethod.POST })
public void PhotoUploadHTML5(HttpServletRequest request, HttpServletResponse response) throws Exception {
    try {//from w ww .  j a v  a 2s.c  om
        System.out.println("________PhotoUploadHTML5");
        //?
        String sFileInfo = "";
        String filename = request.getHeader("file-name");
        String filename_ext = filename.substring(filename.lastIndexOf(".") + 1);
        filename_ext = filename_ext.toLowerCase();

        String[] allow_file = { "jpg", "png", "bmp", "gif" };

        int cnt = 0;
        for (int i = 0; i < allow_file.length; i++) {
            if (filename_ext.equals(allow_file[i])) {
                cnt++;
            }
        }

        if (cnt == 0) {
            PrintWriter print = response.getWriter();
            print.print("NOTALLOW_" + filename);
            print.flush();
            print.close();
        } else {
            String dftFilePath = request.getSession().getServletContext().getRealPath("/");
            String folderPath = new SimpleDateFormat("yyyyMMdd").format(new java.util.Date());
            String filePath = dftFilePath + "editor" + File.separator + "multiupload" + File.separator
                    + folderPath + File.separator;
            File file = new File(filePath);
            if (!file.exists()) {
                file.mkdirs();
            }

            String realFileNm = "";
            SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
            String today = formatter.format(new java.util.Date());
            realFileNm = today + UUID.randomUUID().toString() + filename.substring(filename.lastIndexOf("."));
            String rlFileNm = filePath + realFileNm;

            InputStream is = request.getInputStream();
            OutputStream os = new FileOutputStream(rlFileNm);
            int numRead;
            byte b[] = new byte[Integer.parseInt(request.getHeader("file-size"))];
            while ((numRead = is.read(b, 0, b.length)) != -1) {
                os.write(b, 0, numRead);
            }
            if (is != null) {
                is.close();
            }
            os.flush();
            os.close();

            //backup
            file = new File(backupFolderHTML5 + folderPath + File.separator);
            if (!file.exists()) {
                file.mkdirs();
            }
            fileCopy(rlFileNm, backupFolderHTML5 + folderPath + File.separator + realFileNm);
            System.out.println("___________rlFileNm: " + rlFileNm);
            System.out.println("____________backupFolderHTML5: " + backupFolderHTML5 + folderPath
                    + File.separator + realFileNm);

            String serverPath = request.getContextPath();
            sFileInfo += "&bNewLine=true";
            sFileInfo += "&sFileName=" + filename;
            sFileInfo += "&sFileURL=" + serverPath + "/editor/multiupload/" + folderPath + "/" + realFileNm;
            PrintWriter print = response.getWriter();
            print.print(sFileInfo);
            print.flush();
            print.close();
        }
    } catch (Exception e) {
        e.getStackTrace();
    }
}

From source file:main.export.sql.DataImporter.java

/**
 * // www .j a  v a2s  .  com
 * @param configFile
 */
private void loadDataConfig(InputSource configFile) {

    try {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

        DocumentBuilder builder = dbf.newDocumentBuilder();
        Document document;
        try {
            document = builder.parse(configFile);
        } finally {
            // some XML parsers are broken and don't close the byte stream
            // (but they should according to spec)
            IOUtils.closeQuietly(configFile.getByteStream());
        }

        config = new DataConfig();
        NodeList elems = document.getElementsByTagName("dataConfig");
        if (elems == null || elems.getLength() == 0) {
            log.error("the root node '<dataConfig>' is missing");
            throw new IOException();
        }
        config.readFromXml((Element) elems.item(0));
        log.info("Data Configuration loaded successfully");
    } catch (Exception e) {
        log.error(e.getStackTrace());
    }

}

From source file:com.jaspersoft.jasperserver.war.CSVServlet.java

private MondrianDrillThroughTableModel getDrillThroughModel(HttpServletRequest req) {
    HttpSession session = req.getSession();
    OlapModel olapModel = (OlapModel) session.getAttribute("olapModel");
    Model mdl = ((OlapModelDecorator) olapModel).getRootModel();
    String currentView = (String) session.getAttribute("currentView");
    // only MondrianModel supports Drillthru
    if (mdl instanceof MondrianModel) {
        try {/*from  ww w .j av a  2  s .  c  om*/
            if (currentView != null) {
                EditableTableComponent et = (EditableTableComponent) session
                        .getAttribute(currentView + ".drillthroughtable");
                if (et != null) {
                    return (MondrianDrillThroughTableModel) et.getModel();
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getStackTrace());
        }
    }
    return null;
}