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:Debug.java

public static String getDebug(Throwable e, int max) {
    StringBuffer result = new StringBuffer();

    String datetime = timestamp.format(new Date()).toLowerCase();

    result.append(newline);/*from  w  w  w .j  a  v  a2s.com*/
    result.append("Throwable: " + ((e == null) ? "" : ("(" + e.getClass().getName() + ")")) + ":" + datetime
            + newline);
    result.append("Throwable: " + ((e == null) ? "null" : e.getLocalizedMessage()) + newline);
    result.append(newline);

    result.append(getStackTrace(e, max));

    result.append("Caught here:" + newline);
    result.append(getStackTrace(new Exception(), max, 1));
    //        Debug.dumpStack();
    result.append(newline);
    return result.toString();
}

From source file:fr.olympicinsa.riocognized.exception.ErrorMessage.java

public ErrorMessage(Throwable exception) {
    this.exception = exception;
    this.message = exception.getLocalizedMessage();
}

From source file:com.jsonstore.security.DPKBean.java

protected DPKBean(String json) throws JSONException {
    try {/*from   w  w w  .ja  v a 2 s.  co  m*/
        this.obj = JsonOrgModule.deserializeJSONObject(json);
    }

    catch (Throwable e) {
        throw new JSONException(e.getLocalizedMessage());
    }
}

From source file:org.eclipse.jubula.version.Vn.java

/** {@inheritDoc} */
public void start(BundleContext context) throws Exception {
    super.start(context);
    plugin = this;

    URL url = getBundle().getResource("version.properties"); //$NON-NLS-1$

    if (url != null) {
        Properties p = new Properties();
        InputStream versionInfo = null;
        try {//from  ww  w.  ja va 2  s . c om
            versionInfo = url.openStream();
            p.load(versionInfo);
            String versionString = StrSubstitutor.replace(p.getProperty(BUILD_VERSION_KEY), p);
            m_version = new Version(versionString);
        } catch (Throwable t) {
            log.warn(t.getLocalizedMessage(), t);
        } finally {
            if (versionInfo != null) {
                versionInfo.close();
            }
        }
    }
}

From source file:org.craftercms.security.utils.handlers.AbstractRestHandlerBase.java

protected void sendErrorMessage(int status, Throwable e, RequestContext context) throws IOException {
    sendMessage(status, e.getLocalizedMessage(), context);
}

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

private static boolean setFeature(File baseDir, File granule, SimpleFeature feature, String geometryName,
        String locationKey) {//w w  w .j ava  2s  . c o  m

    String granuleBaseName = FilenameUtils.getBaseName(granule.getAbsolutePath());

    // get attributes and copy them over
    try {
        AbstractGridFormat format = (AbstractGridFormat) GridFormatFinder.findFormat(granule);
        if (format == null || (format instanceof UnknownFormat)) {
            throw new IllegalArgumentException(
                    "Unable to find a reader for the provided file: " + granule.getAbsolutePath());
        }
        // can throw UnsupportedOperationsException
        final AbstractGridCoverage2DReader reader = (AbstractGridCoverage2DReader) format.getReader(granule,
                new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE));

        GeneralEnvelope originalEnvelope = reader.getOriginalEnvelope();

        ReferencedEnvelope bb = new ReferencedEnvelope(originalEnvelope);

        WKTReader wktReader = new WKTReader();
        Geometry the_geom = wktReader.read("POLYGON((" + bb.getMinX() + " " + bb.getMinY() + "," + bb.getMinX()
                + " " + bb.getMaxY() + "," + bb.getMaxX() + " " + bb.getMaxY() + "," + bb.getMaxX() + " "
                + bb.getMinY() + "," + bb.getMinX() + " " + bb.getMinY() + "))");

        Integer SRID = CRS.lookupEpsgCode(bb.getCoordinateReferenceSystem(), true);
        /*
         * TODO ETJ suggestion: String crsId =
         * CRS.lookupIdentifier(bb.getCoordinateReferenceSystem(), true);
         */
        if (SRID == null) {
            throw new IllegalArgumentException("Unable to get the EPSG code for the granule: " + granule);
        }
        the_geom.setSRID(SRID);

        feature.setAttribute(geometryName, the_geom);
        // TODO absolute
        feature.setAttribute(locationKey, granule.getName());
        // granule.getName().replaceAll("\\", "\\\\"));

        final File indexer = new File(baseDir, org.geotools.gce.imagemosaic.Utils.INDEXER_PROPERTIES);
        final Properties indexerProps = ImageMosaicProperties.getPropertyFile(indexer);

        /**
         * @see {@link #org.geotools.gce.imagemosaic.properties.RegExPropertiesCollector.collect(File)}
         */
        final String granuleName = FilenameUtils.getBaseName(granule.getName());

        if (indexerProps.getProperty("TimeAttribute") != null) {

            // Since timeattrib may be ranged, we may have 2 attribs to update
            String timePropNames[] = indexerProps.getProperty("TimeAttribute").split(";");

            for (String timePropName : timePropNames) {
                updateFeatureTimeAttrib(feature, baseDir, timePropName, indexerProps, granuleName);
            }
        }

        // TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO
        // TODO: the time attribute handling has been refact'ed in order to use proper regex files
        // and to support ranges.
        // Same should be done for Elevation, Runtime(?) and AdditionalDomain attributes.
        // Furthermore, proper SPI should be used for parsing.
        // All of this should be handled if possibile using GT libs, and not reimplementing
        // the parsing from scratch.
        // TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO

        if (indexerProps.getProperty("ElevationAttribute") != null) {
            // TODO move out of the cycle
            final File elevationRegex = new File(baseDir, "elevationregex.properties");
            final Properties elevProps = ImageMosaicProperties.getPropertyFile(elevationRegex);
            final Pattern elevPattern = Pattern.compile(elevProps.getProperty("regex"));
            // TODO move out of the cycle
            final Matcher matcher = elevPattern.matcher(granuleName);
            if (matcher.find()) {
                feature.setAttribute(indexerProps.getProperty("ElevationAttribute"),
                        Double.valueOf(matcher.group()));
            }
        }

        if (indexerProps.getProperty("RuntimeAttribute") != null) {
            // TODO move out of the cycle
            final File runtimeRegex = new File(baseDir, "runtimeregex.properties");
            final Properties runtimeProps = ImageMosaicProperties.getPropertyFile(runtimeRegex);
            final Pattern runtimePattern = Pattern.compile(runtimeProps.getProperty("regex"));
            // TODO move out of the cycle
            final Matcher matcher = runtimePattern.matcher(granuleName);
            if (matcher.find()) {
                feature.setAttribute(indexerProps.getProperty("RuntimeAttribute"),
                        Integer.valueOf(matcher.group()));
            }
        }

        return true;

    } catch (Throwable e) {
        if (LOGGER.isErrorEnabled())
            LOGGER.error(e.getLocalizedMessage(), e);
        return false;
    }

}

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

/**
 * add files to the passed datastore/*from  w  w w.j  ava2 s . co  m*/
 * 
 * @param addList
 * @param dataStore
 * @param store
 * @param locationKey
 * @param baseDir
 * @return
 */
private static boolean addFileToStore(List<File> addList, DataStore dataStore, String store,
        final String locationKey, final File baseDir) {

    // ADD FILES TO THE LAYER
    final String handle = "ImageMosaic:" + Thread.currentThread().getId();
    final Transaction transaction = new DefaultTransaction(handle);

    FeatureWriter<SimpleFeatureType, SimpleFeature> fw = null;
    try {

        fw = dataStore.getFeatureWriterAppend(store, transaction);
        if (fw == null) {
            if (LOGGER.isErrorEnabled()) {
                LOGGER.error("The FeatureWriter is null, it's impossible"
                        + " to get a writer on the dataStore: " + dataStore.toString());
            }
            return false;
        }

        // get the schema if this feature
        final FeatureType schema = fw.getFeatureType();

        // TODO check needed???
        final String geometryPropertyName = schema.getGeometryDescriptor().getLocalName();

        for (File file : addList) {
            // get the next feature to append
            SimpleFeature feature = fw.next();
            if (feature != null) {
                if (LOGGER.isInfoEnabled()) {
                    LOGGER.info("Updating feature for file " + file);
                }
                setFeature(baseDir, file, feature, geometryPropertyName, locationKey);
                fw.write();
            }
        }

        // commit
        transaction.commit();
    } catch (Exception e) {

        try {
            transaction.rollback();
        } catch (Throwable t) {
            if (LOGGER.isWarnEnabled()) {
                LOGGER.warn("Problem during rollback" + t.getLocalizedMessage(), t);
            }
        }
        return false;
    } finally {

        try {
            transaction.close();
        } catch (Throwable t) {
            if (LOGGER.isWarnEnabled()) {
                LOGGER.warn("Problem closing transaction: " + t.getLocalizedMessage(), t);
            }
        }
        if (fw != null) {
            try {
                fw.close();
            } catch (Throwable t) {
                if (LOGGER.isWarnEnabled()) {
                    LOGGER.warn("Problem closing transaction: " + t.getLocalizedMessage(), t);
                }
            }
        }
    }
    return true;
}

From source file:org.thehecklers.MQTTSubscriber.java

@Override
public void connectionLost(Throwable thrwbl) {
    System.out.println("Connection lost. Error: " + thrwbl.getLocalizedMessage());
}

From source file:org.opencms.gwt.A_CmsClientMessageBundle.java

/**
 * @see org.opencms.gwt.I_CmsClientMessageBundle#export(java.util.Locale)
 *//*from w  w w.  jav a  2s .c o  m*/
public String export(Locale locale) {

    JSONObject keys = new JSONObject();
    try {
        ResourceBundle resourceBundle = CmsResourceBundleLoader.getBundle(getBundleName(), locale);
        Enumeration<String> bundleKeys = resourceBundle.getKeys();
        while (bundleKeys.hasMoreElements()) {
            String bundleKey = bundleKeys.nextElement();
            keys.put(bundleKey, resourceBundle.getString(bundleKey));
        }
    } catch (Throwable e) {
        LOG.error(e.getLocalizedMessage(), e);
        try {
            keys.put("error", e.getLocalizedMessage());
        } catch (JSONException e1) {
            // ignore, should never happen
            LOG.error(e1.getLocalizedMessage(), e1);
        }
    }
    return getBundleName().replace('.', '_') + "=" + keys.toString() + ";";
}

From source file:org.openehealth.coala.lifecycle.FacesAppListener.java

@Override
public void processEvent(SystemEvent event) throws AbortProcessingException {

    /*/*  w  w w  .j  a v a  2 s  . c o m*/
     * STARTUP PHASE - nothing yet
     */
    if (event instanceof PostConstructApplicationEvent) {
        LOG.info("PostConstructApplicationEvent is called");
    }

    /*
     * SHUTDOWN PHASE - cleaning up PDQ/XDS ipf routes (mwiesner)
     */

    if (event instanceof PreDestroyApplicationEvent) {
        LOG.info("PreDestroyApplicationEvent is called");
        MBeanServer mbserver = null;

        ArrayList<MBeanServer> mbservers = MBeanServerFactory.findMBeanServer(null);

        if (mbservers.size() > 0) {
            mbserver = (MBeanServer) mbservers.get(0);
        }

        if (mbserver != null) {
            LOG.info("Found our MBean server instance...");
        } else {
            mbserver = MBeanServerFactory.createMBeanServer();
        }

        try {
            Set<ObjectInstance> mbeans = mbserver.queryMBeans(null, null);
            for (ObjectInstance mb : mbeans) {
                if (mb.getObjectName().getCanonicalName().contains("camelContext-pdq")) {
                    LOG.info("Successfully removed MBean: " + mb.getObjectName().getCanonicalName());
                    mbserver.unregisterMBean(mb.getObjectName());
                } else if (mb.getObjectName().getCanonicalName().contains("camelContext-xds")) {
                    LOG.info("Successfully removed MBean: " + mb.getObjectName().getCanonicalName());
                    mbserver.unregisterMBean(mb.getObjectName());
                }
            }
        } catch (InstanceNotFoundException infe) {
            LOG.warn("Ignoring to unregister pdq/xds camelContext, as it was not found!?");
        } catch (Throwable e) {
            LOG.error(e.getLocalizedMessage(), e);
        }
    }
}