Example usage for java.lang Exception getLocalizedMessage

List of usage examples for java.lang Exception getLocalizedMessage

Introduction

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

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:com.amalto.core.objects.DroppedItemPOJO.java

/**
 * load a dropped item//from  w w w . j  a  va 2 s.  c  o m
 */
public static DroppedItemPOJO load(DroppedItemPOJOPK droppedItemPOJOPK) throws XtentisException {
    if (droppedItemPOJOPK == null) {
        return null;
    }
    ItemPOJOPK refItemPOJOPK = droppedItemPOJOPK.getRefItemPOJOPK();
    String actionName = "load"; //$NON-NLS-1$
    //for load we need to be admin, or have a role of admin , or role of write on instance or role of read on instance
    rolesFilter(refItemPOJOPK, actionName, "r"); //$NON-NLS-1$
    //get XmlServerSLWrapperLocal
    XmlServer server = Util.getXmlServerCtrlLocal();
    //load the dropped item
    try {
        //retrieve the dropped item
        String droppedItemStr = server.getDocumentAsString(MDM_ITEMS_TRASH, droppedItemPOJOPK.getUniquePK());
        if (droppedItemStr == null) {
            return null;
        }
        return MarshallingFactory.getInstance().getUnmarshaller(DroppedItemPOJO.class)
                .unmarshal(new StringReader(droppedItemStr));
    } catch (Exception e) {
        String err = "Unable to load the dropped item  " + droppedItemPOJOPK.getUniquePK() + ": "
                + e.getClass().getName() + ": " + e.getLocalizedMessage();
        LOGGER.error(err, e);
        throw new XtentisException(err, e);
    }
}

From source file:com.amalto.core.objects.DroppedItemPOJO.java

/**
 * remove a dropped item record/*from   w  ww .  j av a  2  s . co m*/
 */
public static DroppedItemPOJOPK remove(DroppedItemPOJOPK droppedItemPOJOPK) throws XtentisException {
    if (droppedItemPOJOPK == null) {
        return null;
    }
    ItemPOJOPK refItemPOJOPK = droppedItemPOJOPK.getRefItemPOJOPK();
    String actionName = "remove"; //$NON-NLS-1$
    //for remove we need to be admin, or have a role of admin , or role of write on instance
    rolesFilter(refItemPOJOPK, actionName, "w"); //$NON-NLS-1$
    //get XmlServerSLWrapperLocal
    XmlServer server = Util.getXmlServerCtrlLocal();
    try {
        //remove the record
        long res = server.deleteDocument(MDM_ITEMS_TRASH, droppedItemPOJOPK.getUniquePK());
        if (res == -1) {
            return null;
        }
        return droppedItemPOJOPK;
    } catch (Exception e) {
        String err = "Unable to " + actionName + " the dropped item " + droppedItemPOJOPK.getUniquePK() + ": "
                + e.getClass().getName() + ": " + e.getLocalizedMessage();
        LOGGER.error(err, e);
        throw new XtentisException(err, e);
    }
}

From source file:it.geosolutions.geobatch.geotiff.retile.GeotiffRetilerAction.java

/**
 * @deprecated replaced by {@link #GeoTiffRetilerUtils.reTile(...)}
 */// w  w w  . j a v a 2s. com
@Deprecated
public static void reTile(File inFile, File tiledTiffFile, double compressionRatio, String compressionType,
        int tileW, int tileH, boolean forceBigTiff) throws IOException {
    //
    // look for a valid file that we can read
    //

    AbstractGridFormat format = null;
    AbstractGridCoverage2DReader reader = null;
    GridCoverage2D inCoverage = null;
    AbstractGridCoverageWriter writer = null;
    final Hints hints = new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE);

    // getting a format for the given input
    format = (AbstractGridFormat) GridFormatFinder.findFormat(inFile, hints);
    if (format == null || (format instanceof UnknownFormat)) {
        throw new IllegalArgumentException("Unable to find the GridFormat for the provided file: " + inFile);
    }

    try {
        //
        // ACQUIRING A READER
        //
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("Acquiring a reader for the provided file...");
        }

        // can throw UnsupportedOperationsException
        reader = (AbstractGridCoverage2DReader) format.getReader(inFile, hints);

        if (reader == null) {
            final IOException ioe = new IOException("Unable to find a reader for the provided file: " + inFile);
            throw ioe;
        }

        //
        // ACQUIRING A COVERAGE
        //
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("Acquiring a coverage provided file...");
        }
        inCoverage = (GridCoverage2D) reader.read(null);
        if (inCoverage == null) {
            final IOException ioe = new IOException("inCoverage == null");
            throw ioe;
        }

        //
        // PREPARING A WRITE
        //
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("Writing down the file in the decoded directory...");
        }

        final GeoTiffFormat wformat = new GeoTiffFormat();
        final GeoTiffWriteParams wp = new GeoTiffWriteParams();
        if (!Double.isNaN(compressionRatio) && compressionType != null) {
            wp.setCompressionMode(GeoTiffWriteParams.MODE_EXPLICIT);
            wp.setCompressionType(compressionType);
            wp.setCompressionQuality((float) compressionRatio);
        }
        wp.setForceToBigTIFF(forceBigTiff);
        wp.setTilingMode(GeoToolsWriteParams.MODE_EXPLICIT);
        wp.setTiling(tileW, tileH);
        final ParameterValueGroup wparams = wformat.getWriteParameters();
        wparams.parameter(AbstractGridFormat.GEOTOOLS_WRITE_PARAMS.getName().toString()).setValue(wp);

        //
        // ACQUIRING A WRITER AND PERFORMING A WRITE
        //
        writer = (AbstractGridCoverageWriter) new GeoTiffWriter(tiledTiffFile);
        writer.write(inCoverage,
                (GeneralParameterValue[]) wparams.values().toArray(new GeneralParameterValue[1]));

    } finally {
        //
        // PERFORMING FINAL CLEAN UP AFTER THE WRITE PROCESS
        //
        if (reader != null) {
            try {
                reader.dispose();
            } catch (Exception e) {
                if (LOGGER.isWarnEnabled())
                    LOGGER.warn(e.getLocalizedMessage(), e);
            }

        }

        if (writer != null) {
            try {
                writer.dispose();
            } catch (Exception e) {
                if (LOGGER.isWarnEnabled())
                    LOGGER.warn(e.getLocalizedMessage(), e);
            }

        }

        if (inCoverage != null) {
            final RenderedImage initImage = inCoverage.getRenderedImage();
            ImageReader r = (ImageReader) initImage.getProperty(ImageReadDescriptor.PROPERTY_NAME_IMAGE_READER);
            try {
                r.dispose();
            } catch (Exception e) {
                if (LOGGER.isWarnEnabled())
                    LOGGER.warn("GeotiffRetiler::reTile(): " + e.getLocalizedMessage(), e);
            }

            // dispose
            ImageUtilities.disposePlanarImageChain(PlanarImage.wrapRenderedImage(initImage));

        }
    }

}

From source file:com.amalto.core.objects.DroppedItemPOJO.java

/**
 * find all pks of dropped items/*ww w. j a v  a 2 s  .  c o  m*/
 */
public static List<DroppedItemPOJOPK> findAllPKs(String regex) throws XtentisException {
    // get XmlServerSLWrapperLocal
    XmlServer server = Util.getXmlServerCtrlLocal();
    if ("".equals(regex) || "*".equals(regex) || ".*".equals(regex)) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        regex = null;
    }
    try {
        //retrieve the item
        String[] ids = server.getAllDocumentsUniqueID(MDM_ITEMS_TRASH);
        if (ids == null) {
            return Collections.emptyList();
        }
        //build PKs collection
        List<DroppedItemPOJOPK> list = new ArrayList<DroppedItemPOJOPK>();

        Map<String, ComplexTypeMetadata> conceptMap = new HashMap<String, ComplexTypeMetadata>();
        for (String uid : ids) {
            String[] uidValues = uid.split("\\."); //$NON-NLS-1$
            ItemPOJOPK refItemPOJOPK;
            if (uidValues.length < 3) {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Could not read id '" + uid + "'. Skipping it.");
                }
                continue;
            }
            // check xsd key's length
            String uidPrefix = uidValues[0] + "." + uidValues[1] + "."; //$NON-NLS-1$//$NON-NLS-2$
            String[] idArray = Arrays.copyOfRange(uidValues, 2, uidValues.length);
            if (!conceptMap.containsKey(uidPrefix)) {
                MetadataRepository repository = ServerContext.INSTANCE.get().getMetadataRepositoryAdmin()
                        .get(uidValues[0]);
                conceptMap.put(uidPrefix, repository.getComplexType(uidValues[1]));
            }
            if (conceptMap.get(uidPrefix) != null && conceptMap.get(uidPrefix).getKeyFields().size() == 1) {
                idArray = new String[] { StringUtils.removeStart(uid, uidPrefix) };
            }
            refItemPOJOPK = new ItemPOJOPK(new DataClusterPOJOPK(uidValues[0]), uidValues[1], idArray);
            // set revision id as ""
            DroppedItemPOJOPK droppedItemPOJOPK = new DroppedItemPOJOPK(refItemPOJOPK, "/"); //$NON-NLS-1$ //$NON-NLS-2$
            if (regex != null) {
                if (uid.matches(regex)) {
                    list.add(droppedItemPOJOPK);
                }
            } else {
                list.add(droppedItemPOJOPK);
            }
        }
        return list;
    } catch (Exception e) {
        String err = "Unable to find all the identifiers for dropped items " + ": " + e.getClass().getName()
                + ": " + e.getLocalizedMessage();
        LOGGER.error(err, e);
        throw new XtentisException(err, e);
    }
}

From source file:de.dfki.iui.mmds.core.emf.persistence.EmfPersistence.java

private static void write(EObject instance, Resource resource, OutputStream os,
        NonContainmentReferenceHandling refOption, Map<String, Object> saveOptions) throws IOException {
    if (refOption == null) {
        refOption = NonContainmentReferenceHandling.KEEP_ORIGINAL_LOCATION;
    }/*  w ww . j  a  va 2s . c  o  m*/
    HashSet<EObject> alreadyVisited = new HashSet<EObject>();
    List<EObject> rootList = new ArrayList<EObject>();

    if (refOption == NonContainmentReferenceHandling.ADD_TO_RESOURCE) {
        instance = EmfUtils.clone(instance);
        resource.getContents().add(instance);
        collectObjectsWithoutResource(instance, alreadyVisited, rootList, refOption);
        resource.getContents().addAll(rootList);
        write(resource, os, saveOptions);
    } else if (refOption == NonContainmentReferenceHandling.KEEP_ORIGINAL_LOCATION) {
        instance = EcoreUtil.copy(instance);
        resource.getContents().add(instance);
        collectObjectsWithoutResource(instance, alreadyVisited, rootList, refOption);

        Resource resourceTemp = new XMLResourceFactoryImpl().createResource(URI.createURI(""));
        resourceTemp.getContents().addAll(rootList);
        write(resource, os, saveOptions);
    } else if (refOption == NonContainmentReferenceHandling.INLINE) {
        instance = EmfUtils.clone(instance);

        resource.getContents().add(instance);
        // Reads to DOM and injects dependencies(replaces href nodes)

        Document d;
        Map<String, Namespace> namespaces = new HashMap<String, Namespace>();
        try {
            d = createDocFromEObject(instance, namespaces);
            Set<EObject> alreadyHandled = new HashSet<EObject>();
            dfs(instance, d.getRootElement(), alreadyHandled, namespaces);
            for (String prefix : namespaces.keySet()) {
                Namespace namespace = d.getRootElement().getNamespace(prefix);
                if (namespace == null)
                    d.getRootElement().addNamespaceDeclaration(namespaces.get(prefix));
            }
            XMLOutputter out = new XMLOutputter();
            out.setFormat(Format.getPrettyFormat());
            out.output(d, os);
        } catch (Exception e) {
            logger.error("An error occured while serializing an object:\n" + e.getLocalizedMessage());
            e.printStackTrace();
        }
    }
}

From source file:com.hemou.android.account.AccountUtils.java

/**
 * Is the given {@link Exception} due to a 401 Unauthorized API response?
 * /*from  w  w  w . jav a 2s.c  o  m*/
 * @param e
 * @return true if 401, false otherwise
 */
public static boolean isUnauthorized(final Exception e) {
    Log.e(TAG, "Exception occured[" + Thread.currentThread().getId() + "]:{type:" + e.getClass().getName() + ","
            + e.getLocalizedMessage() + "}");
    String errorMess = e.getMessage();

    if (!StringUtils.isEmpty(errorMess) && (errorMess.contains("The authorization has expired")
            || errorMess.contains("401 Unauthorized") || errorMess.contains("403 Forbidden")))
        return true;

    if (e instanceof NotAuthorizedException) {
        Log.e(TAG, "?...");
        return true;
    }
    //      if (e instanceof ResourceAccessException)
    //         return true;
    if (e instanceof HttpClientErrorException) {
        HttpClientErrorException expt = (HttpClientErrorException) e;
        HttpStatus status = expt.getStatusCode();
        if (Arrays.asList(HttpStatus.UNAUTHORIZED, HttpStatus.NETWORK_AUTHENTICATION_REQUIRED,
                HttpStatus.NON_AUTHORITATIVE_INFORMATION, HttpStatus.PROXY_AUTHENTICATION_REQUIRED,
                //403??????
                HttpStatus.FORBIDDEN).contains(status))
            return true;
    }

    return false;
}

From source file:it.cloudicaro.disit.kb.BusinessConfigurationResource.java

static public void deleteBusinessConfiguration(String name, @Context HttpServletRequest request)
        throws Exception {
    Date start = new Date();
    Configuration conf = Configuration.getInstance();
    //remove context associated with id
    RDFStoreInterface rdfStore = RDFStore.getInstance();

    String graph = "urn:cloudicaro:context:BusinessConfiguration:" + name;
    String bcAbout = "";
    if (conf.get("kb.sm.forward.BusinessConfiguration", "false").equals("true")) {
        //find the BusinessConfiguration id that is in this graph
        QueryResult qr = rdfStore.query(IcaroKnowledgeBase.SPARQL_PREFIXES + "SELECT ?bc WHERE { GRAPH <"
                + graph + "> { ?bc a icr:BusinessConfiguration } }");
        if (qr.results().size() == 1) {
            bcAbout = qr.results().get(0).get("bc").getValue();
        } else if (qr.results().size() > 1) {
            String error = "Not only one BC in graph " + graph;
            IcaroKnowledgeBase.error(start, "DELETE", "BC", name, "FAILED-ID-CHECK", error, null, request);
            throw new KbException(error, 400);
        }//from  w w  w. j  a v  a  2s .co m
    }

    rdfStore.removeGraph(graph);

    //request is null when the KB is recovered
    if (request != null) {
        rdfStore.flush();
        IcaroKnowledgeBase.storeDelete(start, name, "BC");

        Date mid = new Date();
        if (!bcAbout.equals("")) {
            //forward the delete operation to SM
            try {
                String smUrl = conf.get("kb.sm.url", "http://192.168.0.37/icaro/api/configurator") + "/"
                        + bcAbout;
                ServerMonitoringClient client = new ServerMonitoringClient(smUrl);
                client.setUsernamePassword(conf.get("kb.sm.user", "test"), conf.get("kb.sm.passwd", "12345"));

                System.out.println("DELETE BC " + bcAbout + " to SM");
                client.delete();
                client.close();
            } catch (Exception e) {
                e.printStackTrace();
                IcaroKnowledgeBase.error(start, "DELETE", "BC", name, "FAILED-SM", e.getLocalizedMessage(),
                        null, request);
                throw new KbException("Failed deleting monitoring: " + e.getLocalizedMessage(), 400);
            }
        }
        Date end = new Date();
        System.out.println(start + " KB-PERFORMANCE DELETE BC " + name + " kb:"
                + (mid.getTime() - start.getTime()) + "ms sm:" + (end.getTime() - mid.getTime()) + "ms");
        IcaroKnowledgeBase.log(start, "DELETE", "BC", name, "OK", request);
    }
}

From source file:com.hybris.mobile.data.WebServiceDataProvider.java

private static void trustAllHosts() {
    // Create a trust manager that does not validate certificate chains
    TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
        public java.security.cert.X509Certificate[] getAcceptedIssuers() {
            return new java.security.cert.X509Certificate[] {};
        }//from www  . ja  v a 2 s .c  om

        public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
        }

        public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
        }
    } };

    // Install the all-trusting trust manager
    try {
        SSLContext sc = SSLContext.getInstance("TLS");
        sc.init(null, trustAllCerts, new java.security.SecureRandom());
        HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
    } catch (Exception e) {
        LoggingUtils.e(LOG_TAG, "Error with SSL connection. " + e.getLocalizedMessage(), null);
    }
}

From source file:com.photon.phresco.service.impl.DependencyManagerImpl.java

private static void updateTestPom(File path) throws PhrescoException {
    if (isDebugEnabled) {
        LOGGER.debug("DependencyManagerImpl.updateTestPom:Entry");
        LOGGER.info("DependencyManagerImpl.updateTestPom",
                ServiceConstants.PATH_EQUALS_SLASH + path.getPath() + "\"");
    }/*from  w  w w. j  a  va2  s .  co m*/
    try {
        File sourcePom = new File(path + "/pom.xml");
        if (!sourcePom.exists()) {
            if (isDebugEnabled) {
                LOGGER.warn("DependencyManagerImpl.updateTestPom", ServiceConstants.STATUS_BAD_REQUEST,
                        "message=\"pom path not exist\"");
            }
            return;
        }

        PomProcessor processor;
        processor = new PomProcessor(sourcePom);
        String groupId = processor.getGroupId();
        String artifactId = processor.getArtifactId();
        String version = processor.getVersion();
        String name = processor.getName();
        Set<String> keySet = testPomFiles.keySet();
        for (String string : keySet) {
            File testPomFile = new File(path + testPomFiles.get(string));
            if (testPomFile.exists()) {
                processor = new PomProcessor(testPomFile);
                processor.setGroupId(groupId + "." + string);
                processor.setArtifactId(artifactId);
                processor.setVersion(version);
                if (name != null && !name.isEmpty()) {
                    processor.setName(name);
                }
                processor.save();
            }
        }
        if (isDebugEnabled) {
            LOGGER.debug("DependencyManagerImpl.updateTestPom:Exit");
        }
    } catch (Exception e) {
        LOGGER.error("DependencyManagerImpl.updateTestPom", ServiceConstants.STATUS_FAILURE,
                ServiceConstants.MESSAGE_EQUALS + "\"" + e.getLocalizedMessage() + "\"");
        throw new PhrescoException(e);
    }
}

From source file:cn.org.once.cstack.utils.MessageUtils.java

public static Message writeAfterThrowingModuleMessage(Exception e, User user, String type) {
    Message message = new Message();
    String body = "";
    message.setType(Message.ERROR);//from  w w w.ja v a 2s  . com
    message.setAuthor(user);

    switch (type) {
    case "CREATE":
        body = "Error create application - " + e.getLocalizedMessage();
        break;
    case "DELETE":
        body = "Error delete application - " + e.getLocalizedMessage();
        break;
    default:
        body = "Error : unkown error";
        break;
    }

    message.setEvent(body);

    return message;
}