List of usage examples for java.lang StackTraceElement getClassName
public String getClassName()
From source file:org.collectionspace.chain.csp.webui.main.StreamUIRequest.java
private void exception_to_text_internal(StringBuffer buf, Throwable e) { buf.append("Exception " + e.getClass() + " thrown message=\"" + e.getMessage() + "\"\n"); for (StackTraceElement el : e.getStackTrace()) { buf.append(el.getClassName() + " " + el.getMethodName() + " (" + el.getFileName() + ":" + el.getLineNumber() + ")\n"); }//from w ww . j a v a 2 s .c om Throwable next = e.getCause(); if (next != null && next != e) { buf.append("Caused by:\n"); exception_to_text_internal(buf, next); } }
From source file:org.unitils.mock.core.proxy.ProxyService.java
/** * First finds a trace element in which a cglib proxy method was invoked. Then it returns the rest of the stack trace following that * element. The stack trace starts with the element is the method call that was proxied by the proxy method. * * @return The proxied method trace, not null *//*from w w w . j ava 2s . com*/ public StackTraceElement[] getProxiedMethodStackTrace(StackTraceElement[] stackTrace) { List<StackTraceElement> result = new ArrayList<StackTraceElement>(); boolean foundProxyMethod = false; for (StackTraceElement stackTraceElement : stackTrace) { if (foundProxyMethod) { result.add(stackTraceElement); } else if (isCglibProxyClassName(stackTraceElement.getClassName())) { // found the proxy method element, the next element is the proxied method element foundProxyMethod = true; } } if (result.isEmpty()) { throw new UnitilsException( "No invocation of a cglib proxy method found in stack trace: " + Arrays.toString(stackTrace)); } return result.toArray(new StackTraceElement[result.size()]); }
From source file:edu.wustl.lookingglass.issue.ExceptionPane.java
public String getErrorMessage() { if (this.getRootThrowable() != null) { String key = this.getRootThrowable().getClass().getSimpleName(); StackTraceElement[] trace = this.getRootThrowable().getStackTrace(); for (StackTraceElement element : trace) { String marker = element.getClassName() + "." + element.getMethodName(); if (this.getRootThrowable().getClass().equals(AssertionError.class)) { switch (marker) { case "org.alice.stageide.StageIDE.setProject": key += "." + marker; break; }//from www.java 2 s .c om } } try { return getLocalizedString(key); } catch (MissingResourceException e) { return null; } } else { return null; } }
From source file:org.opentestsystem.shared.docs.RequestLoggingInterceptor.java
/** * NOTE: this is a brittle example of walking up the stack to find * an annotated method to determine how to treat the API doc captured in this * Intercepter. The use of annotations provides a lightweight mechanism of doing just that. * * @return the rank if found (or the ApiDocExample.DEFAULT_RANK if not) *//*from ww w. ja v a 2 s . c o m*/ private int getRankOfApiDoc() { StackTraceElement[] stack = Thread.currentThread().getStackTrace(); // default to DEFAULT_RANK which will capture the doc, but put it at the bottom if no annotation is found. int rank = ApiDocExample.DEFAULT_RANK; // loop up the stack to find the annotation for (int i = 0; i < stack.length; i++) { StackTraceElement ste = stack[i]; // shortcut up the stack: once we get to the MocMvc call, we're in business: start interrogating the methods if (ste.getClassName().equals(MockMvc.class.getName())) { for (int j = i; j < stack.length; j++) { StackTraceElement theOne = stack[j]; try { Class<?> clazz = Class.forName(theOne.getClassName()); // following JUnit convention, the root test will have no args Method theMethod = clazz.getMethod(theOne.getMethodName(), (Class[]) null); // find the ApiDocExample if it exists ApiDocExample example = theMethod.getAnnotation(ApiDocExample.class); if (example != null) { rank = example.rank(); // once we find an example annotation, break out of loops. break; } } catch (ClassNotFoundException | NoSuchMethodException e) { // getMethod failed to find a no arg method, continue down the stack. continue; } } break; } } return rank; }
From source file:com.stackify.log.log4j2.LogEventAdapter.java
/** * @see com.stackify.api.common.log.EventAdapter#getLogMsg(java.lang.Object, com.google.common.base.Optional) *//*from ww w . j a v a2 s .c o m*/ @Override public LogMsg getLogMsg(final LogEvent event, final StackifyError error) { LogMsg.Builder builder = LogMsg.newBuilder(); builder.msg(getMessage(event)); Map<String, String> props = getProperties(event); if (!props.isEmpty()) { try { builder.data(json.writeValueAsString(props)); } catch (Exception e) { // do nothing } } builder.ex(error); builder.th(event.getThreadName()); builder.epochMs(event.getTimeMillis()); builder.level(event.getLevel().toString().toLowerCase()); String transactionId = APMLogData.isLinked() ? APMLogData.getTransactionId() : ServletLogContext.getTransactionId(); if (transactionId != null) { builder.transId(transactionId); } StackTraceElement source = event.getSource(); if (source != null) { builder.srcMethod(source.getClassName() + "." + source.getMethodName()); try { builder.srcLine(source.getLineNumber()); } catch (Throwable e) { } } return builder.build(); }
From source file:org.apache.hupa.server.InMemoryIMAPStoreCache.java
private Session createSession(final User user) { Properties props = new Properties(); Settings settings = user.getSettings(); props.setProperty("mail.mime.decodetext.strict", "false"); if (settings.getImapSecure()) { props.setProperty("mail.store.protocol", "imaps"); props.setProperty("mail.imaps.connectionpoolsize", connectionPoolSize + ""); props.setProperty("mail.imaps.connectionpooltimeout", timeout + ""); if (trustSSL) { props.setProperty("mail.imaps.ssl.trust", settings.getImapServer()); }/* w w w . j av a 2 s .c om*/ } else { props.setProperty("mail.imap.connectionpoolsize", connectionPoolSize + ""); props.setProperty("mail.imap.connectionpooltimeout", timeout + ""); } if (settings.getSmtpSecure()) { if (settings.getSmtpPort() == 587) { props.setProperty("mail.smtp.starttls.enable", "true"); props.setProperty("mail.transport.protocol.rfc822", "smtp"); } else { props.setProperty("mail.transport.protocol.rfc822", "smtps"); props.setProperty("mail.smtps.ssl.enable", "true"); if (trustSSL) { props.setProperty("mail.smtps.ssl.trust", settings.getSmtpServer()); } } } else { props.setProperty("mail.transport.protocol.rfc822", "smtp"); } props.setProperty("mail.smtp.host", settings.getSmtpServer()); props.setProperty("mail.smtps.host", settings.getSmtpServer()); props.setProperty("mail.smtp.port", settings.getSmtpPort() + ""); props.setProperty("mail.smtps.port", settings.getSmtpPort() + ""); Authenticator auth = null; if (settings.getSmtpAuth() && user.getPassword() != null && user.getName() != null) { props.setProperty("mail.smtp.auth", "true"); props.setProperty("mail.smtps.auth", "true"); auth = new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { String userId = user.getId(); StackTraceElement[] sElms = Thread.currentThread().getStackTrace(); for (StackTraceElement e : sElms) { if (e.getClassName().equals(InMemoryIMAPStoreCache.class.getName()) && e.getMethodName().equals("get")) { // We try with the id part the second time (unix imap/smtp auth compatible) if (userId.matches(".*@.*")) { userId = userId.replaceFirst("@.*", ""); user.setId(userId); break; } else { return null; } } } return new PasswordAuthentication(userId, user.getPassword()); } }; } Session ses = Session.getInstance(props, auth); ses.setDebug(debug && logger.isDebugEnabled()); logger.debug("Created session " + user.getName() + "\n" + settings + "\n" + props.toString().replaceAll(",", ",\n ")); return ses; }
From source file:com.stackify.log.log4j2.LogEventAdapter.java
/** * @see com.stackify.api.common.log.EventAdapter#getStackifyError(java.lang.Object, java.lang.Throwable) *//*w ww . j ava2s . c o m*/ @Override public StackifyError getStackifyError(final LogEvent event, final Throwable exception) { StackifyError.Builder builder = StackifyError.newBuilder(); builder.environmentDetail(envDetail); builder.occurredEpochMillis(new Date(event.getTimeMillis())); if (exception != null) { builder.error(Throwables.toErrorItem(getMessage(event), exception)); } else { String className = null; String methodName = null; int lineNumber = 0; StackTraceElement source = event.getSource(); if (source != null) { className = source.getClassName(); methodName = source.getMethodName(); try { lineNumber = source.getLineNumber(); } catch (Throwable e) { } } builder.error(Throwables.toErrorItem(getMessage(event), className, methodName, lineNumber)); } String user = APMLogData.isLinked() ? APMLogData.getUser() : ServletLogContext.getUser(); if (user != null) { builder.userName(user); } WebRequestDetail webRequest = APMLogData.isLinked() ? APMLogData.getWebRequest() : ServletLogContext.getWebRequest(); if (webRequest != null) { builder.webRequestDetail(webRequest); } builder.serverVariables(Maps.fromProperties(System.getProperties())); return builder.build(); }
From source file:com.dianping.dpsf.jmx.DpsfResponsorMonitor.java
private String getThreadStackTraces(RequestProcessor requestProcessor, State state, int threadCount) { ThreadGroup threadGroup = requestProcessor.getThreadPool().getFactory().getGroup(); Thread[] threads = new Thread[threadGroup.activeCount()]; threadGroup.enumerate(threads, false); StringBuilder builder = new StringBuilder(); int count = 0; if (threads != null && threads.length > 0 && threadCount > 0) { for (Thread thread : threads) { if (state == thread.getState()) { count++;/*from w w w .ja v a2 s. c o m*/ if (count > 1) { builder.append("\r\n\r\n"); } builder.append("Thread ").append(thread.getId()).append(" ").append(thread.getName()) .append(" (state = ").append(state).append(")").append("\r\n"); StackTraceElement[] stackTrace = thread.getStackTrace(); for (StackTraceElement ste : stackTrace) { builder.append(ste.getClassName()).append("-").append(ste.getMethodName()).append("(") .append(ste.getLineNumber()).append(")").append("\r\n"); } if (count >= threadCount) { break; } } } } return builder.toString(); }
From source file:org.gradle.internal.featurelifecycle.ScriptUsageLocationReporter.java
private void doReportLocation(DeprecatedFeatureUsage usage, StringBuilder target) { List<StackTraceElement> stack = usage.getStack(); if (stack.isEmpty()) { return;/*from w w w . j a v a2 s .co m*/ } StackTraceElement directCaller = stack.get(0); if (scripts.containsKey(directCaller.getFileName())) { reportStackTraceElement(directCaller, target); return; } int caller = 1; while (caller < stack.size() && stack.get(caller).getClassName().equals(directCaller.getClassName())) { caller++; } if (caller == stack.size()) { return; } StackTraceElement indirectCaller = stack.get(caller); if (scripts.containsKey(indirectCaller.getFileName())) { reportStackTraceElement(indirectCaller, target); } }
From source file:au.id.wolfe.riak.log4j.RiakAppender.java
/** * builds the JSON string containing the log event attributes. * * @param recordKey The key for the record. * @param event log event/*w w w. j a v a 2 s. c o m*/ * @throws JSONException This may be caused by malformed string input. * @return String containing log event serialised to JSON. * @see java.util.logging.XMLFormatter * */ private String buildJson(String recordKey, LoggingEvent event) throws JSONException { JSONStringer jsonLogEvent; jsonLogEvent = new JSONStringer(); jsonLogEvent.object(); if (event.getLocationInformation() != null) { JSONObject sourceInfo = new JSONObject(); sourceInfo.put("class", event.getLocationInformation().getClassName()); sourceInfo.put("fileName", event.getLocationInformation().getFileName()); sourceInfo.put("lineNumber", event.getLocationInformation().getLineNumber()); sourceInfo.put("methodName", event.getLocationInformation().getMethodName()); jsonLogEvent.key("sourceInfo").value(sourceInfo); } jsonLogEvent.key("class").value(event.getFQNOfLoggerClass()); jsonLogEvent.key("level").value(event.getLevel()); jsonLogEvent.key("message").value(event.getMessage()); // ripple specific information, I don't see any issue including it even if it is not used. jsonLogEvent.key("record_id").value(recordKey); jsonLogEvent.key("_type").value("LogRecord"); if (event.getThrowableInformation() != null) { ThrowableInformation throwableInformation = event.getThrowableInformation(); JSONArray stack = new JSONArray(); for (StackTraceElement stackTraceElement : throwableInformation.getThrowable().getStackTrace()) { JSONObject frame = new JSONObject(); frame.put("class", stackTraceElement.getClassName()); frame.put("method", stackTraceElement.getMethodName()); if (stackTraceElement.getLineNumber() >= 0) { frame.put("lineNumber", stackTraceElement.getLineNumber()); } stack.put(frame); } JSONObject throwableInfo = new JSONObject(); throwableInfo.put("throwable", throwableInformation.getThrowable().getClass().getCanonicalName()); throwableInfo.put("message", throwableInformation.getThrowable().getMessage()); throwableInfo.put("stack", stack); jsonLogEvent.key("throwableInfo").value(throwableInfo); } jsonLogEvent.key("millis").value(event.getTimeStamp()); return jsonLogEvent.endObject().toString(); }