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.configuration.CmsADEManager.java

/**
 * Returns the favorite list, or creates it if not available.<p>
 *
 * @param cms the cms context/*from w w w .j a v  a 2s. c o  m*/
 * 
 * @return the favorite list
 * 
 * @throws CmsException if something goes wrong 
 */
public List<CmsContainerElementBean> getRecentList(CmsObject cms) throws CmsException {

    CmsUser user = cms.getRequestContext().getCurrentUser();
    Object obj = user.getAdditionalInfo(ADDINFO_ADE_RECENT_LIST);

    List<CmsContainerElementBean> recentList = new ArrayList<CmsContainerElementBean>();
    if (obj instanceof String) {
        try {
            JSONArray array = new JSONArray((String) obj);
            for (int i = 0; i < array.length(); i++) {
                try {
                    recentList.add(elementFromJson(array.getJSONObject(i)));
                } 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());
        }
    } else {
        // save to be better next time
        saveRecentList(cms, recentList);
    }

    return recentList;
}

From source file:im.ene.lab.attiq.ui.activities.ProfileActivity.java

@Override
protected void onResume() {
    super.onResume();
    // setup//  w w w.  ja  v  a  2  s.  com
    mOnFollowStateCallback = new Callback<Void>() {
        @Override
        public void onResponse(Call<Void> call, Response<Void> response) {
            ((State) mState).isFollowing = response != null && response.code() == 204;
            EventBus.getDefault()
                    .post(new StateEvent<>(ProfileActivity.class.getSimpleName(), true, null, mState));
        }

        @Override
        public void onFailure(Call<Void> call, Throwable t) {
            EventBus.getDefault().post(new StateEvent<>(ProfileActivity.class.getSimpleName(), false,
                    new Event.Error(Event.Error.ERROR_UNKNOWN, t.getLocalizedMessage()), null));
        }
    };

    mOnUnFollowStateCallback = new Callback<Void>() {
        @Override
        public void onResponse(Call<Void> call, Response<Void> response) {
            ((State) mState).isFollowing = response != null && !(response.code() == 204);
        }

        @Override
        public void onFailure(Call<Void> call, Throwable t) {
            EventBus.getDefault().post(new StateEvent<>(ProfileActivity.class.getSimpleName(), false,
                    new Event.Error(Event.Error.ERROR_UNKNOWN, t.getLocalizedMessage()), null));
        }
    };

    mOnUserCallback = new Callback<User>() {
        @Override
        public void onResponse(Call<User> call, Response<User> response) {
            User user = response.body();
            if (user != null) {
                Realm realm = Attiq.realm();
                realm.beginTransaction();
                realm.copyToRealmOrUpdate(user);
                realm.commitTransaction();
                realm.close();
                EventBus.getDefault()
                        .post(new UserFetchedEvent(ProfileActivity.class.getSimpleName(), true, null, user));
            } else {
                EventBus.getDefault().post(new UserFetchedEvent(ProfileActivity.class.getSimpleName(), false,
                        new Event.Error(response.code(), response.message()), null));
            }
        }

        @Override
        public void onFailure(Call<User> call, Throwable error) {
            EventBus.getDefault().post(new UserFetchedEvent(ProfileActivity.class.getSimpleName(), false,
                    new Event.Error(Event.Error.ERROR_UNKNOWN, error.getLocalizedMessage()), null));
        }
    };

    final String baseUrl = "http://qiita.com/" + mUserId;

    mDocumentCallback = new DocumentCallback(baseUrl) {
        @Override
        public void onDocument(Document response) {
            if (response != null) {
                EventBus.getDefault()
                        .post(new DocumentEvent(ProfileActivity.class.getSimpleName(), true, null, response));
            }
        }
    };

    WebUtil.loadWeb(baseUrl).enqueue(mDocumentCallback);

    // update UI
    if (mProfile != null) {
        EventBus.getDefault()
                .post(new ProfileUpdatedEvent(ProfileActivity.class.getSimpleName(), true, null, mProfile));
    }

    ApiClient.isFollowing(mUserId).enqueue(mOnFollowStateCallback);
    ApiClient.user(mUserId).enqueue(mOnUserCallback);
}

From source file:org.polymap.core.operation.OperationSupport.java

/**
 * Notifies all {@link IOperationSaveListener}s to persistently save
 * changes. If successful the history of operations is disposed.
 * //from www. j av a  2 s. c o  m
 * @throws Exception If the prepare save operation of any of the listeners
 *         failed.
 */
public void saveChanges() throws Exception {
    UIJob job = new UIJob(Messages.get("OperationSupport_saveChanges")) {
        protected void runWithException(IProgressMonitor monitor) throws Exception {

            monitor.beginTask(getName(), saveListeners.size() * 11);
            try {
                // prepare
                for (IOperationSaveListener listener : saveListeners) {
                    SubProgressMonitor subMon = new SubProgressMonitor(monitor, 10, "Preparing");
                    listener.prepareSave(OperationSupport.this, subMon);
                    if (monitor.isCanceled()) {
                        throw new OperationCanceledException("Operation wurde abgebrochen.");
                    }
                    subMon.done();
                }
                // commit
                for (IOperationSaveListener listener : saveListeners) {
                    SubProgressMonitor subMon = new SubProgressMonitor(monitor, 1, "Committing");
                    listener.save(OperationSupport.this, subMon);
                    subMon.done();
                }
                history.dispose(context, true, true, false);
            } catch (final Throwable e) {
                // rollback
                for (IOperationSaveListener listener : saveListeners) {
                    SubProgressMonitor subMon = new SubProgressMonitor(monitor, 1, "Rolling back");
                    listener.rollback(OperationSupport.this, subMon);
                    subMon.done();
                }
                Polymap.getSessionDisplay().asyncExec(new Runnable() {
                    public void run() {
                        PolymapWorkbench.handleError(CorePlugin.PLUGIN_ID, this, e.getLocalizedMessage(), e);
                    }
                });
            }
        }
    };
    // don't block the UI thread but use rules to prevent other
    // operations to change things during save
    job.setRule(new OneSaver());
    job.setShowProgressDialog(null, true);
    job.schedule();
}

From source file:org.sakaiproject.blti.ProviderServlet.java

public void doError(HttpServletRequest request, HttpServletResponse response, String s, String message,
        Throwable e) throws java.io.IOException {
    if (e != null) {
        M_log.error(e.getLocalizedMessage(), e);
    }//from   w w  w  .java 2  s  .  co  m
    M_log.info(rb.getString(s) + ": " + message);
    String return_url = request.getParameter(BasicLTIConstants.LAUNCH_PRESENTATION_RETURN_URL);
    if (return_url != null && return_url.length() > 1) {
        if (return_url.indexOf('?') > 1) {
            return_url += "&lti_msg=" + URLEncoder.encode(rb.getString(s), "UTF-8");
        } else {
            return_url += "?lti_msg=" + URLEncoder.encode(rb.getString(s), "UTF-8");
        }
        // Avoid Response Splitting
        return_url = return_url.replaceAll("[\r\n]", "");
        response.sendRedirect(return_url);
        return;
    }
    PrintWriter out = response.getWriter();
    out.println(rb.getString(s));
}

From source file:com.cloud.hypervisor.vmware.util.VmwareHelper.java

public static String getExceptionMessage(Throwable e, boolean printStack) {
    //TODO: in vim 5.1, exceptions do not have a base exception class, MethodFault becomes a FaultInfo that we can only get
    // from individual exception through getFaultInfo, so we have to use reflection here to get MethodFault information.
    try {//from  ww w  .  j a  va2 s .com
        Class<? extends Throwable> cls = e.getClass();
        Method mth = cls.getDeclaredMethod("getFaultInfo", (Class<?>) null);
        if (mth != null) {
            Object fault = mth.invoke(e, (Object[]) null);
            if (fault instanceof MethodFault) {
                final StringWriter writer = new StringWriter();
                writer.append("Exception: " + fault.getClass().getName() + "\n");
                writer.append("message: " + ((MethodFault) fault).getFaultMessage() + "\n");

                if (printStack) {
                    writer.append("stack: ");
                    e.printStackTrace(new PrintWriter(writer));
                }
                return writer.toString();
            }
        }
    } catch (Exception ex) {
        s_logger.info("[ignored]" + "failed toi get message for exception: " + e.getLocalizedMessage());
    }

    return ExceptionUtil.toString(e, printStack);
}

From source file:org.bedework.util.http.BasicHttpClient.java

/** Release the connection
 *
 * @throws HttpException//from   ww  w . j a va  2  s . com
 */
public void release() throws HttpException {
    try {
        HttpEntity ent = getResponseEntity();

        if (ent != null) {
            InputStream is = ent.getContent();
            is.close();
        }
    } catch (Throwable t) {
        throw new HttpException(t.getLocalizedMessage(), t);
    }
}

From source file:org.bedework.util.http.BasicHttpClient.java

/**
 * Returns the response body of the HTTP method, if any, as an {@link InputStream}.
 * If response body is not available, returns <tt>null</tt>
 *
 * @return InputStream    response body//www . ja  v a2  s  .  com
 * @throws HttpException
 */
public InputStream getResponseBodyAsStream() throws HttpException {
    try {
        HttpEntity ent = getResponseEntity();

        if (ent == null) {
            return null;
        }

        return ent.getContent();
    } catch (Throwable t) {
        throw new HttpException(t.getLocalizedMessage(), t);
    }
}

From source file:org.bedework.util.http.BasicHttpClient.java

public InputStream post(final String url, final List<Header> hdrs, final HttpEntity entity)
        throws HttpException {
    final HttpPost poster = new HttpPost(url);

    poster.setEntity(entity);/*from  w  ww.  java  2 s. co m*/

    try {
        // Make the request
        response = execute(poster);

        status = response.getStatusLine().getStatusCode();

        return getResponseBodyAsStream();
    } catch (final HttpException he) {
        throw he;
    } catch (final Throwable t) {
        throw new HttpException(t.getLocalizedMessage(), t);
    }
}

From source file:org.opencms.db.generic.CmsSubscriptionDriver.java

/**
 * Adds an entry to the table of visits.<p>
 * //from w  ww  .  j  av a  2s  .  c  om
 * @param dbc the database context to use 
 * @param poolName the name of the database pool to use 
 * @param visit the visit bean
 *  
 * @throws CmsDbSqlException if the database operation fails  
 */
protected void addVisit(CmsDbContext dbc, String poolName, CmsVisitEntry visit) throws CmsDbSqlException {

    Connection conn = null;
    PreparedStatement stmt = null;

    try {
        if (CmsStringUtil.isNotEmpty(poolName)) {
            conn = m_sqlManager.getConnection(poolName);
        } else {
            conn = m_sqlManager.getConnection(dbc);
        }

        stmt = m_sqlManager.getPreparedStatement(conn, "C_VISIT_CREATE_3");

        stmt.setString(1, visit.getUserId().toString());
        stmt.setLong(2, visit.getDate());
        stmt.setString(3, visit.getStructureId() == null ? null : visit.getStructureId().toString());
        try {
            stmt.executeUpdate();
        } catch (SQLException e) {
            // ignore, most likely a duplicate entry
            LOG.debug(Messages.get()
                    .container(Messages.ERR_GENERIC_SQL_1, CmsDbSqlException.getErrorQuery(stmt)).key(), e);
        }

    } catch (SQLException e) {
        throw new CmsDbSqlException(
                Messages.get().container(Messages.ERR_GENERIC_SQL_1, CmsDbSqlException.getErrorQuery(stmt)), e);
    } finally {
        try {
            m_sqlManager.closeAll(dbc, conn, stmt, null);
        } catch (Throwable t) {
            // this could happen during shutdown
            LOG.debug(t.getLocalizedMessage(), t);
        }
    }
}

From source file:net.refractions.udig.catalog.internal.CatalogImpl.java

/**
 * Returns a list of friendly resources working with related data.
 * <p>//from  w  w  w. ja  v  a 2  s  . c o  m
 * This method is used internally to determine resource handles that
 * offer different entry points to the same information.
 * </p>
 * A friend can be found via:
 * <ul>
 * <li>Making use of a CSW2.0 association
 * <li>URL Pattern matching for well known cases like GeoServer and MapServer
 * <li>Service Metadata, for example WMS resourceURL referencing a WFS SimpleFeatureType
 * </ul>
 * All of these handles will be returned from the find( URL, monitor ) method.
 * </ul>
 * @param handle
 * @return List of frends, possibly empty
 */
public List<IResolve> friends(final IResolve handle) {
    final List<IResolve> friends = new ArrayList<IResolve>();
    ExtensionPointUtil.process(CatalogPlugin.getDefault(), "net.refractions.udig.catalog.friendly", //$NON-NLS-1$
            new ExtensionPointProcessor() {
                /**
                 * Lets find our friends.
                 */
                public void process(IExtension extension, IConfigurationElement element) throws Exception {
                    try {
                        String target = element.getAttribute("target"); //$NON-NLS-1$
                        String contain = element.getAttribute("contain"); //$NON-NLS-1$
                        if (target != null) {
                            // perform target check
                            if (target.equals(target.getClass().toString())) {
                                return;
                            }
                        }
                        if (contain != null) {
                            String uri = handle.getIdentifier().toExternalForm();
                            if (!uri.contains(contain)) {
                                return;
                            }
                        }

                        IFriend friendly = (IFriend) element.createExecutableExtension("class"); //$NON-NLS-1$
                        friends.addAll(friendly.friendly(handle, null));
                    } catch (Throwable t) {
                        CatalogPlugin.log(t.getLocalizedMessage(), t);
                    }
                }
            });
    return friends;
}