Example usage for java.lang Throwable getLocalizedMessage

List of usage examples for java.lang Throwable getLocalizedMessage

Introduction

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

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:org.opencms.ade.sitemap.CmsVfsSitemapService.java

/**
 * Returns the deleted list from the current user.<p>
 * /* ww  w.j a v a2s  .c o  m*/
 * @return the deleted list
 */
private LinkedHashMap<CmsUUID, CmsClientSitemapEntry> getDeletedList() {

    CmsObject cms = getCmsObject();
    CmsUser user = cms.getRequestContext().getCurrentUser();
    Object obj = user.getAdditionalInfo(ADDINFO_ADE_DELETED_LIST);
    LinkedHashMap<CmsUUID, CmsClientSitemapEntry> result = new LinkedHashMap<CmsUUID, CmsClientSitemapEntry>();
    if (obj instanceof String) {
        try {
            JSONArray array = new JSONArray((String) obj);
            for (int i = 0; i < array.length(); i++) {
                try {
                    CmsUUID delId = new CmsUUID(array.getString(i));
                    CmsResource res = cms.readResource(delId, CmsResourceFilter.ALL);
                    if (res.getState().isDeleted()) {
                        // make sure resource is still deleted
                        CmsClientSitemapEntry delEntry = new CmsClientSitemapEntry();
                        delEntry.setSitePath(cms.getSitePath(res));
                        delEntry.setOwnProperties(getClientProperties(cms, res, false));
                        delEntry.setName(res.getName());
                        delEntry.setVfsPath(cms.getSitePath(res));
                        delEntry.setEntryType(res.isFolder() ? EntryType.folder
                                : isRedirectType(res.getTypeId()) ? EntryType.redirect : EntryType.leaf);
                        delEntry.setId(delId);
                        result.put(delId, delEntry);
                    }
                } catch (Throwable e) {
                    // should never happen, catches wrong or no longer existing values
                    LOG.warn(e.getLocalizedMessage());
                }
            }
        } catch (Throwable e) {
            // should never happen, catches json parsing
            LOG.warn(e.getLocalizedMessage());
        }
    }
    return result;
}

From source file:org.pentaho.platform.engine.services.runtime.RuntimeContext.java

protected void executeComponent(final ISolutionActionDefinition actionDefinition)
        throws ActionExecutionException {
    if (RuntimeContext.debug) {
        debug(Messages.getInstance().getString("RuntimeContext.DEBUG_STARTING_COMPONENT_EXECUTE")); //$NON-NLS-1$
    }//from  w  w  w  .j ava 2  s.  c o m
    try {
        if (getOutputPreference() == IOutputHandler.OUTPUT_TYPE_PARAMETERS
                && actionDefinition.getComponentName().contains("SecureFilterComponent")) {
            status = actionDefinition.getComponent().execute();
        } else if (getOutputPreference() != IOutputHandler.OUTPUT_TYPE_PARAMETERS) {
            status = actionDefinition.getComponent().execute();
        } else {
            status = IRuntimeContext.RUNTIME_STATUS_SUCCESS;
        }
        actionDefinition.getComponent().done();
        if (RuntimeContext.debug) {
            debug(Messages.getInstance().getString("RuntimeContext.DEBUG_FINISHED_COMPONENT_EXECUTE")); //$NON-NLS-1$
        }
        /*
         * We need to catch checked and unchecked exceptions here so we can create an ActionSequeceException with
         * contextual information, including the root cause. Allowing unchecked exceptions to pass through would
         * prevent valuable feedback in the log or response. Once the IComponent API changes to throw
         * ActionSequenceException from execute(), we may want to handle those specially here by allowing them to
         * pass through without a wrapping exception.
         */
    } catch (Throwable e) {
        status = IRuntimeContext.RUNTIME_STATUS_FAILURE;
        audit(MessageTypes.COMPONENT_EXECUTE_FAILED, MessageTypes.FAILED, e.getLocalizedMessage(), 0);
        throw new ActionExecutionException(
                Messages.getInstance().getErrorString("RuntimeContext.ERROR_0017_COMPONENT_EXECUTE_FAILED"), e, //$NON-NLS-1$
                session.getName(), instanceId, getActionSequence().getSequenceName(),
                actionDefinition.getComponent().getActionDefinition());
    }

    if (status != IRuntimeContext.RUNTIME_STATUS_SUCCESS) {
        throw new ActionExecutionException(
                Messages.getInstance().getErrorString("RuntimeContext.ERROR_0017_COMPONENT_EXECUTE_FAILED"), //$NON-NLS-1$
                session.getName(), instanceId, getActionSequence().getSequenceName(),
                actionDefinition.getComponent().getActionDefinition());
    }
}

From source file:org.apache.synapse.message.store.impl.jms.JmsProducer.java

public boolean storeMessage(MessageContext synCtx) {
    if (synCtx == null) {
        return false;
    }/*from w w  w  .  j a v  a 2  s.  c  o m*/
    if (!checkConnection()) {
        logger.warn(getId() + ". Ignored MessageID : " + synCtx.getMessageID());
        return false;
    }
    StorableMessage message = MessageConverter.toStorableMessage(synCtx);
    boolean error = false;
    Throwable throwable = null;
    try {
        ObjectMessage objectMessage = session.createObjectMessage(message);
        objectMessage.setStringProperty(OriginalMessageID, synCtx.getMessageID());
        setPriority(producer, objectMessage, message);
        setJmsProducerProperties(producer, synCtx);
        setJmsMessageProperties(objectMessage, synCtx);
        setTransportHeaders(objectMessage, synCtx);
        producer.send(objectMessage);

        if (session.getTransacted()) {
            session.commit();
        }

    } catch (JMSException e) {
        throwable = e;
        error = true;
        isConnectionError = true;

        try {

            if (session.getTransacted()) {
                session.rollback();
            }

        } catch (JMSException ex) {
            if (logger.isDebugEnabled()) {
                logger.debug("Fail to rollback message [" + synCtx.getMessageID() + "] from the message store "
                        + ":" + store.getName());
            }
        }

    } catch (Throwable t) {
        throwable = t;
        error = true;

        try {

            if (session.getTransacted()) {
                session.rollback();
            }

        } catch (JMSException e) {
            if (logger.isDebugEnabled()) {
                logger.debug("Fail to rollback message [" + synCtx.getMessageID() + "] from the message store "
                        + ":" + store.getName());
            }
        }
    }

    if (error) {
        String errorMsg = getId() + ". Ignored MessageID : " + synCtx.getMessageID()
                + ". Could not store message to store [" + store.getName() + "]. Error:"
                + throwable.getLocalizedMessage();
        logger.error(errorMsg, throwable);
        store.closeWriteConnection();
        connection = null;
        if (logger.isDebugEnabled()) {
            logger.debug(getId() + ". Ignored MessageID : " + synCtx.getMessageID());
        }
        return false;
    } else {
        store.cleanup(null, session, false);
    }
    if (logger.isDebugEnabled()) {
        logger.debug(getId() + ". Stored MessageID : " + synCtx.getMessageID());
    }
    store.enqueued();
    return true;
}

From source file:com.github.vatbub.tictactoe.view.Main.java

public void showErrorMessage(@SuppressWarnings("SameParameterValue") String errorMessage, Throwable e) {
    Throwable finalException;
    if (ExceptionUtils.getRootCause(e) != null) {
        finalException = ExceptionUtils.getRootCause(e);
    } else {/*from   w  w  w  .j ava  2s .  c o m*/
        finalException = e;
    }
    String errorText = finalException.getClass().getSimpleName();
    if (finalException.getLocalizedMessage() != null) {
        errorText = errorText + ": " + finalException.getLocalizedMessage();
    }
    showErrorMessage(errorMessage, errorText);
}

From source file:org.pentaho.platform.web.refactor.SubscriptionAdminUIComponent.java

Element getException(final String message, final Throwable t) {
    Element root = DocumentHelper.createElement(SubscriptionAdminUIComponent.NODE_EXCEPTION);
    if (message != null) {
        root.addElement("message").addText(message); //$NON-NLS-1$
    }// w ww.j a  v a  2 s  .  co  m

    // Some exceptions may have null messages, look for one in the chain.
    String exMsg = null;
    Throwable tmpT = t;
    while ((tmpT != null) && (exMsg == null)) {
        exMsg = tmpT.getLocalizedMessage();
        tmpT = tmpT.getCause();
    }

    root.addElement("exceptionMessage").addText((exMsg != null) ? exMsg //$NON-NLS-1$
            : Messages.getString("SubscriptionAdminUIComponent.ERROR_CAUSE_UNKNOWN", t.getClass().getName())); //$NON-NLS-1$
    return (root);
}

From source file:org.opencms.workplace.CmsWidgetDialog.java

/**
 * Creates the HTML for the error message if validation errors were found.<p>
 * /*from  ww w . j  a  va2 s .com*/
 * @return the HTML for the error message if validation errors were found
 */
protected String createWidgetErrorHeader() {

    StringBuffer result = new StringBuffer(8);
    if (hasValidationErrors() || hasCommitErrors()) {
        result.append("<tr><td colspan=\"5\">&nbsp;</td></tr>\n");
        result.append("<tr><td colspan=\"2\">&nbsp;</td>");
        result.append("<td class=\"xmlTdErrorHeader\">");
        result.append(key(Messages.GUI_EDITOR_WIDGET_VALIDATION_ERROR_TITLE_0));
        result.append("</td><td colspan=\"2\">&nbsp;");
        result.append("</td></tr>\n");
        result.append("<tr><td colspan=\"5\">&nbsp;</td></tr>\n");
        if (hasCommitErrors()) {
            result.append(dialogBlockStart(""));
            result.append(createWidgetTableStart());
            Iterator<Throwable> i = getCommitErrors().iterator();
            while (i.hasNext()) {
                Throwable t = i.next();
                result.append("<tr><td><img src=\"");
                result.append(getSkinUri()).append("editors/xmlcontent/");
                result.append("error.png");
                result.append("\" border=\"0\" alt=\"\"></td><td class=\"xmlTdError maxwidth\">");
                while (t != null) {
                    String message = "";
                    if (t instanceof I_CmsThrowable) {
                        message = ((I_CmsThrowable) t).getLocalizedMessage(getLocale());
                    } else {
                        message = t.getLocalizedMessage();
                    }
                    if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(message)) {
                        result.append(CmsStringUtil.escapeHtml(message));
                    }

                    t = t.getCause();
                    if (t != null) {
                        result.append("<br/>");
                    }
                }
                result.append("</td></tr>\n");
            }
            result.append(createWidgetTableEnd());
            result.append(dialogBlockEnd());
        }
        if (hasValidationErrors()) {
            result.append(dialogBlockStart(""));
            result.append(createWidgetTableStart());
            Iterator<Throwable> i = getValidationErrorList().iterator();
            while (i.hasNext()) {
                Throwable t = i.next();
                result.append("<tr><td><img src=\"");
                result.append(getSkinUri()).append("editors/xmlcontent/");
                result.append("error.png");
                result.append("\" border=\"0\" alt=\"\"></td><td class=\"xmlTdError maxwidth\">");
                while (t != null) {
                    String message = "";
                    if (t instanceof I_CmsThrowable) {
                        message = ((I_CmsThrowable) t).getLocalizedMessage(getLocale());
                    } else {
                        message = t.getLocalizedMessage();
                    }
                    result.append(CmsStringUtil.escapeHtml(message));
                    t = t.getCause();
                    if (t != null) {
                        result.append("<br>");
                    }
                }
                result.append("</td></tr>\n");
            }
            result.append(createWidgetTableEnd());
            result.append(dialogBlockEnd());
        }
    }
    return result.toString();
}

From source file:org.pentaho.platform.web.refactor.SubscriptionAdminUIComponent.java

/**
 * @return/*from   ww  w.  j a  v a 2  s .com*/
 */
private void doGetSchedulerStatus(Element root) {
    root = root.addElement(SubscriptionAdminUIComponent.NODE_SCHEDULER_STATUS);
    ISubscriptionScheduler subScheduler = PentahoSystem.get(ISubscriptionScheduler.class, this.getSession());
    int schedulerState = IScheduledJob.STATE_ERROR;
    try {
        schedulerState = subScheduler.getSchedulerState();
    } catch (Throwable t) {
        root.add(getErrorMessage(
                Messages.getString("SubscriptionAdminUIComponent.ERROR_GETTING_SCHEDULER_STATUS") //$NON-NLS-1$
                        + t.getLocalizedMessage()));
    }
    root.addAttribute("state", String.valueOf(schedulerState)); //$NON-NLS-1$
}

From source file:org.opencms.main.OpenCmsCore.java

/**
 * Invokes the GWT servlet from within OpenCms.<p>
 * //from w ww.j  a  v  a2  s .  co m
 * @param serviceName the GWT PRC service class name 
 * @param req the current servlet request
 * @param res the current servlet response
 * @param servletConfig the servlet configuration
 */
protected void invokeGwtService(String serviceName, HttpServletRequest req, HttpServletResponse res,
        ServletConfig servletConfig) {

    CmsObject cms = null;
    try {
        // instantiate CMS context
        cms = initCmsObject(req, res);
        // instantiate GWT RPC service
        CmsGwtService rpcService = getGwtService(serviceName, servletConfig);
        // check permissions
        rpcService.checkPermissions(cms);
        // set runtime variables
        rpcService.setCms(cms);
        try {
            Object lock = req.getSession();
            if (lock == null) {
                lock = new Object();
            }
            synchronized (lock) {
                rpcService.service(req, res);
            }
        } finally {
            // be sure to clear the cms context
            rpcService.setCms(null);
        }
    } catch (Throwable t) {
        // error code not set - set "internal server error" (500)
        LOG.error(t.getLocalizedMessage(), t);
        int status = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
        res.setStatus(status);
        try {
            res.sendError(status, t.toString());
        } catch (IOException e) {
            // can be ignored
            LOG.error(e.getLocalizedMessage(), e);
        }
    }
}

From source file:net.sourceforge.fenixedu.presentationTier.util.ExceptionInformation.java

public ExceptionInformation(HttpServletRequest request, Throwable ex) {
    StringBuilder tempBuilder = new StringBuilder();

    StringBuilder exceptionInfo = headerAppend(ex);

    // user/* w  w  w  . j av  a  2s  .com*/
    this.requestBean = userInfoContextAppend(request, exceptionInfo);

    // mapping
    mappingContextAppend(request, exceptionInfo);

    // requestContext
    requestContextAppend(request, tempBuilder);
    this.requestContext = tempBuilder.toString();
    exceptionInfo.append("\n[RequestContext] \n");
    exceptionInfo.append(tempBuilder);
    exceptionInfo.append("\n\n");
    tempBuilder.setLength(0);

    // sessionContext
    exceptionInfo.append("\n[SessionContext]\n");
    sessionContextAppend(request, tempBuilder);
    this.sessionContext = tempBuilder.toString();
    exceptionInfo.append(tempBuilder);
    exceptionInfo.append("\n\n");
    tempBuilder.setLength(0);

    // stackTrace
    stackTrace2StringAppend(ex.getStackTrace(), tempBuilder);
    this.stackTrace = tempBuilder.toString();
    exceptionInfo.append(tempBuilder);

    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    ex.printStackTrace(pw);
    String formattedST = sw.toString();
    this.formattedStackTrace = formattedST;

    ActionMapping mapping = this.getActionMapping();
    if (mapping != null) {
        StackTraceElement element = getStackTraceElementForActionMapping(request, mapping, ex.getStackTrace());
        if (element != null) {
            this.actionErrorFile = element.getFileName();
            this.actionErrorLine = element.getLineNumber();
        }
    }
    this.exceptionInfo = exceptionInfo.toString();

    if (ex.getClass().getName().equals("org.apache.jasper.JasperException")) {
        String message = ex.getLocalizedMessage();
        if (message.contains("\n")) {
            String[] name = message.split("\n");
            final Pattern lastIntPattern = Pattern.compile("([0-9]+)$");
            Matcher matcher = lastIntPattern.matcher(name[0]);
            if (matcher.find()) {
                jspExceptionLine = matcher.group(1);
                jspExceptionMessage = name[0];
                setJspExceptionSourceBefore(new ArrayList<JSPLine>());
                setJspExceptionSourceAfter(new ArrayList<JSPLine>());
                int state = 0;
                for (String s : Arrays.copyOfRange(name, 2, name.length - 3)) {
                    int i = s.indexOf(":");
                    JSPLine line = new JSPLine(s.substring(0, i).toString(),
                            s.substring(i + 1, s.length()).toString());
                    switch (state) {
                    case 0:
                        if (s.startsWith(jspExceptionLine)) {

                            setJspExceptionSourceLine(line);
                            state = 1;
                        } else {
                            getJspExceptionSourceBefore().add(line);
                        }
                        break;
                    case 1:
                        getJspExceptionSourceAfter().add(line);
                    default:
                        break;
                    }
                }
            }
        }
    }
}

From source file:com.lipy.android.http.exception.ActionException.java

public static Throwable handleException(java.lang.Throwable e) {

    Log.e("Novate", e.getMessage());
    Throwable ex;//from   ww  w  . j  av a2 s .  co m
    if (e instanceof HttpException) {
        HttpException httpException = (HttpException) e;
        ex = new Throwable(e, ERROR.HTTP_ERROR);
        switch (httpException.code()) {
        case UNAUTHORIZED:
            ex.setMessage("?");
        case FORBIDDEN:
            ex.setMessage("?");
        case NOT_FOUND:
            ex.setMessage("??");
        case REQUEST_TIMEOUT:
            ex.setMessage("");
        case GATEWAY_TIMEOUT:
            ex.setMessage("?");
        case INTERNAL_SERVER_ERROR:
            ex.setMessage("?");
        case BAD_GATEWAY:
            ex.setMessage("");
        case SERVICE_UNAVAILABLE:
            ex.setMessage("???");
        case ACCESS_DENIED:
            ex.setMessage("");
        case HANDEL_ERRROR:
            ex.setMessage("??");
        default:
            ex.setMessage(e.getMessage());
            break;
        }
        ex.setCode(httpException.code());
        return ex;
    } else if (e instanceof ServerException) {
        ServerException resultException = (ServerException) e;
        ex = new Throwable(resultException, resultException.code);
        ex.setMessage(resultException.getMessage());
        return ex;
    } else if (e instanceof JsonParseException || e instanceof JSONException || e instanceof ParseException) {
        ex = new Throwable(e, ERROR.PARSE_ERROR);
        ex.setMessage("?");
        return ex;
    } else if (e instanceof ConnectException) {
        ex = new Throwable(e, ERROR.NETWORD_ERROR);
        ex.setMessage("");
        return ex;
    } else if (e instanceof javax.net.ssl.SSLHandshakeException) {
        ex = new Throwable(e, ERROR.SSL_ERROR);
        ex.setMessage("??");
        return ex;
    } else if (e instanceof java.security.cert.CertPathValidatorException) {
        ex = new Throwable(e, ERROR.SSL_NOT_FOUND);
        ex.setMessage("?");
        return ex;
    } else if (e instanceof ConnectTimeoutException) {
        ex = new Throwable(e, ERROR.TIMEOUT_ERROR);
        ex.setMessage("");
        return ex;
    } else if (e instanceof java.net.SocketTimeoutException) {
        ex = new Throwable(e, ERROR.TIMEOUT_ERROR);
        ex.setMessage("");
        return ex;
    } else if (e instanceof ClassCastException) {
        ex = new Throwable(e, ERROR.FORMAT_ERROR);
        ex.setMessage("?");
        return ex;
    } else if (e instanceof NullPointerException) {
        ex = new Throwable(e, ERROR.NULL);
        ex.setMessage("?");
        return ex;
    } else if (e instanceof FormatException) {
        FormatException resultException = (FormatException) e;
        ex = new Throwable(resultException, resultException.code);
        ex.setMessage(resultException.message);
        return ex;
    } else {

        ex = new Throwable(e, ERROR.UNKNOWN);
        ex.setMessage(e.getLocalizedMessage());
        return ex;
    }
}