List of usage examples for java.lang Exception getStackTrace
public StackTraceElement[] getStackTrace()
From source file:com.vangent.hieos.logbrowser.servlets.GetTableServlet.java
/** * * @param e/*from w w w . jav a2 s . c o m*/ * @param response */ private void getError(Exception e, HttpServletResponse response) { PrintWriter print; try { print = response.getWriter(); response.setContentType("text/javascript"); StringBuffer toPrint = new StringBuffer(); StringBuffer toPrint2 = new StringBuffer(); toPrint.append("{ \"result\":"); JSONStringer stringer = new JSONStringer(); stringer.object(); stringer.key("error"); stringer.value(e.getClass().toString() + ":" + e.getMessage()); stringer.endObject(); toPrint.append(stringer.toString()); toPrint2.append(e.getClass().toString() + ":" + e.getMessage() + "\n"); StackTraceElement[] stack = e.getStackTrace(); for (int i = 0; i < stack.length; i++) { toPrint2.append(stack[i].toString() + "\n"); } toPrint.append("}"); print.write(toPrint.toString()); logger.fatal(toPrint2.toString()); } catch (IOException e1) { } catch (JSONException e2) { // TODO Auto-generated catch block e2.printStackTrace(); } }
From source file:com.bah.applefox.main.plugins.fulltextindex.FTLoader.java
/** This method is used to get the page source from the given URL * @param url - the url from which to get the contents * @return - the page contents/*from w w w .j a v a 2 s. c o m*/ */ private static String getPageContents(URL url) { String pageContents = ""; try { // Open the URL Connection URLConnection con = url.openConnection(); // Get the file path, and eliminate unreadable documents String filePath = url.toString(); // Reads content only if it is a valid format if (!(filePath.endsWith(".pdf") || filePath.endsWith(".doc") || filePath.endsWith(".jsp") || filePath.endsWith("rss") || filePath.endsWith(".css"))) { // Sets the connection timeout (in milliseconds) con.setConnectTimeout(1000); // Tries to match the character set of the Web Page String charset = "utf-8"; try { Matcher m = Pattern.compile("\\s+charset=([^\\s]+)\\s*").matcher(con.getContentType()); charset = m.matches() ? m.group(1) : "utf-8"; } catch (Exception e) { log.error("Page had no specified charset"); } // Reader derived from the URL Connection's input stream, with // the // given character set Reader r = new InputStreamReader(con.getInputStream(), charset); // String Buffer used to append each chunk of Web Page data StringBuffer buf = new StringBuffer(); // Tries to get an estimate of bytes available int BUFFER_SIZE = con.getInputStream().available(); // If BUFFER_SIZE is too small, increases the size if (BUFFER_SIZE <= 1000) { BUFFER_SIZE = 1000; } // Character array to hold each chunk of Web Page data char[] ch = new char[BUFFER_SIZE]; // Read the first chunk of Web Page data int len = r.read(ch); // Loops until end of the Web Page is reached while (len != -1) { // Appends the data chunk to the string buffer and gets the // next chunk buf.append(ch, 0, len); len = r.read(ch, 0, BUFFER_SIZE); } // Sets the pageContents to the newly created string pageContents = buf.toString(); } } catch (UnsupportedEncodingException e) { if (e.getMessage() != null) { log.error(e.getMessage()); } else { log.error(e.getStackTrace()); } // Assume the body contents are blank if the character encoding is // not supported pageContents = ""; } catch (IOException e) { if (e.getMessage() != null) { log.error(e.getMessage()); } else { log.error(e.getStackTrace()); } // Assume the body contents are blank if the Web Page could not be // accessed pageContents = ""; } return pageContents; }
From source file:com.enation.app.shop.core.action.api.MemberApiAction.java
public String saveInfo() { Member member = UserConext.getCurrentMember(); member = memberManager.get(member.getMember_id()); ///*from w ww .ja va2s. co m*/ String faceField = "faceFile"; if (file != null) { // String allowTYpe = "gif,jpg,bmp,png"; if (!fileFileName.trim().equals("") && fileFileName.length() > 0) { String ex = fileFileName.substring(fileFileName.lastIndexOf(".") + 1, fileFileName.length()); if (allowTYpe.toString().indexOf(ex.toLowerCase()) < 0) { this.showErrorJson("?,?gif,jpg,bmp,png??"); return this.JSON_MESSAGE; } } //? if (file.length() > 200 * 1024) { this.showErrorJson("'?,?200K?"); return this.JSON_MESSAGE; } String imgPath = UploadUtil.upload(file, fileFileName, faceField); member.setFace(imgPath); } HttpServletRequest request = ThreadContextHolder.getHttpRequest(); if (StringUtil.isEmpty(mybirthday)) { member.setBirthday(0L); } else { member.setBirthday(DateUtil.getDateline(mybirthday)); } // if (member.getEmail() != null && !member.getEmail().equals(email)) { if (memberManager.checkemail(email) > 0) { this.showErrorJson("email?"); return this.JSON_MESSAGE; } if (memberManager.checkname(email) > 0) { this.showErrorJson("email??"); return this.JSON_MESSAGE; } } member.setProvince_id(province_id); member.setCity_id(city_id); member.setRegion_id(region_id); member.setProvince(province); member.setCity(city); member.setRegion(region); member.setAddress(address); member.setZip(zip); member.setEmail(email); if (mobile != null) { //? if (member.getMobile() != null && !member.getMobile().equals(mobile)) { if (memberManager.checkMobile(mobile) > 0) { this.showErrorJson("??"); return this.JSON_MESSAGE; } if (memberManager.checkname(mobile) > 0) { this.showErrorJson("???"); return this.JSON_MESSAGE; } } member.setMobile(mobile); } member.setTel(tel); if (nickname != null) { member.setNickname(nickname); } if (name != null) { member.setName(name); } member.setSex(Integer.valueOf(sex)); // String midentity = request.getParameter("member.midentity"); if (!StringUtil.isEmpty(midentity)) { member.setMidentity(StringUtil.toInt(midentity, 0)); } else { member.setMidentity(0); } // String pw_question = request.getParameter("member.pw_question"); // member.setPw_question(pw_question); // String pw_answer = request.getParameter("member.pw_answer"); // member.setPw_answer(pw_answer); try { // ?? boolean addPoint = false; if (member.getInfo_full() == 0 && !StringUtil.isEmpty(member.getName()) && !StringUtil.isEmpty(member.getNickname()) && !StringUtil.isEmpty(member.getProvince()) && !StringUtil.isEmpty(member.getCity()) && !StringUtil.isEmpty(member.getRegion()) && (!StringUtil.isEmpty(member.getMobile()) || !StringUtil.isEmpty(member.getTel()))) { addPoint = true; } // if (addPoint) { member.setInfo_full(1); memberManager.edit(member); if (memberPointManger.checkIsOpen(IMemberPointManger.TYPE_FINISH_PROFILE)) { int point = memberPointManger.getItemPoint(IMemberPointManger.TYPE_FINISH_PROFILE + "_num"); int mp = memberPointManger.getItemPoint(IMemberPointManger.TYPE_FINISH_PROFILE + "_num_mp"); memberPointManger.add(member.getMember_id(), point, "", null, mp); } } else { memberManager.edit(member); } this.showSuccessJson("??"); return this.JSON_MESSAGE; } catch (Exception e) { if (this.logger.isDebugEnabled()) { logger.error(e.getStackTrace()); } this.showErrorJson("?"); return this.JSON_MESSAGE; } }
From source file:eu.europa.ec.markt.dss.validation102853.SignedDocumentValidator.java
/** * Main method for validating a signature. The diagnostic data is extracted. * * @param signature Signature to be validated (can be XAdES, CAdES, PAdES. * @return The JAXB object containing all diagnostic data pertaining to the signature *///from ww w .java 2 s . c o m private XmlSignature validateSignature(final AdvancedSignature signature, final ValidationContext valContext) throws DSSException { /* * TODO: (Bob 20130424) The the certToValidate parameter must be added. */ final XmlSignature xmlSignature = DIAGNOSTIC_DATA_OBJECT_FACTORY.createXmlSignature(); try { final CertificateToken signingToken = dealSignature(signature, xmlSignature); valContext.setCertificateToValidate(signingToken); valContext.validate(); dealPolicy(signature, xmlSignature); dealCertificateChain(xmlSignature, signingToken); dealTimestamps(xmlSignature, valContext.getTimestampTokens()); dealContentTimestamps(signature, xmlSignature); dealSigAndRefsTimestamp(xmlSignature, valContext.getSigAndRefsTimestamps()); dealRefsOnlyTimestamp(xmlSignature, valContext.getRefsOnlyTimestamps()); dealArchiveTimestamp(xmlSignature, valContext.getArchiveTimestamps()); } catch (Exception e) { LOG.warning(e.toString() + "\n" + e.getStackTrace()[0].toString()); String errorMessage = xmlSignature.getErrorMessage(); if (errorMessage == null || errorMessage.isEmpty()) { xmlSignature.setErrorMessage(e.toString()); } else { errorMessage += "<br>" + e.toString(); } } return xmlSignature; }
From source file:gov.llnl.lc.smt.command.SmtCommand.java
protected void closeSession(OsmSession ParentSession) { OsmServiceManager OsmService = OsmServiceManager.getInstance(); try {//from w w w . ja va2 s . co m OsmService.closeSession(ParentSession); } catch (Exception e) { logger.severe(e.getStackTrace().toString()); } }
From source file:gov.llnl.lc.smt.command.SmtCommand.java
/** * Describe the method here//from w ww . ja v a2 s .c o m * * @throws Exception * * @see describe related java objects * ***********************************************************/ protected OsmSession openSession() { // establish a connection OsmSession ParentSession = null; Map<String, String> map = smtConfig.getConfigMap(); String hostNam = map.get(SmtProperty.SMT_HOST.getName()); String portNum = map.get(SmtProperty.SMT_PORT.getName()); /* the one and only OsmServiceManager */ OsmServiceManager OsmService = OsmServiceManager.getInstance(); try { ParentSession = OsmService.openSession(hostNam, portNum, null, null); } catch (Exception e) { logger.severe(e.getStackTrace().toString()); System.exit(-1); } return ParentSession; }
From source file:com.commontime.plugin.LocationManager.java
private void _handleExceptionOfCommand(CallbackContext callbackContext, Exception exception) { Log.e(TAG, "Uncaught exception: " + exception.getMessage()); Log.e(TAG, "Stack trace: " + exception.getStackTrace()); // When calling without a callback from the client side the command can be null. if (callbackContext == null) { return;//from w ww . j av a 2s .c o m } callbackContext.error(exception.getMessage()); }
From source file:co.forsaken.api.json.JsonWebCall.java
public String executeRet(Object arg) { if (_log)/*from w w w . ja va 2 s. c o m*/ System.out.println("Requested: [" + _url + "]"); try { canConnect(); } catch (Exception ex) { ex.printStackTrace(); return null; } HttpClient httpClient = new DefaultHttpClient(_connectionManager); InputStream in = null; String res = null; try { Gson gson = new Gson(); HttpPost request = new HttpPost(_url); if (arg != null) { StringEntity params = new StringEntity(gson.toJson(arg)); params.setContentType(new BasicHeader("Content-Type", "application/json")); request.setEntity(params); } HttpResponse response = httpClient.execute(request); if (response != null) { in = response.getEntity().getContent(); res = convertStreamToString(in); } } catch (Exception ex) { System.out.println("JSONWebCall.execute() Error: \n" + ex.getMessage()); System.out.println("Result: \n" + res); StackTraceElement[] arrOfSTE; int max = (arrOfSTE = ex.getStackTrace()).length; for (int i = 0; i < max; i++) { StackTraceElement trace = arrOfSTE[i]; System.out.println(trace); } } finally { httpClient.getConnectionManager().shutdown(); if (in != null) { try { in.close(); } catch (IOException e) { e.printStackTrace(); } } } if (_log) System.out.println("Returned: [" + _url + "] [" + res + "]"); return res; }
From source file:com.symbian.driver.core.report.Result.java
/** *//*from w w w .jav a 2 s. c o m*/ private void setException(final BaseReport aBaseReport) { Map<? extends Exception, ESeverity> lExceptions = iTaskFinishedEvent.getExceptions(); if (lExceptions != null && !lExceptions.isEmpty()) { EList lExceptionList = aBaseReport.getExecptionReport(); for (Exception lException : lExceptions.keySet()) { //handle the crash exception if (lException instanceof CrashException) { CrashException crashExp = (CrashException) lException; aBaseReport.setCrash(true); if (crashExp.getCoreDumpUrl() != null) { aBaseReport.setCoredump(crashExp.getCoreDumpUrl().toString()); sReport.getReportInfo().getInfo().put("hasCoreDump", "true"); } continue; } ExceptionReport lExceptionReport = REPORT_FACTORY.createExceptionReport(); lExceptionReport.setMessage(lException.getMessage()); StringBuffer lStringBuffer = new StringBuffer(); StackTraceElement[] lStackTrace = lException.getStackTrace(); for (int i = 0; i < lStackTrace.length; i++) { lStringBuffer.append(lStackTrace[i].getFileName() + "#" + lStackTrace[i].getMethodName() + " (" + lStackTrace[i].getLineNumber() + ")\n"); } lExceptionReport.setStackTrace(lStringBuffer.toString()); lExceptionList.add(lExceptionReport); if (lException instanceof TimeLimitExceededException) { aBaseReport.setTimeout(true); } else { aBaseReport.setTimeout(false); } } } else { aBaseReport.setTimeout(false); } }
From source file:de.hybris.platform.marketplaceintegrationbackoffice.renderer.MarketplaceIntegrationOrderIncrementalRenderer.java
private boolean incrementalOrderDownload(final MarketplaceStoreModel model, final String status) { boolean flag = false; final String logUUID = logUtil.getUUID(); final MarketplaceSellerModel seller = model.getMarketplaceSeller(); final MarketplaceModel marketPlace = seller.getMarketplace(); modelService.refresh(seller);//from w w w . j a v a 2 s. c om final String requestUrl = marketPlace.getAdapterUrl() + Config.getParameter(MARKETPLACE_ORDER_REALTIME_SYNC_PATH) + Config.getParameter(MARKETPLACE_ORDER_SYCHRONIZE_MIDDLE_PATH) + model.getIntegrationId() + Config.getParameter(MARKETPLACE_ORDER_SYCHRONIZE_LOGUUID) + logUUID; final JSONObject jsonObj = new JSONObject(); jsonObj.put("currency", model.getCurrency().getIsocode()); jsonObj.put("productCatalogVersion", model.getCatalogVersion().getCatalog().getId() + ":" + model.getCatalogVersion().getVersion()); jsonObj.put("status", status); try { this.saveMarketplaceLog(status, model, logUUID); final JSONObject results = marketplaceHttpUtil.post(requestUrl, jsonObj.toJSONString()); final String msg = results.toJSONString(); final String responseCode = results.get("code").toString(); if ("401".equals(responseCode)) { LOG.error("========================================================================="); LOG.error("Order incremental download request post to Tmall failed!"); LOG.error("Marketplacestore Code: " + model.getName()); LOG.error("Error Status Code: " + responseCode); LOG.error("Request path: " + requestUrl); LOG.error("-------------------------------------------------------------------------"); LOG.error("Failed Reason:"); LOG.error("Authentication was failed, please re-authenticate again!"); LOG.error("-------------------------------------------------------------------------"); LOG.error("========================================================================="); NotificationUtils.notifyUserVia(Labels.getLabel("marketplace.order.authorization.fail"), NotificationEvent.Type.FAILURE, ""); LOG.warn("Authentication was failed, please re-authenticate again!"); } else if (!("0".equals(responseCode))) { LOG.error("========================================================================="); LOG.error("Order incremental download request post to Tmall failed!"); LOG.error("Marketplacestore Code: " + model.getName()); LOG.error("Error Status Code: " + responseCode); LOG.error("Request path: " + requestUrl); LOG.error("-------------------------------------------------------------------------"); LOG.error("Failed Reason:"); LOG.error("A known issue occurs in tmall, error details :" + msg); LOG.error("-------------------------------------------------------------------------"); LOG.error("========================================================================="); /* * NotificationUtils.notifyUserVia(Labels.getLabel("marketplace.tmallapp.known.issues", new Object[] { msg * }), NotificationEvent.Type.FAILURE, ""); */ LOG.warn("A known issue occurs in tmall, error details :" + msg); } else if ("0".equals(responseCode)) { LOG.debug("Open listen sucessfully"); NotificationUtils.notifyUserVia(Labels.getLabel("marketplace.order.incremental.order.success"), NotificationEvent.Type.SUCCESS, ""); flag = true; LOG.info("========================================================================="); LOG.info("Order incremental download request post to Tmall suceessfully!"); LOG.info("-------------------------------------------------------------------------"); LOG.info("Marketplacestore Code: " + model.getName()); LOG.info("Request path: " + requestUrl); LOG.info("========================================================================="); } } catch (final HttpClientErrorException httpError) { if (httpError.getStatusCode().is4xxClientError()) { LOG.error("========================================================================="); LOG.error("Order incremental download request post to Tmall failed!"); LOG.error("Marketplacestore Code: " + model.getName()); LOG.error("Error Status Code: " + httpError.getStatusCode().toString()); LOG.error("Request path: " + requestUrl); LOG.error("-------------------------------------------------------------------------"); LOG.error("Failed Reason:"); LOG.error("Requested Tmall service URL is not correct!"); LOG.error("-------------------------------------------------------------------------"); LOG.error("Detail error info: " + httpError.getMessage()); LOG.error("========================================================================="); NotificationUtils.notifyUserVia(Labels.getLabel("marketplace.error.request.post.error"), NotificationEvent.Type.FAILURE, ""); } if (httpError.getStatusCode().is5xxServerError()) { LOG.error("========================================================================="); LOG.error("Order incremental download request post to Tmall failed!"); LOG.error("Marketplacestore Code: " + model.getName()); LOG.error("Error Status Code: " + httpError.getStatusCode().toString()); LOG.error("Request path: " + requestUrl); LOG.error("-------------------------------------------------------------------------"); LOG.error("Failed Reason:"); LOG.error("Requested Json Ojbect is not correct!"); LOG.error("-------------------------------------------------------------------------"); LOG.error("Detail error info: " + httpError.getMessage()); LOG.error("========================================================================="); NotificationUtils.notifyUserVia(Labels.getLabel("marketplace.error.server.process.error"), NotificationEvent.Type.FAILURE, ""); } LOG.error(httpError.toString()); return flag; } catch (final ResourceAccessException raError) { LOG.error("========================================================================="); LOG.error("Order incremental download request post to Tmall failed!"); LOG.error("Marketplacestore Code: " + model.getName()); LOG.error("Request path: " + requestUrl); LOG.error("-------------------------------------------------------------------------"); LOG.error("Failed Reason:"); LOG.error("Marketplace order download request server access failed!"); LOG.error("-------------------------------------------------------------------------"); LOG.error("Detail error info: " + raError.getMessage()); LOG.error("========================================================================="); NotificationUtils.notifyUserVia(Labels.getLabel("marketplace.error.server.access.error"), NotificationEvent.Type.FAILURE, ""); return flag; } catch (final HttpServerErrorException serverError) { LOG.error("========================================================================="); LOG.error("Order incremental download request post to Tmall failed!"); LOG.error("Marketplacestore Code: " + model.getName()); LOG.error("Request path: " + requestUrl); LOG.error("-------------------------------------------------------------------------"); LOG.error("Failed Reason:"); LOG.error("Marketplace order download request server process failed!"); LOG.error("-------------------------------------------------------------------------"); LOG.error("Detail error info: " + serverError.getMessage()); LOG.error("========================================================================="); NotificationUtils.notifyUserVia(Labels.getLabel("marketplace.error.server.process.error"), NotificationEvent.Type.FAILURE, ""); return flag; } catch (final Exception e) { final String errorMsg = e.getClass().toString() + ":" + e.getMessage(); NotificationUtils.notifyUserVia( Labels.getLabel("marketplace.runtime.issues", new Object[] { errorMsg }), NotificationEvent.Type.FAILURE, ""); LOG.error("========================================================================="); LOG.error("Order incremental download request failed!"); LOG.error("Marketplacestore Code: " + model.getName()); LOG.error("Request path: " + requestUrl); LOG.error("-------------------------------------------------------------------------"); LOG.error("Detail error info: " + e.getMessage()); LOG.error("========================================================================="); NotificationUtils.notifyUserVia(Labels.getLabel("marketplace.error.server.process.error"), NotificationEvent.Type.FAILURE, ""); LOG.warn(e.getMessage() + e.getStackTrace()); return flag; } return flag; }