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.openvpms.web.component.error.ThrowableAdapter.java

/**
 * Constructs a <tt>ThrowableAdapter</tt>.
 *
 * @param exception the exception/*from   w  w w .j ava 2s.c o  m*/
 */
public ThrowableAdapter(Throwable exception) {
    type = exception.getClass();
    message = exception.getLocalizedMessage();
    stackTrace = exception.getStackTrace();
    Throwable root = ExceptionUtils.getCause(exception);
    if (root != null) {
        cause = new ThrowableAdapter(root);
    }
}

From source file:com.kii.sample.hellothingif.MainActivity.java

private void registerJPush() {
    PromiseAPIWrapper api = new PromiseAPIWrapper(mAdm, mApi);
    mAdm.when(api.registerJPush(getApplicationContext())).then(new DoneCallback<Void>() {
        @Override/*from w ww  .j a  va2  s.c  o  m*/
        public void onDone(Void param) {
            Toast.makeText(MainActivity.this, "Succeeded push registration", Toast.LENGTH_LONG).show();
        }
    }).fail(new FailCallback<Throwable>() {
        @Override
        public void onFail(final Throwable tr) {
            Toast.makeText(MainActivity.this, "Error push registration:" + tr.getLocalizedMessage(),
                    Toast.LENGTH_LONG).show();
        }
    });
}

From source file:com.buddycloud.mediaserver.web.MediaServerResource.java

protected Representation unexpectedError(Throwable t) {
    LOGGER.error("Unexpected error: " + t.getLocalizedMessage(), t);

    setStatus(Status.SERVER_ERROR_INTERNAL);
    return new StringRepresentation("Unexpected error.", MediaType.APPLICATION_JSON);
}

From source file:com.tlabs.eve.api.EveRequest.java

public final T createError(Throwable t) {
    return createError(500, (null == t) ? null : t.getLocalizedMessage());
}

From source file:io.github.prefanatic.cleantap.ui.BeerSearchActivity.java

@Override
public void error(Throwable e) {
    Snackbar.make(recyclerView, e.getLocalizedMessage(), Snackbar.LENGTH_LONG).show();
}

From source file:it.geosolutions.geobatch.imagemosaic.ImageMosaicUpdater.java

/**
 * Try to update the datastore using the passed command and the
 * mosaicDescriptor as data and//w ww.  j  a va2  s . c  o  m
 * 
 * @param mosaicProp
 * @param dataStoreProp
 * @param mosaicDescriptor
 * @param cmd
 * @return boolean representing the operation success (true) or failure
 *         (false)
 * @throws IOException 
 * @throws ClassNotFoundException 
 * @throws IllegalAccessException 
 * @throws InstantiationException 
 * @throws IllegalArgumentException 
 */
protected static boolean updateDataStore(Properties mosaicProp, Properties dataStoreProp,
        ImageMosaicGranulesDescriptor mosaicDescriptor, ImageMosaicCommand cmd) throws IOException {

    if (mosaicProp == null) {
        if (LOGGER.isErrorEnabled()) {
            LOGGER.error("Unable to get mosaic properties.");
        }
        return false;
    }

    DataStore dataStore = null;
    try {
        // create the datastore
        dataStore = getDataStore(dataStoreProp);

        boolean absolute = isTrue(mosaicProp.get(org.geotools.gce.imagemosaic.Utils.Prop.ABSOLUTE_PATH));
        // does the layer use absolute path?
        if (!absolute) {
            /*
             * if we have some absolute path into delFile list we have to
             * skip those files since the layer is relative and acceptable
             * (to deletion) passed path are to be relative
             */
            List<File> files = null;
            if ((files = cmd.getDelFiles()) != null) {
                for (File file : files) {
                    if (file.isAbsolute()) {
                        /*
                         * this file can still be acceptable since it can be
                         * child of the layer baseDir
                         */
                        final String path = file.getAbsolutePath();
                        if (!path.contains(cmd.getBaseDir().getAbsolutePath())) {
                            // the path is absolute AND the file is outside
                            // the layer baseDir!
                            // files.remove(file); // remove it
                            // TODO move into a recoverable path to
                            // rollback!
                            // log as warning
                            if (LOGGER.isWarnEnabled()) {
                                LOGGER.warn("Layer specify a relative pattern for files but the "
                                        + "incoming xml command file has an absolute AND outside the layer baseDir file into the "
                                        + "delFile list! This file will NOT be removed from the layer: "
                                        + file.getAbsolutePath());
                            }
                        }
                    }
                }
            }
        }

        // TODO check object cast
        // the attribute key location
        final String locationKey = (String) mosaicProp
                .get(org.geotools.gce.imagemosaic.Utils.Prop.LOCATION_ATTRIBUTE);
        final String store = mosaicDescriptor.getCoverageStoreId();

        final List<File> delList = cmd.getDelFiles();
        Filter delFilter = null;
        // query
        if (!CollectionUtils.isEmpty(delList)) {
            try {
                delFilter = getQuery(delList, absolute, locationKey);
            } catch (Exception e) {
                if (LOGGER.isErrorEnabled()) {
                    LOGGER.error("Unable to build a query. Message: " + e, e);
                }
                return false;
            }

            // REMOVE features
            if (!removeFeatures(dataStore, store, delFilter)) {
                if (LOGGER.isWarnEnabled()) {
                    LOGGER.warn("Failed to remove features.");
                }
            } else {

                //
                // should we remove the files for good? #81
                // do we want to back them up? #84
                //
                final File backUpDirectory = cmd.getBackupDirectory();
                if (cmd.isDeleteGranules()) {
                    boolean delete = true;
                    if (backUpDirectory != null) {
                        //if we don't manage to move, we try to cancel
                        delete = (!backUpGranulesFiles(cmd.getDelFiles(), backUpDirectory));
                    }

                    // delete 
                    if (delete) {
                        deleteGranulesFiles(cmd.getDelFiles());
                    }
                }
            }
        } else {
            if (LOGGER.isInfoEnabled()) {
                LOGGER.info("No items to delete");
            }
        }

        //========================================
        // Handle the addFiles list
        //========================================

        // if it's empty, we'll return anyway. The config is telling us if it's a problem or not.
        // Notice that a un/marshalled empty list willb e probabily set to null
        if (CollectionUtils.isEmpty(cmd.getAddFiles())) {
            if (cmd.isIgnoreEmptyAddList()) {
                if (LOGGER.isInfoEnabled()) {
                    LOGGER.info("No items to add");
                }
                return true;
            } else {
                if (LOGGER.isErrorEnabled()) {
                    LOGGER.error("addFiles list is empty.");
                }
                return false;
            }
        }

        // Remove from addList the granules already in the mosaic.
        // TODO remove (ALERT please remove existing file from destination
        // for the copyListFileToNFS()
        if (!purgeAddFileList(cmd.getAddFiles(), dataStore, store, locationKey, cmd.getBaseDir(), absolute)) {
            return false;
        }

        // //////////////////////////////////
        if (cmd.getAddFiles() == null) { // side effect in previous method call? should not happen.
            if (LOGGER.isErrorEnabled()) {
                LOGGER.error("Filtered addFiles list is null.");
            }
            return false;
        } else if (cmd.getAddFiles().isEmpty()) {
            if (LOGGER.isWarnEnabled()) {
                LOGGER.warn("All requested files are already in the mosaic.");
            }
            return true;
        } else if (cmd.getAddFiles().size() > 0) {
            /*
             * copy purged addFiles list of files to the baseDir and replace
             * addFiles list with the new copied file list
             */
            // store copied file for rollback purpose
            List<File> addedFile = null;
            if (!absolute) {
                if (LOGGER.isInfoEnabled()) {
                    LOGGER.info("Starting file copy (" + cmd.getAddFiles().size() + " file/s)");
                }
                addedFile = Copy.copyListFileToNFS(cmd.getAddFiles(), cmd.getBaseDir(), false,
                        cmd.getNFSCopyWait());
            }
            if (!addFileToStore(addedFile, dataStore, store, locationKey, cmd.getBaseDir())) {
                if (LOGGER.isErrorEnabled())
                    LOGGER.error("Unable to update the new layer, removing copied files...");
                // if fails rollback the copied files
                if (addedFile != null) {
                    for (File file : addedFile) {
                        if (LOGGER.isWarnEnabled())
                            LOGGER.warn("ImageMosaicAction: DELETING -> " + file.getAbsolutePath());
                        // this is done since addedFiles are copied not moved
                        file.delete();
                    }
                }
            }
        } // addFiles size > 0

    } catch (Exception e) {

        if (LOGGER.isErrorEnabled()) {
            LOGGER.error(e.getLocalizedMessage(), e);
        }

        return false;

    } finally {
        if (dataStore != null) {
            try {
                dataStore.dispose();
            } catch (Throwable t) {
                if (LOGGER.isWarnEnabled()) {
                    LOGGER.warn(t.getLocalizedMessage(), t);
                }
            }
        }
    }
    return true;
}

From source file:org.kalypso.contribs.eclipse.core.runtime.StatusPrinter.java

public boolean print(final IStatus status) {
    final String severity = StatusUtilities.getLocalizedSeverity(status);

    if (status instanceof IStatusWithTime) {
        final Date time = ((IStatusWithTime) status).getTime();
        m_pw.print(m_df.format(time));//from  w  w w . j a  v  a 2 s  . co m
        m_pw.print(' ');
    }

    m_pw.print(StringUtils.repeat(' ', m_indentation));
    m_pw.print(severity);
    m_pw.print(": ");
    m_pw.print(status.getMessage());

    final Throwable exception = status.getException();
    if (exception != null)
        m_pw.format(" (Exception: %s)", exception.getLocalizedMessage());

    final IStatus[] children = status.getChildren();
    final StatusPrinter childrenPrinter = getChildPrinter();
    for (final IStatus child : children)
        childrenPrinter.print(child);

    m_pw.println();
    m_pw.flush();

    return true;
}

From source file:org.feistymeow.process.ethread.java

/**
 * this is the override from Runnable that allows us to call our own performActivity method. implementors should not override this; they
 * should override performActivity instead.
 *///from   w w  w .j a  va  2  s. c om
@Override
public void run() {
    if (!threadAlive()) {
        return; // stopped before it ever started. how can this be? we just got invoked.
    }
    try {
        while (true) {
            boolean keepGoing = performActivity();
            if (!keepGoing) {
                c_logger.debug("thread returned false, signifying it wants to exit.  now dropping it.");
                break;
            }
            if (c_period == 0) {
                // not a periodic thread, so we're done now.
                break;
            }
            long nextRun = System.currentTimeMillis() + c_period;
            while (System.currentTimeMillis() < nextRun) {
                if (shouldStop()) {
                    break;
                }
                try {
                    Thread.sleep(SNOOZE_PERIOD);
                } catch (InterruptedException e) {
                    // well, we'll hit it again soon.
                }
            }
        }
    } catch (Throwable t) {
        c_logger.info("exception thrown from performActivity: " + t.getLocalizedMessage(), t);
    }
    // reset the thread held since we're leaving right now.
    c_stopThread = true;
    c_RealThread = null;
}

From source file:org.eclipse.cdt.internal.p2.touchpoint.natives.actions.UnpackAction.java

@Override
public IStatus execute(Map<String, Object> parameters) {
    try {/*from   w w w .ja  va  2 s. co m*/
        String source = (String) parameters.get(PARM_SOURCE);
        if (source == null) {
            return Activator.getStatus(IStatus.ERROR,
                    String.format(Messages.UnpackAction_ParmNotPresent, PARM_SOURCE, ACTION_NAME));
        }

        String targetDir = (String) parameters.get(PARM_TARGET_DIR);
        if (targetDir == null) {
            return Activator.getStatus(IStatus.ERROR,
                    String.format(Messages.UnpackAction_ParmNotPresent, PARM_TARGET_DIR, ACTION_NAME));
        }

        String format = (String) parameters.get(PARM_FORMAT);
        if (format == null) {
            return Activator.getStatus(IStatus.ERROR,
                    String.format(Messages.UnpackAction_ParmNotPresent, PARM_FORMAT, ACTION_NAME));
        }

        IProfile profile = (IProfile) parameters.get("profile"); //$NON-NLS-1$
        File installFolder = new File(profile.getProperty(IProfile.PROP_INSTALL_FOLDER));
        File destDir = new File(installFolder, targetDir);
        if (destDir.exists()) {
            return Activator.getStatus(IStatus.ERROR, String.format(
                    org.eclipse.cdt.internal.p2.touchpoint.natives.actions.Messages.UnpackAction_TargetDirExists,
                    destDir.getAbsolutePath()));
        }

        URL url = new URL(source);
        InputStream fileIn = new BufferedInputStream(url.openStream());

        switch (format) {
        case "tar.gz": //$NON-NLS-1$
            InputStream gzIn = new GzipCompressorInputStream(fileIn);
            untar(gzIn, destDir);
            break;
        case "tar.bz2": //$NON-NLS-1$
            InputStream bzIn = new BZip2CompressorInputStream(fileIn);
            untar(bzIn, destDir);
            break;
        case "tar.xz": //$NON-NLS-1$
            InputStream xzIn = new XZCompressorInputStream(fileIn);
            untar(xzIn, destDir);
            break;
        case "zip": //$NON-NLS-1$

        }

        return Status.OK_STATUS;
    } catch (Throwable e) {
        return new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getLocalizedMessage(), e);
    }
}

From source file:org.deegree.framework.log.JCLLogger.java

public void logError(Throwable e) {
    if (e != null) {
        logError(e.getLocalizedMessage(), e);
    } else {/* ww  w .  j a  v a2 s.com*/
        logError("No exception to log.", new NullPointerException("No exception to log."));
    }
}