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.workplace.explorer.CmsResourceUtil.java

/**
 * Returns the name of the user who last modified the given resource.<p>
 * /*  www .  j  a  v  a2  s  . c  om*/
 * @return the name of the user who last modified the given resource
 */
public String getUserLastModified() {

    String user = m_resource.getUserLastModified().toString();
    try {
        user = getCurrentOuRelativeName(CmsPrincipal
                .readPrincipalIncludingHistory(getCms(), m_resource.getUserLastModified()).getName());
    } catch (Throwable e) {
        LOG.info(e.getLocalizedMessage());
    }
    return user;
}

From source file:org.opencms.workplace.explorer.CmsResourceUtil.java

/**
 * Returns the reference project resources.<p>
 * //w w w . java2s . co  m
 * @return the reference project resources
 */
private List<String> getProjectResources() {

    if (m_projectResources == null) {
        try {
            m_projectResources = getCms().readProjectResources(getReferenceProject());
        } catch (Throwable e) {
            LOG.error(e.getLocalizedMessage(), e);
            // use an empty list (all resources are "outside")
            m_projectResources = new ArrayList<String>();
        }
    }
    return m_projectResources;
}

From source file:org.geotools.gce.imagemosaic.ImageMosaicReaderTest.java

@Test
//    @Ignore   /*  ww  w.ja va 2 s .  com*/
public void errors() throws NoSuchAuthorityCodeException, FactoryException {
    final Hints hints = new Hints(Hints.DEFAULT_COORDINATE_REFERENCE_SYSTEM, CRS.decode("EPSG:4326", true));

    ////
    //
    // MOSAIC_LOCATION_ATTRIBUTE
    //
    // error for location attribute
    AbstractGridCoverage2DReader reader = null;
    try {
        LOGGER.info("Testing Invalid location attribute. (A DataSourceException should be catched) ");
        reader = (AbstractGridCoverage2DReader) ((AbstractGridFormat) GridFormatFinder.findFormat(rgbURL,
                hints)).getReader(rgbURL, new Hints(Hints.MOSAIC_LOCATION_ATTRIBUTE, "aaaa"));
        Assert.assertNull(reader);
    } catch (Throwable e) {
        Assert.fail(e.getLocalizedMessage());
    }
    //      try {
    //         reader=(AbstractGridCoverage2DReader) ((AbstractGridFormat) GridFormatFinder.findFormat(rgbJarURL)).getReader(rgbJarURL, new Hints(Hints.MOSAIC_LOCATION_ATTRIBUTE, "aaaa"));
    //         Assert.assertNull(reader);
    //      } catch (Throwable e) {
    //         Assert.fail(e.getLocalizedMessage());
    //      }

    try {
        reader = (AbstractGridCoverage2DReader) ((AbstractGridFormat) GridFormatFinder.findFormat(rgbURL,
                hints)).getReader(rgbURL, new Hints(Hints.MOSAIC_LOCATION_ATTRIBUTE, "location"));
        Assert.assertNotNull(reader);
        reader.dispose();
        Assert.assertTrue(true);
    } catch (Throwable e) {
        Assert.fail(e.getLocalizedMessage());
    }

    //      try {
    //         reader=(AbstractGridCoverage2DReader) ((AbstractGridFormat) GridFormatFinder.findFormat(rgbJarURL)).getReader(rgbJarURL, new Hints(Hints.MOSAIC_LOCATION_ATTRIBUTE, "location"));
    //         Assert.assertNotNull(reader);
    //         reader.dispose();
    //         Assert.assertTrue(true);
    //      } catch (Throwable e) {
    //         Assert.fail(e.getLocalizedMessage());
    //      }

    ////
    //
    // MAX_ALLOWED_TILES
    //
    ////
    // error for num tiles
    try {
        reader = (AbstractGridCoverage2DReader) ((AbstractGridFormat) GridFormatFinder.findFormat(rgbURL))
                .getReader(rgbURL, new Hints(Hints.MAX_ALLOWED_TILES, Integer.valueOf(2)));
        Assert.assertNotNull(reader);

        //read the coverage
        @SuppressWarnings("unused")
        GridCoverage2D gc = (GridCoverage2D) reader.read(null);
        Assert.fail("MAX_ALLOWED_TILES was not respected");
    } catch (Throwable e) {

        if (reader != null)
            reader.dispose();

        Assert.assertTrue(true);
    }

    try {
        reader = (AbstractGridCoverage2DReader) ((AbstractGridFormat) GridFormatFinder.findFormat(rgbURL))
                .getReader(rgbURL, new Hints(Hints.MAX_ALLOWED_TILES, Integer.valueOf(1000)));
        Assert.assertNotNull(reader);
        //read the coverage
        GridCoverage2D gc = (GridCoverage2D) reader.read(null);
        Assert.assertTrue(true);
        gc.dispose(true);
        reader.dispose();
    } catch (Exception e) {
        Assert.fail(e.getLocalizedMessage());
    }
}

From source file:org.geotools.gce.imagemosaic.ImageMosaicReader.java

/**
 * Init this {@link ImageMosaicReader} using the provided object as a source referring to an {@link URL}. 
 * /*  w  ww .  j  av  a 2  s. c o m*/
 * @param source
 * @param uHints
 * @throws DataSourceException
 */
private void initReaderFromURL(final Object source, final Hints hints) throws Exception {
    this.sourceURL = Utils.checkSource(source, hints);
    if (this.sourceURL == null)
        throw new DataSourceException(
                "This plugin accepts File, URL or String. The string may describe a File or an URL");

    //
    // Load properties file with information about levels and envelope
    //
    MosaicConfigurationBean configuration = Utils.loadMosaicProperties(sourceURL, this.locationAttributeName);
    if (configuration == null) {
        //
        // do we have a datastore properties file? It will preempt on the shapefile
        //
        final File parent = DataUtilities.urlToFile(sourceURL).getParentFile();

        // this can be used to look for properties files that do NOT define a datastore
        final File[] properties = parent.listFiles((FilenameFilter) FileFilterUtils.and(
                FileFilterUtils.notFileFilter(FileFilterUtils.nameFileFilter("indexer.properties")),
                FileFilterUtils.and(
                        FileFilterUtils.notFileFilter(FileFilterUtils.nameFileFilter("datastore.properties")),
                        FileFilterUtils.makeFileOnly(FileFilterUtils.suffixFileFilter(".properties")))));

        // do we have a valid datastore + mosaic properties pair?
        for (File propFile : properties)
            if (Utils.checkFileReadable(propFile)
                    && Utils.loadMosaicProperties(DataUtilities.fileToURL(propFile), "") != null) {
                configuration = Utils.loadMosaicProperties(DataUtilities.fileToURL(propFile),
                        this.locationAttributeName);
            }

    }
    if (configuration == null)
        throw new DataSourceException(
                "Unable to create reader for this mosaic since we could not parse the configuration.");

    // now load the configuration and extract properties from there
    extractProperties(configuration);

    //location attribute override
    if (this.hints.containsKey(Hints.MOSAIC_LOCATION_ATTRIBUTE)) {
        this.locationAttributeName = ((String) this.hints.get(Hints.MOSAIC_LOCATION_ATTRIBUTE));
    }

    //
    // Load tiles informations, especially the bounds, which will be
    // reused
    //
    try {
        // create the index
        catalog = GranuleCatalogFactory.createGranuleCatalog(sourceURL, configuration);
        // error
        if (catalog == null) {
            throw new DataSourceException("Unable to create index for this URL " + sourceURL);
        }
        final SimpleFeatureType type = catalog.getType();
        if (type == null) {
            throw new IllegalArgumentException(
                    "Problems when opening the index, no typenames for the schema are defined");
        }

        // additional domain properties
        SimpleFeatureType schema = catalog.getType();
        if (configuration.getAdditionalDomainAttributes() != null) {
            domainsManager = new DomainManager(configuration.getAdditionalDomainAttributes(), schema);
        }
        // time attribute
        if (configuration.getTimeAttribute() != null) {
            final HashMap<String, String> init = new HashMap<String, String>();
            init.put("TIME", configuration.getTimeAttribute());
            timeDomainManager = new DomainManager(init, schema);
        }
        // elevation attribute
        if (configuration.getElevationAttribute() != null) {
            final HashMap<String, String> init = new HashMap<String, String>();
            init.put("ELEVATION", configuration.getElevationAttribute());
            elevationDomainManager = new DomainManager(init, schema);
        }

        // everything is fine
        if (LOGGER.isLoggable(Level.FINE))
            LOGGER.fine("Connected mosaic reader to its index " + sourceURL.toString());

        setGridGeometry(configuration.getEnvelope());

        //
        // get the crs if able to
        //
        final Object tempCRS = this.hints.get(Hints.DEFAULT_COORDINATE_REFERENCE_SYSTEM);
        if (tempCRS != null) {
            this.crs = (CoordinateReferenceSystem) tempCRS;
            LOGGER.log(Level.WARNING, "Using forced coordinate reference system ");
        } else {
            final CoordinateReferenceSystem tempcrs = type.getGeometryDescriptor()
                    .getCoordinateReferenceSystem();
            if (tempcrs == null) {
                // use the default crs
                crs = AbstractGridFormat.getDefaultCRS();
                LOGGER.log(Level.WARNING, "Unable to find a CRS for this coverage, using a default one");
            } else
                crs = tempcrs;
        }

        //
        // perform checks on location attribute name
        //
        if (this.locationAttributeName == null) {
            throw new DataSourceException("The provided name for the location attribute is invalid.");
        } else {
            if (type.getDescriptor(this.locationAttributeName) == null) {
                // ORACLE fix
                this.locationAttributeName = this.locationAttributeName.toUpperCase();

                // try again with uppercase
                if (type.getDescriptor(this.locationAttributeName) == null) {
                    throw new DataSourceException("The provided name for the location attribute is invalid.");
                }
            }
        }

        // creating the raster manager
        rasterManager = new RasterManager(this);
    } catch (Throwable e) {
        try {
            if (catalog != null) {
                catalog.dispose();
            }
        } catch (Throwable e1) {
            if (LOGGER.isLoggable(Level.FINEST)) {
                LOGGER.log(Level.FINEST, e1.getLocalizedMessage(), e1);
            }
        } finally {
            catalog = null;
        }

        // dispose raster manager as well
        try {
            if (rasterManager != null)
                rasterManager.dispose();
        } catch (Throwable e1) {
            if (LOGGER.isLoggable(Level.FINEST))
                LOGGER.log(Level.FINEST, e1.getLocalizedMessage(), e1);
        } finally {
            rasterManager = null;
        }

        // rethrow
        throw new DataSourceException(e);
    }

}

From source file:org.opencms.workplace.explorer.CmsResourceUtil.java

/**
 * Returns the the lock for the given resource.<p>
 * //from   w ww  . ja va2 s .c  o  m
 * @return the lock the given resource
 */
public CmsLock getLock() {

    if (m_lock == null) {
        try {
            m_lock = getCms().getLock(m_resource);
        } catch (Throwable e) {
            m_lock = CmsLock.getNullLock();
            LOG.error(e.getLocalizedMessage(), e);
        }
    }
    return m_lock;
}

From source file:de.duenndns.ssl.MemorizingTrustManager.java

private String certChainMessage(final X509Certificate[] chain, CertificateException cause) {
    Throwable e = cause;
    LOGGER.log(Level.FINE, "certChainMessage for " + e);
    StringBuffer si = new StringBuffer();
    if (e.getCause() != null) {
        e = e.getCause();/* w ww  .jav  a2 s  .  c o  m*/
        // HACK: there is no sane way to check if the error is a "trust anchor
        // not found", so we use string comparison.
        if (NO_TRUST_ANCHOR.equals(e.getMessage())) {
            si.append(master.getString(R.string.mtm_trust_anchor));
        } else
            si.append(e.getLocalizedMessage());
        si.append("\n");
    }
    si.append("\n");
    si.append(master.getString(R.string.mtm_connect_anyway));
    si.append("\n\n");
    si.append(master.getString(R.string.mtm_cert_details));
    for (X509Certificate c : chain) {
        certDetails(si, c);
    }
    return si.toString();
}

From source file:org.openehealth.coala.beans.ConsentBean.java

/**
 * Gets the logged-in user and sets him as an author.
 * Then takes the 5 parameters(patient, validFrom, validUntil, policy, author) which are
 * given by the user and puts them into a patient consent and tries to send it to pxsQuery.
 * //from  w w w.  j  av a 2  s.  c om
 * @return
 */
public String registerConsent() {
    FacesContext fc = FacesContext.getCurrentInstance();

    // Replaced dependency to eHF with fixed mocks for the time being.
    author = new CoalaAuthor("testTitle", "testFirstName", "testLastName");

    UIViewRoot uiRoot = FacesContext.getCurrentInstance().getViewRoot();

    try {
        // try to register now, as we have all relevant data for it
        consentCreationService.createPatientConsent(selectedPatient, validFrom, validUntil, policy, author);
        setSuccessfulRegistration(true);
        setErrorfulRegistration(false);
        // show successful creation panel to the user
        UIPopupPanel consentCreationSuccessDialog = (UIPopupPanel) uiRoot
                .findComponent("consentCreationSuccessDialog");
        if (consentCreationSuccessDialog != null) {
            consentCreationSuccessDialog.setShow(true);
            LOG.info("[CONSENT CREATION] ok, showing success PopUpPanel");
        }
        // cleanup selected values here, as they are outdated now.
        setValidFrom(null);
        setValidUntil(null);
        setPolicy(PatientConsentPolicy.ONE);
        setValidationSuccessful(false);
        return "patientSearch";

    } catch (Throwable t) {
        setErrorfulRegistration(true);
        setSuccessfulRegistration(false);
        UIPopupPanel consentCreationErrorDialog = (UIPopupPanel) uiRoot
                .findComponent("consentCreationErrorDialog");
        if (consentCreationErrorDialog != null) {
            consentCreationErrorDialog.setShow(true);
            LOG.warn("[CONSENT CREATION] failed, showing error PopUpPanel");
        }
        setValidationSuccessful(false);

        FacesMessage msg = new FacesMessage("Could not create consent.");
        msg.setSeverity(FacesMessage.SEVERITY_ERROR);
        fc.addMessage(null, msg);

        LOG.error(t.getLocalizedMessage(), t);
        // TODO Maybe add Facesmessage for display in ErrorPanelDialog
    }
    return "createConsent";
}

From source file:com.jkoolcloud.tnt4j.streams.inputs.TNTInputStream.java

private void shutdownStream() {
    if (isShotDown()) {
        return;//from   w w w .  jav a  2s  .com
    }

    endTime = System.currentTimeMillis();
    if (!failureFlag.get()) {
        notifyStreamSuccess();
    }

    try {
        cleanup();
    } catch (Throwable exc) {
        logger().log(OpLevel.ERROR, StreamsResources.getString(StreamsResources.RESOURCE_BUNDLE_NAME,
                "TNTInputStream.failed.cleanup.stream"), exc.getLocalizedMessage(), exc);
        notifyStreamEvent(OpLevel.ERROR,
                StreamsResources.getStringFormatted(StreamsResources.RESOURCE_BUNDLE_NAME,
                        "TNTInputStream.failed.cleanup.stream", exc.getLocalizedMessage()),
                name);
    }

    notifyFinished();

    logger().log(OpLevel.INFO,
            StreamsResources.getString(StreamsResources.RESOURCE_BUNDLE_NAME, "TNTInputStream.thread.ended"),
            Thread.currentThread().getName());
    logger().log(OpLevel.INFO, StreamsResources.getString(StreamsResources.RESOURCE_BUNDLE_NAME,
            "TNTInputStream.stream.statistics"), name, getStreamStatistics());

    removeListeners();

    if (isOwned()) {
        ownerThread.notifyCompleted();
    }
}

From source file:cn.sinobest.jzpt.framework.utils.string.StringUtils.java

/**
 * /*from ww  w.  j av a2 s.  c o m*/
 *
 * @param e
 * @return
 */
public static String exceptionSummary(Throwable e) {
    String msg = e.getLocalizedMessage();
    StackTraceElement[] stacks = e.getStackTrace();
    if (msg == null && e.getCause() != null) {
        msg = exceptionSummary(e.getCause());
    }
    String stack = stacks.length > 0 ? stacks[0].toString() : "";
    return StringUtils.concat(e.getClass().getSimpleName(), ":", msg, "\r\n", stack);
}

From source file:org.apache.synapse.message.store.impl.rabbitmq.RabbitMQStore.java

/**
 * @return new MessageProducer// w ww . ja v  a  2  s  . c om
 */
public MessageProducer getProducer() {
    RabbitMQProducer producer = new RabbitMQProducer(this);
    producer.setId(nextProducerId());
    if (exchangeName != null) {
        producer.setQueueName(routeKey);
        producer.setExchangeName(exchangeName);
    } else {
        producer.setQueueName(queueName);
        producer.setExchangeName(null);
        if (logger.isDebugEnabled()) {
            logger.debug(nameString() + " exchange is not defined, using default exchange and "
                    + "queue name for routing messages");
        }
    }

    Throwable throwable = null;
    boolean error = false;
    try {
        synchronized (producerLock) {
            if (producerConnection == null) {
                boolean ok = newProducerConnection();
                //if its not possible to create a producer connection, return messagePeoducer
                //without a connection
                if (!ok) {
                    return producer;
                }
            }
            if (!producerConnection.isOpen()) {
                producerConnection = connectionFactory.newConnection();
            }
        }
        producer.setConnection(producerConnection());
    } catch (Throwable t) {
        error = true;
        throwable = t;
    }
    if (error) {
        String errorMsg = "Could not create a Message Producer for " + nameString() + ". Error:"
                + throwable.getLocalizedMessage();
        logger.error(errorMsg, throwable);
        synchronized (producerLock) {
            cleanup(producerConnection, true);
            producerConnection = null;
        }
        return producer;
    }
    if (logger.isDebugEnabled()) {
        logger.debug(nameString() + " created message producer " + producer.getId());
    }
    return producer;
}