Example usage for java.lang Throwable toString

List of usage examples for java.lang Throwable toString

Introduction

In this page you can find the example usage for java.lang Throwable toString.

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:com.t3.client.TabletopTool.java

/**
 * This method looks up the message key in the properties file and returns
 * the resultant text with the detail message from the
 * <code>Throwable</code> appended to the end.
 * //from  w  ww. j a v a2  s . c  o m
 * @param msgKey
 *            the string to use when calling {@link I18N#getText(String)}
 * @param t
 *            the exception to be processed
 * @return the <code>String</code> result
 */
public static String generateMessage(String msgKey, Throwable t) {
    String msg;
    if (t == null) {
        msg = I18N.getText(msgKey);
    } else if (msgKey == null) {
        msg = t.toString();
    } else {
        msg = I18N.getText(msgKey) + "<br/>" + t.toString();
    }
    return msg;
}

From source file:net.sourceforge.fenixedu.presentationTier.TagLib.OptionsTag.java

/**
 * Return an iterator for the option labels or values, based on our
 * configured properties./*from  ww w  .  ja va2 s.c  o m*/
 * 
 * @param name
 *            Name of the bean attribute (if any)
 * @param property
 *            Name of the bean property (if any)
 * 
 * @exception JspException
 *                if an error occurs
 */
protected Iterator getIterator(String name, String property) throws JspException {

    // Identify the bean containing our collection
    String beanName = name;
    if (beanName == null) {
        beanName = Constants.BEAN_KEY;
    }
    Object bean = pageContext.findAttribute(beanName);
    if (bean == null) {
        throw new JspException(messages.getMessage("getter.bean", beanName));
    }

    // Identify the collection itself
    Object collection = bean;
    if (property != null) {
        try {
            collection = PropertyUtils.getProperty(bean, property);
            if (collection == null) {
                throw new JspException(messages.getMessage("getter.property", property));
            }
        } catch (IllegalAccessException e) {
            throw new JspException(messages.getMessage("getter.access", property, name));
        } catch (InvocationTargetException e) {
            Throwable t = e.getTargetException();
            throw new JspException(messages.getMessage("getter.result", property, t.toString()));
        } catch (NoSuchMethodException e) {
            throw new JspException(messages.getMessage("getter.method", property, name));
        }
    }

    // Construct and return an appropriate iterator
    if (collection.getClass().isArray()) {
        collection = Arrays.asList((Object[]) collection);
    }
    if (collection instanceof Collection) {
        return (((Collection) collection).iterator());
    } else if (collection instanceof Iterator) {
        return ((Iterator) collection);
    } else if (collection instanceof Map) {
        return (((Map) collection).entrySet().iterator());
    } else if (collection instanceof Enumeration) {
        return (IteratorUtils.asIterator((Enumeration) collection));
    } else {
        throw new JspException(messages.getMessage("optionsTag.iterator", collection.toString()));
    }

}

From source file:com.cisco.oss.foundation.http.server.MonitoringFilter.java

@Override
public void doFilterImpl(final ServletRequest request, final ServletResponse response, final FilterChain chain)
        throws IOException, ServletException {

    regiterMonitoring();/*from  w  w w . ja v  a 2 s.  c om*/

    final long startTime = System.currentTimeMillis();
    HttpServletRequest httpServletRequest = (HttpServletRequest) request;
    HttpServletResponse httpServletResponse = (HttpServletResponse) response;
    String tempMethodName = httpServletRequest.getMethod();
    if (uniqueUriMonitoringEnabled) {
        tempMethodName += ":" + httpServletRequest.getRequestURI();
    }

    boolean reportToMonitoring = true;

    try {
        LOGGER.trace("Monitoring filter: Request processing started at: {}", startTime);

        //         methodName = httpServletRequest.getMethod() + ":" + httpServletRequest.getRequestURI().toString();
        tempMethodName = updateMethodName(httpServletRequest, tempMethodName);

        LOGGER.trace("transaction method name is: {}", tempMethodName);

        CommunicationInfo.getCommunicationInfo().transactionStarted(serviceDetails, tempMethodName,
                threadPool != null ? threadPool.getThreads() : -1);

    } catch (Exception e) {
        LOGGER.error("can't report monitoring data as it has failed on:" + e);
        reportToMonitoring = false;
    }
    final String methodName = tempMethodName;

    try {
        chain.doFilter(httpServletRequest, httpServletResponse);

        if (request.isAsyncStarted()) {

            AsyncContext async = request.getAsyncContext();
            async.addListener(new AsyncListener() {
                @Override
                public void onComplete(AsyncEvent event) throws IOException {
                    final long endTime = System.currentTimeMillis();
                    final int processingTime = (int) (endTime - startTime);
                    LOGGER.debug("Processing time: {} milliseconds", processingTime);
                }

                @Override
                public void onTimeout(AsyncEvent event) throws IOException {

                }

                @Override
                public void onError(AsyncEvent event) throws IOException {
                    Throwable throwable = event.getThrowable();
                    if (throwable != null) {
                        CommunicationInfo.getCommunicationInfo().transactionFinished(serviceDetails, methodName,
                                true, throwable.toString());
                    }
                }

                @Override
                public void onStartAsync(AsyncEvent event) throws IOException {

                }
            });

        } else {
            final long endTime = System.currentTimeMillis();
            final int processingTime = (int) (endTime - startTime);
            LOGGER.debug("Processing time: {} milliseconds", processingTime);
        }

    } catch (Exception e) {
        CommunicationInfo.getCommunicationInfo().transactionFinished(serviceDetails, methodName, true,
                e.toString());
        throw e;
    }

    if (reportToMonitoring) {
        try {

            int status = httpServletResponse.getStatus();

            if (status >= 400) {
                CommunicationInfo.getCommunicationInfo().transactionFinished(serviceDetails, methodName, true,
                        httpServletResponse.getStatus() + "");

            } else {

                CommunicationInfo.getCommunicationInfo().transactionFinished(serviceDetails, methodName, false,
                        "");
            }
        } catch (Exception e) {
            LOGGER.error("can't report monitoring data as it has failed on:" + e);
        }
    }

}

From source file:edu.harvard.iq.dataverse.HandlenetServiceBean.java

public Throwable registerNewHandle(Dataset dataset) {
    logger.log(Level.FINE, "registerNewHandle");
    String handlePrefix = dataset.getAuthority();
    String handle = getDatasetHandle(dataset);
    String datasetUrl = getRegistrationUrl(dataset);

    logger.info("Creating NEW handle " + handle);

    String authHandle = getHandleAuthority(dataset);

    PublicKeyAuthenticationInfo auth = getAuthInfo(handlePrefix);
    HandleResolver resolver = new HandleResolver();

    try {//from w w  w  .j a  va 2s  .  co  m

        AdminRecord admin = new AdminRecord(authHandle.getBytes("UTF8"), 300, true, true, true, true, true,
                true, true, true, true, true, true, true);

        int timestamp = (int) (System.currentTimeMillis() / 1000);

        HandleValue[] val = {
                new HandleValue(100, "HS_ADMIN".getBytes("UTF8"), Encoder.encodeAdminRecord(admin),
                        HandleValue.TTL_TYPE_RELATIVE, 86400, timestamp, null, true, true, true, false),
                new HandleValue(1, "URL".getBytes("UTF8"), datasetUrl.getBytes(), HandleValue.TTL_TYPE_RELATIVE,
                        86400, timestamp, null, true, true, true, false) };

        CreateHandleRequest req = new CreateHandleRequest(handle.getBytes("UTF8"), val, auth);

        resolver.traceMessages = true;
        AbstractResponse response = resolver.processRequest(req);
        if (response.responseCode == AbstractMessage.RC_SUCCESS) {
            logger.info("Success! Response: \n" + response);
            return null;
        } else {
            logger.log(Level.WARNING, "registerNewHandle failed");
            logger.warning("Error response: \n" + response);
            return new Exception("registerNewHandle failed: " + response);
        }
    } catch (Throwable t) {
        logger.log(Level.WARNING, "registerNewHandle failed");
        logger.log(Level.WARNING, "String {0}", t.toString());
        logger.log(Level.WARNING, "localized message {0}", t.getLocalizedMessage());
        logger.log(Level.WARNING, "cause", t.getCause());
        logger.log(Level.WARNING, "message {0}", t.getMessage());
        return t;
    }
}

From source file:org.ireland.jnetty.webapp.ServletContextImpl.java

/**
 * Removes an attribute from the servlet context.
 * /*from   www .j  a  va2  s.  c  om*/
 * @param name
 *            the name of the attribute to remove.
 */
@Override
public void removeAttribute(String name) {
    Object oldValue;

    synchronized (_attributes) {
        oldValue = _attributes.remove(name);
    }

    // Call any listeners
    if (_applicationAttributeListeners != null) {
        ServletContextAttributeEvent event;

        event = new ServletContextAttributeEvent(this, name, oldValue);

        for (int i = 0; i < _applicationAttributeListeners.size(); i++) {
            ServletContextAttributeListener listener;

            Object objListener = _applicationAttributeListeners.get(i);
            listener = (ServletContextAttributeListener) objListener;

            try {
                listener.attributeRemoved(event);
            } catch (Throwable e) {
                log.debug(e.toString(), e);
            }
        }
    }
}

From source file:org.biopax.validator.impl.ValidatorImpl.java

private void execute(ExecutorService exec, final Rule rule, final Validation validation, final Object obj) {
    exec.execute(new Runnable() {
        @SuppressWarnings("unchecked") //obj can be either Model or a BPE
        public void run() {
            try {
                if (rule.canCheck(obj))
                    rule.check(validation, obj);
            } catch (Throwable t) {
                //if we're here, there is probably a bug in the rule or validator!
                String id = validation.identify(obj);
                log.fatal(rule + ".check(" + id + ") threw the exception: " + t.toString(), t);
                // anyway, report it almost normally (for a user to see this in the results too)
                validation.addError(//from www. j  a va 2  s  .  c  o m
                        utils.createError(id, "exception", rule.getClass().getName(), null, false, t));
            }
        }
    });
}

From source file:com.qmetry.qaf.automation.testng.pro.QAFTestNGListener.java

private String getFailureMessage(Throwable t) {
    if (null == t)
        return "";
    String msg = t.getMessage();//from  w  w  w . j a  va  2  s .  c om
    if (StringUtil.isNotBlank(msg))
        return msg;
    return t.toString();
}

From source file:it.tidalwave.northernwind.frontend.util.InitializationDiagnosticsDispatcherServletDecorator.java

/*******************************************************************************************************************
 *
 *
 ******************************************************************************************************************/
private void sendProcessingError(final @Nonnull Throwable t, final @Nonnull HttpServletResponse response)
        throws IOException {
    response.setStatus(500);//ww w. j a  va 2  s .  c  o m
    response.setContentType("text/html");
    final PrintWriter pw = new PrintWriter(new PrintStream(response.getOutputStream(), true, "UTF-8"));
    pw.print("<html>\n<head>\n<title>Configuration Error</title>\n</head>\n<body>\n");
    pw.print("<h1>Configuration Error</h1>\n<pre>\n");
    pw.print(t.toString());
    //        t.printStackTrace(pw);
    pw.print("</pre>\n");
    pw.print("<h2>Boot log</h2>\n<pre>\n");
    pw.print(BootLogger.getLogContent());
    pw.print("</pre></body>\n</html>");
    pw.close();
    response.getOutputStream().close();
}

From source file:com.sos.i18n.logging.commons.CommonsLogMsg.java

/**
 * Logs the message, along with the given <code>throwable</code>, at the warn level. If
 * {@link Logger#getDumpStackTraces() stack traces are not to be dumped}, the logged message will be appended
 * with the throwable's <code>Throwable.toString()</code> contents.
 *
 * @param log       where to log the message
 * @param key       the resource key that is associated with the message
 * @param msg       the message to log/*from   w  w w .  ja  v a  2  s . c  o  m*/
 * @param throwable the throwable associated with the message
 */
private static void logWarnWithThrowable(Log log, String key, Msg msg, Throwable throwable) {
    if (Logger.getDumpStackTraces()) {
        log.warn(((Logger.getDumpLogKeys()) ? ('{' + key + '}' + msg) : msg), throwable);
    } else {
        log.warn(((Logger.getDumpLogKeys()) ? ('{' + key + '}' + msg) : msg) + ". Cause: "
                + throwable.toString());
    }
}

From source file:com.sos.i18n.logging.commons.CommonsLogMsg.java

/**
 * Logs the message, along with the given <code>throwable</code>, at the info level. If
 * {@link Logger#getDumpStackTraces() stack traces are not to be dumped}, the logged message will be appended
 * with the throwable's <code>Throwable.toString()</code> contents.
 *
 * @param log       where to log the message
 * @param key       the resource key that is associated with the message
 * @param msg       the message to log//from   w w  w.ja  v a2 s  .co  m
 * @param throwable the throwable associated with the message
 */
private static void logInfoWithThrowable(Log log, String key, Msg msg, Throwable throwable) {
    if (Logger.getDumpStackTraces()) {
        log.info(((Logger.getDumpLogKeys()) ? ('{' + key + '}' + msg) : msg), throwable);
    } else {
        log.info(((Logger.getDumpLogKeys()) ? ('{' + key + '}' + msg) : msg) + ". Cause: "
                + throwable.toString());
    }
}