List of usage examples for java.lang Exception getStackTrace
public StackTraceElement[] getStackTrace()
From source file:com.l2jfree.gameserver.model.entity.events.CTF.java
public static void showFlagHtml(L2Player eventPlayer, String objectId, String teamName) { if (eventPlayer == null) return;//from w w w .j a v a 2 s .c om try { NpcHtmlMessage adminReply = new NpcHtmlMessage(5); L2TextBuilder replyMSG = L2TextBuilder.newInstance("<html><body><center>"); replyMSG.append("CTF Flag<br><br>"); replyMSG.append("<font color=\"00FF00\">" + teamName + "'s Flag</font><br1>"); if (eventPlayer.as(CTFPlayerInfo.class)._teamNameCTF != null && eventPlayer.as(CTFPlayerInfo.class)._teamNameCTF.equals(teamName)) replyMSG.append("<font color=\"LEVEL\">This is your Flag</font><br1>"); else replyMSG.append("<font color=\"LEVEL\">Enemy Flag!</font><br1>"); if (_started) { processInFlagRange(eventPlayer); } else replyMSG.append("CTF match is not in progress yet.<br>Wait for a GM to start the event<br>"); replyMSG.append("</center></body></html>"); adminReply.setHtml(replyMSG.moveToString()); eventPlayer.sendPacket(adminReply); } catch (Exception e) { _log.warn("" + "CTF Engine[showEventHtlm(" + eventPlayer.getName() + ", " + objectId + ")]: exception: " + e.getStackTrace()); } }
From source file:org.metis.sql.SqlJob.java
/** * Broadcasts a message to all the clients that are currently subscribed to * this SQL job/*www. j a v a 2s.c o m*/ * * @param message */ private void sendResponseMessage(List<Map<String, Object>> response) { TextMessage textMessage = null; try { // create a TextMessage to send back based on json response // object textMessage = new TextMessage(Utils.generateJson(response)); } catch (Exception e) { LOG.error(getThreadName() + ":ERROR, caught this " + "Exception while trying to gen json message - " + e.toString()); LOG.error(getThreadName() + ": exception stack trace follows:"); dumpStackTrace(e.getStackTrace()); if (e.getCause() != null) { LOG.error(getThreadName() + ": Caused by " + e.getCause().toString()); LOG.error(getThreadName() + ": causing exception stack trace follows:"); dumpStackTrace(e.getCause().getStackTrace()); } return; } // broadcast the message for (String key : getSocketSessions().keySet()) { WdsSocketSession session = getSocketSessions().get(key); if (session.isOpen()) { try { session.getSession().sendMessage(textMessage); } catch (Exception exc) { LOG.error(getThreadName() + ":ERROR, caught this " + "Exception while trying to broadcast message - " + exc.toString()); LOG.error(getThreadName() + ": exception stack trace follows:"); dumpStackTrace(exc.getStackTrace()); if (exc.getCause() != null) { LOG.error(getThreadName() + ": Caused by " + exc.getCause().toString()); LOG.error(getThreadName() + ": causing exception stack trace follows:"); dumpStackTrace(exc.getCause().getStackTrace()); } return; } } } }
From source file:org.agnitas.util.AgnUtils.java
/** * Getter for property stackTrace.//from w w w.j av a 2s. co m * * @return Value of property stackTrace. */ public static String getStackTrace(Exception e) { String trace = ""; StackTraceElement[] st = e.getStackTrace(); for (int c = 0; c < st.length && c < 20; c++) { trace += st[c].toString() + "\n"; } return trace; }
From source file:no.dusken.common.spring.ExceptionHandler.java
private String getBody(HttpServletRequest request, Exception ex) { StringBuilder builder = new StringBuilder(); builder.append("Method: "); builder.append(request.getMethod()); builder.append('\n'); builder.append("Servletpath: "); builder.append(request.getServletPath()); builder.append('\n'); builder.append("URI: "); builder.append(request.getRequestURI()); builder.append('\n'); builder.append("Query: "); builder.append(request.getQueryString()); builder.append('\n'); builder.append("User-Agent: "); builder.append(request.getHeader("User-Agent")); builder.append('\n'); builder.append("Accept: "); builder.append(request.getHeader("Accept")); builder.append('\n'); builder.append("Accept-Encoding: "); builder.append(request.getHeader("Accept-Encoding")); builder.append('\n'); builder.append("Stacktrace:"); builder.append('\n'); String stacktrace = getStackTraceAsString(ex.getStackTrace()) + (ex.getMessage() == null ? "" : "| Message: " + ex.getMessage()); builder.append(stacktrace);//ww w . ja v a2 s .c o m return builder.toString(); }
From source file:co.forsaken.api.json.JsonWebCall.java
public String executeGet() { if (_log)/* w w w. ja va 2 s.co 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 { HttpGet request = new HttpGet(_url); request.setHeader("Content-Type", "application/json"); 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:terse.vm.Terp.java
public Dict handleUrl(String url, HashMap<String, String> query) { say("runUrl: %s", url); query = (query == null) ? new HashMap<String, String>() : query; Ur[] queryArr = new Ur[query.size()]; int i = 0;/*from ww w . j a v a2s . c o m*/ for (String k : query.keySet()) { String v = query.get(k); if (k == null) k = "HOW_DID_WE_GET_A_NULL_KEY"; if (v == null) v = "HOW_DID_WE_GET_A_NULL_VALUE"; Ur queryKey = newStr(k); Ur queryValue = newStr(v.replaceAll("\r\n", "\n")); queryArr[i] = new Vec(this, urs(queryKey, queryValue)); ++i; } Dict qDict = newDict(queryArr); assert url.startsWith("/"); if (url.equals("/")) { url = "/Top"; } // To get app name, skip the initial '/', and split on dots. String[] word = url.substring(1).split("[.]"); assert word.length > 0; String appName = word[0]; Dict result = null; try { Cls cls = getTerp().clss.get(appName.toLowerCase()); if (cls == null) { toss("Rendering class does not exist: <%s>", appName); } String urlRepr = newStr(url).repr(); String qDictRepr = qDict.repr(); // Inefficient. TODO. Ur result_ur = instNil; int id = 0; Obj inst = null; try { id = Integer.parseInt(word[1]); if (cls instanceof Usr.UsrCls) { inst = ((Usr.UsrCls) cls).cache.find(id); } } catch (Exception _) { // pass. } long before = tickCounter; long nanosBefore = System.nanoTime(); if (inst != null) { result_ur = inst.eval(fmt("self handle: (%s) query: (%s)", urlRepr, qDictRepr)); } else if (Send.understands(cls, "handle:query:")) { say("CLS <%s> understands handle:query: so sending to class.", cls); // First try sending to the class. result_ur = cls.eval(fmt("self handle: (%s) query: (%s)", urlRepr, qDictRepr)); } else { Ur instance = cls.eval("self new"); Usr usrInst = instance.asUsr(); // TODO: LRU & mention() conflict with Cls.insts map. id = usrInst == null ? 0 : usrInst.omention(); // LRU Cache // Next try creating new instance, and send to it. result_ur = instance.asObj() .eval(fmt("self handle: (%s) query: (%s)", newStr(url).repr(), qDict.repr())); } result = result_ur.asDict(); if (result == null) { toss("Sending <handle:query:> to instance of <%s> did not return a Dict: <%s>", appName, result_ur); } result.dict.put(newStr("id"), newStr(Integer.toString(id))); long after = tickCounter; long nanosAfter = System.nanoTime(); result.dict.put(newStr("ticks"), newNum(before - after)); result.dict.put(newStr("nanos"), newNum(nanosAfter - nanosBefore)); say("<handle:query:> used %d ticks and %.3f secs.", before - after, (double) (nanosAfter - nanosBefore) / 1000000000.0); } catch (Exception ex) { ex.printStackTrace(); StringBuffer sb = new StringBuffer(ex.toString()); StackTraceElement[] elems = ex.getStackTrace(); for (StackTraceElement e : elems) { sb.append("\n * "); sb.append(e.toString()); } Ur[] dict_arr = urs(new Vec(this, urs(newStr("type"), newStr("text"))), new Vec(this, urs(newStr("title"), newStr(ex.toString()))), new Vec(this, urs(newStr("value"), newStr(sb.toString())))); result = newDict(dict_arr); } catch (TooManyTicks err) { err.printStackTrace(); String s = fmt("TOO_MANY_TICKS_IN_handleUrl <%s> qdict <%s>", url, qDict); Ur[] dict_arr = urs(new Vec(this, urs(newStr("type"), newStr("text"))), new Vec(this, urs(newStr("title"), newStr(err.toString()))), new Vec(this, urs(newStr("value"), newStr(s)))); result = newDict(dict_arr); } catch (Error err) { err.printStackTrace(); Ur[] dict_arr = urs(new Vec(this, urs(newStr("type"), newStr("text"))), new Vec(this, urs(newStr("title"), newStr(err.toString()))), new Vec(this, urs(newStr("value"), newStr(err.toString())))); result = newDict(dict_arr); } return result; }
From source file:com.esri.geoevent.solutions.adapter.cot.CoTAdapterInbound.java
private String convertQos(String type) throws Exception { try {/* w w w. j a v a 2s. co m*/ StringBuilder sb = new StringBuilder(); try { Matcher matcher; for (CoTTypeDef cd : this.coTTypeMap) { if (cd.isPredicate() && cd.getValue().startsWith("q.")) { Pattern pattern = Pattern.compile(cd.getKey()); matcher = pattern.matcher(type); if (matcher.find()) { sb.append(cd.getValue() + " "); } } } } catch (Exception e) { // e.printStackTrace(); log.error("null pointer exception while converting Qos."); } return this.filterOutDots(sb.toString()); } catch (Exception e) { log.error(e); log.error(e.getStackTrace()); throw (e); } }
From source file:com.esri.geoevent.solutions.adapter.cot.CoTAdapterInbound.java
private String convertType(String type) throws Exception { try {//from w ww . j a v a2 s . c o m Matcher matcher; try { for (CoTTypeDef cd : this.coTTypeMap) { if (!cd.isPredicate()) { Pattern pattern = Pattern.compile(cd.getKey()); matcher = pattern.matcher(type); if (matcher.find()) { return this.filterOutDots(appendToType(type) + cd.getValue()); } } } } catch (Exception e) { // e.printStackTrace(); log.error("null pointer exception while converting Type."); } // no match was found return ""; } catch (Exception e) { log.error(e); log.error(e.getStackTrace()); throw (e); } }
From source file:edu.wpi.margrave.MCommunicator.java
public static void handleXMLCommand(InputStream commandStream) { DocumentBuilder docBuilder = null; DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); try {/* ww w . j a v a 2 s . c o m*/ docBuilder = docFactory.newDocumentBuilder(); } catch (ParserConfigurationException ex) { Logger.getLogger(MCommunicator.class.getName()).log(Level.SEVERE, null, ex); writeToLog( "\nParserConfigurationException at beginning of handleXMLCommand: " + ex.getLocalizedMessage()); writeToLog("\nTerminating engine..."); System.exit(200); } // Save this command for use in exception messages //MEnvironment.lastCommandReceived = command.trim(); Document inputXMLDoc = null; try { // doc = docBuilder.parse(new InputSource(new StringReader(command))); writeToLog("========================================\n========================================\n"); writeToLog("\n" + commandStream.available()); StringBuffer inputStringBuffer = new StringBuffer(); while (true) { // if available=0; we want to block. But don't want to allocate too much room: if (commandStream.available() < 1) { int b = commandStream.read(); inputStringBuffer.append((char) b); //writeToLog("\n(Blocked and then got) character: `"+(char)b+"`"); } else { byte[] inputBytes = new byte[commandStream.available()]; @SuppressWarnings("unused") int bytesRead = commandStream.read(inputBytes); String block = new String(inputBytes); inputStringBuffer.append(block); //writeToLog("\n(Didn't block for) String: `"+block+"`"); } // Bad kludge. Couldn't get proper XML parse function working, so // did this. Should re-write (preferably with correct XML handling functions!) // The trim() call below is especially egregious... - TN String sMargraveCommandEnding = "</MARGRAVE-COMMAND>"; String bufferStr = inputStringBuffer.toString(); if (bufferStr.trim().endsWith(sMargraveCommandEnding)) break; } // end while(true) for kludge String cmdString = inputStringBuffer.toString(); writeToLog("\n\n*********************************\nDONE! Received command: `" + cmdString + "`\n"); inputXMLDoc = docBuilder.parse(new InputSource(new StringReader(cmdString))); //doc = docBuilder.parse(commandStream); //doc = docBuilder.parse(new InputSource(commandStream)); writeToLog((new Date()).toString()); writeToLog("\nExecuting command: " + transformXMLToString(inputXMLDoc) + "\n"); } // end try catch (SAXException ex) { Logger.getLogger(MCommunicator.class.getName()).log(Level.SEVERE, null, ex); writeToLog( "\nSAXException in handleXMLCommand while parsing command stream: " + ex.getLocalizedMessage()); } catch (IOException ex) { Logger.getLogger(MCommunicator.class.getName()).log(Level.SEVERE, null, ex); writeToLog( "\nIOException in handleXMLCommand while parsing command stream: " + ex.getLocalizedMessage()); } ///////////////////////////////////////////////////// // Done parsing input. Now prepare the response. Document theResponse; try { // protect against getFirstChild() call if (inputXMLDoc != null) theResponse = xmlHelper(inputXMLDoc.getFirstChild(), ""); else theResponse = MEnvironment.errorResponse(MEnvironment.sNotDocument, MEnvironment.sCommand, ""); } catch (Exception e) { // Construct an exception response; theResponse = MEnvironment.exceptionResponse(e); } catch (Throwable e) { // This would ordinarily be a terrible thing to do (catching Throwable) // However, we need to warn the client that we're stuck. try { // First log that we got an exception: writeToLog("\n~~~ Throwable caught: " + e.getClass()); writeToLog("\n " + e.getLocalizedMessage()); writeToLog("\n" + Arrays.toString(e.getStackTrace())); writeToLog("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); theResponse = MEnvironment.exceptionResponse(e); } catch (Throwable f) { // If we can't even warn the client, at least close down the engine. Client will detect EOF. theResponse = null; System.exit(101); } // Last resort System.exit(100); } try { addBuffers(theResponse); writeToLog("Returning: " + transformXMLToString(theResponse) + "\n"); out.write(transformXMLToByteArray(theResponse)); } catch (IOException e) { // don't do this. would go through System.err //e.printStackTrace(); } out.flush(); // ALWAYS FLUSH! }
From source file:com.enation.app.shop.core.action.api.MemberApiAction.java
/** * ?/* ww w. j a v a2s .c om*/ * @param oldpassword:?,String * @param newpassword:?,String * @return json * result 1?0 int * message ??? String */ public String changePassword() { HttpServletRequest request = getRequest(); String usernewpwd = request.getParameter("usernewpwd"); Member member = UserConext.getCurrentMember(); System.out.println("usernewpwd=====" + usernewpwd); //add by Tension member = memberManager.get(member.getMember_id()); if (member == null) { this.showErrorJson("?api"); return this.JSON_MESSAGE; } String oldPassword = this.getOldpassword(); String newPassword = this.getNewpassword(); System.out.println(newPassword); oldPassword = oldPassword == null ? "" : StringUtil.md5(oldPassword); newPassword = newPassword == null ? "" : StringUtil.md5(newPassword); if (newPassword.equals(member.getPassword())) { System.out.println("newPassword=====" + newPassword); this.showErrorJson("????"); } else { if (oldPassword.equals(member.getPassword())) { String password = this.getNewpassword(); String passwd_re = this.getRe_passwd(); if (passwd_re.equals(password)) { try { memberManager.updatePassword(password); this.showSuccessJson("??"); } catch (Exception e) { if (this.logger.isDebugEnabled()) { logger.error(e.getStackTrace()); } this.showErrorJson("?"); } } else { this.showErrorJson("???"); } } else { this.showErrorJson("???"); } } return WWAction.JSON_MESSAGE; }