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.microsoft.tfs.jni.internal.ntlm.JavaNTLM.java

private static byte[] ntlmHash(final String password) throws NTLMException {
    try {//from  w  ww . j a va2  s  . c  o m
        return HashUtils.hashString(password, "UTF-16LE", "MD4", MD4_PROVIDER); //$NON-NLS-1$ //$NON-NLS-2$
    } catch (final Exception e) {
        LOG.error("Could not load MD4 for NTLM", e); //$NON-NLS-1$
        throw new NTLMException(e.getLocalizedMessage());
    }
}

From source file:com.amalto.webapp.core.util.Util.java

public static Document parse(String xmlString, String schema) throws Exception {
    // parse/*from   w  w w . j  a  v  a 2  s . c o m*/
    Document d;
    SAXErrorHandler seh = new SAXErrorHandler();
    try {
        // initialize the sax parser which uses Xerces
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        // Schema validation based on schemaURL
        factory.setNamespaceAware(true);
        factory.setValidating((schema != null));
        factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage", //$NON-NLS-1$
                "http://www.w3.org/2001/XMLSchema"); //$NON-NLS-1$
        if (schema != null) {
            factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaSource", //$NON-NLS-1$
                    new InputSource(new StringReader(schema)));
        }
        DocumentBuilder builder;
        builder = factory.newDocumentBuilder();
        builder.setErrorHandler(seh);
        d = builder.parse(new InputSource(new StringReader(xmlString)));
    } catch (Exception e) {
        String err = "Unable to parse the document" + ": " + e.getClass().getName() + ": " //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
                + e.getLocalizedMessage() + "\n " //$NON-NLS-1$
                + xmlString;
        throw new Exception(err);
    }
    // check if document parsed correctly against the schema
    if (schema != null) {
        String errors = seh.getErrors();
        if (!errors.equals("")) { //$NON-NLS-1$
            String err = "Document  did not parse against schema: \n" + errors + "\n" + xmlString; //$NON-NLS-1$//$NON-NLS-2$
            throw new Exception(err);
        }
    }
    return d;
}

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

static void deleteFile(File granule) throws IOException {
    if (!FileUtils.deleteQuietly(granule)) {
        try {//from  ww w. j  a va2  s.co m
            FileUtils.forceDelete(granule);
        } catch (Exception e) {
            if (LOGGER.isErrorEnabled()) {
                LOGGER.error(e.getLocalizedMessage(), e);
            }

            // delete on exit
            FileUtils.forceDeleteOnExit(granule);
        }
    }
}

From source file:com.amalto.webapp.core.util.Util.java

public static String[] getTextNodes(Node contextNode, String xPath) throws XtentisWebappException {
    // test for hard-coded values
    if (xPath.startsWith("\"") && xPath.endsWith("\"")) { //$NON-NLS-1$ //$NON-NLS-2$
        return new String[] { xPath.substring(1, xPath.length() - 1) };
    }// ww w  .jav  a2  s.c  o  m
    // test for incomplete path (elements missing /text())
    if (!xPath.matches(".*@[^/\\]]+")) { //$NON-NLS-1$
        if (!xPath.endsWith(")")) { //$NON-NLS-1$
            xPath += "/text()"; //$NON-NLS-1$
        }
    }
    try {
        NodeList nodeList = com.amalto.core.util.Util.getNodeList(contextNode, xPath);
        String[] results = new String[nodeList.getLength()];
        for (int i = 0; i < nodeList.getLength(); i++) {
            results[i] = nodeList.item(i).getNodeValue();
        }
        return results;
    } catch (Exception e) {
        String err = "Unable to get the text node(s) of " + xPath + ": " + e.getClass().getName() + ": " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                + e.getLocalizedMessage();
        throw new XtentisWebappException(err, e);
    }
}

From source file:com.amazonaws.mturk.cmd.GetBalance.java

protected void runCommand(CommandLine cmdLine) throws Exception {
    try {/* www . j a  v  a  2s . c om*/
        getBalance();
    } catch (Exception e) {
        log.error("An error occurred while fetching your balance: " + e.getLocalizedMessage(), e);
        System.exit(-1);
    }
}

From source file:org.neo4j.ogm.drivers.http.request.HttpRequestException.java

public HttpRequestException(HttpRequestBase request, Exception hre) {
    super(request.getURI().toString() + ": " + hre.getLocalizedMessage(), hre);
}

From source file:im.vector.util.BugReporter.java

/**
 * Send a bug report./*from   www .j a va 2  s . co m*/
 *
 * @param context         the application context
 * @param withDevicesLogs true to include the device logs
 * @param withCrashLogs   true to include the crash logs
 */
private static void sendBugReport(final Context context, final boolean withDevicesLogs,
        final boolean withCrashLogs, final String bugDescription, final IMXBugReportListener listener) {
    new AsyncTask<Void, Integer, String>() {
        @Override
        protected String doInBackground(Void... voids) {
            File bugReportFile = new File(context.getApplicationContext().getFilesDir(), "bug_report");

            if (bugReportFile.exists()) {
                bugReportFile.delete();
            }

            String serverError = null;
            FileWriter fileWriter = null;

            try {
                fileWriter = new FileWriter(bugReportFile);
                JsonWriter jsonWriter = new JsonWriter(fileWriter);
                jsonWriter.beginObject();

                // android bug report
                jsonWriter.name("user_agent").value("Android");

                // logs list
                jsonWriter.name("logs");
                jsonWriter.beginArray();

                // the logs are optional
                if (withDevicesLogs) {
                    List<File> files = org.matrix.androidsdk.util.Log.addLogFiles(new ArrayList<File>());
                    for (File f : files) {
                        if (!mIsCancelled) {
                            jsonWriter.beginObject();
                            jsonWriter.name("lines").value(convertStreamToString(f));
                            jsonWriter.endObject();
                            jsonWriter.flush();
                        }
                    }
                }

                if (!mIsCancelled && (withCrashLogs || withDevicesLogs)) {
                    jsonWriter.beginObject();
                    jsonWriter.name("lines").value(getLogCatError());
                    jsonWriter.endObject();
                    jsonWriter.flush();
                }

                jsonWriter.endArray();

                jsonWriter.name("text").value(bugDescription);

                String version = "";

                if (null != Matrix.getInstance(context).getDefaultSession()) {
                    version += "User : " + Matrix.getInstance(context).getDefaultSession().getMyUserId() + "\n";
                }

                version += "Phone : " + Build.MODEL.trim() + " (" + Build.VERSION.INCREMENTAL + " "
                        + Build.VERSION.RELEASE + " " + Build.VERSION.CODENAME + ")\n";
                version += "Vector version: " + Matrix.getInstance(context).getVersion(true) + "\n";
                version += "SDK version:  " + Matrix.getInstance(context).getDefaultSession().getVersion(true)
                        + "\n";
                version += "Olm version:  "
                        + Matrix.getInstance(context).getDefaultSession().getCryptoVersion(context, true)
                        + "\n";

                jsonWriter.name("version").value(version);

                jsonWriter.endObject();
                jsonWriter.close();

            } catch (Exception e) {
                Log.e(LOG_TAG, "doInBackground ; failed to collect the bug report data " + e.getMessage());
                serverError = e.getLocalizedMessage();
            } catch (OutOfMemoryError oom) {
                Log.e(LOG_TAG, "doInBackground ; failed to collect the bug report data " + oom.getMessage());
                serverError = oom.getMessage();

                if (TextUtils.isEmpty(serverError)) {
                    serverError = "Out of memory";
                }
            }

            try {
                if (null != fileWriter) {
                    fileWriter.close();
                }
            } catch (Exception e) {
                Log.e(LOG_TAG, "doInBackground ; failed to close fileWriter " + e.getMessage());
            }

            if (TextUtils.isEmpty(serverError) && !mIsCancelled) {

                // the screenshot is defined here
                // File screenFile = new File(VectorApp.mLogsDirectoryFile, "screenshot.jpg");
                InputStream inputStream = null;
                HttpURLConnection conn = null;
                try {
                    inputStream = new FileInputStream(bugReportFile);
                    final int dataLen = inputStream.available();

                    // should never happen
                    if (0 == dataLen) {
                        return "No data";
                    }

                    URL url = new URL(context.getResources().getString(R.string.bug_report_url));
                    conn = (HttpURLConnection) url.openConnection();
                    conn.setDoInput(true);
                    conn.setDoOutput(true);
                    conn.setUseCaches(false);
                    conn.setRequestMethod("POST");
                    conn.setRequestProperty("Content-Type", "application/json");
                    conn.setRequestProperty("Content-Length", Integer.toString(dataLen));
                    // avoid caching data before really sending them.
                    conn.setFixedLengthStreamingMode(inputStream.available());

                    conn.connect();

                    DataOutputStream dos = new DataOutputStream(conn.getOutputStream());

                    byte[] buffer = new byte[8192];

                    // read file and write it into form...
                    int bytesRead;
                    int totalWritten = 0;

                    while (!mIsCancelled && (bytesRead = inputStream.read(buffer, 0, buffer.length)) > 0) {
                        dos.write(buffer, 0, bytesRead);
                        totalWritten += bytesRead;
                        publishProgress(totalWritten * 100 / dataLen);
                    }

                    dos.flush();
                    dos.close();

                    int mResponseCode;

                    try {
                        // Read the SERVER RESPONSE
                        mResponseCode = conn.getResponseCode();
                    } catch (EOFException eofEx) {
                        mResponseCode = HttpURLConnection.HTTP_INTERNAL_ERROR;
                    }

                    // if the upload failed, try to retrieve the reason
                    if (mResponseCode != HttpURLConnection.HTTP_OK) {
                        serverError = null;
                        InputStream is = conn.getErrorStream();

                        if (null != is) {
                            int ch;
                            StringBuilder b = new StringBuilder();
                            while ((ch = is.read()) != -1) {
                                b.append((char) ch);
                            }
                            serverError = b.toString();
                            is.close();

                            // check if the error message
                            try {
                                JSONObject responseJSON = new JSONObject(serverError);
                                serverError = responseJSON.getString("error");
                            } catch (JSONException e) {
                                Log.e(LOG_TAG, "doInBackground ; Json conversion failed " + e.getMessage());
                            }

                            // should never happen
                            if (null == serverError) {
                                serverError = "Failed with error " + mResponseCode;
                            }

                            is.close();
                        }
                    }
                } catch (Exception e) {
                    Log.e(LOG_TAG,
                            "doInBackground ; failed with error " + e.getClass() + " - " + e.getMessage());
                    serverError = e.getLocalizedMessage();

                    if (TextUtils.isEmpty(serverError)) {
                        serverError = "Failed to upload";
                    }
                } catch (OutOfMemoryError oom) {
                    Log.e(LOG_TAG, "doInBackground ; failed to send the bug report " + oom.getMessage());
                    serverError = oom.getLocalizedMessage();

                    if (TextUtils.isEmpty(serverError)) {
                        serverError = "Out ouf memory";
                    }

                } finally {
                    try {
                        if (null != conn) {
                            conn.disconnect();
                        }
                    } catch (Exception e2) {
                        Log.e(LOG_TAG, "doInBackground : conn.disconnect() failed " + e2.getMessage());
                    }
                }

                if (null != inputStream) {
                    try {
                        inputStream.close();
                    } catch (Exception e) {
                        Log.e(LOG_TAG, "doInBackground ; failed to close the inputStream " + e.getMessage());
                    }
                }
            }
            return serverError;
        }

        @Override
        protected void onProgressUpdate(Integer... progress) {
            super.onProgressUpdate(progress);

            if (null != listener) {
                try {
                    listener.onProgress((null == progress) ? 0 : progress[0]);
                } catch (Exception e) {
                    Log.e(LOG_TAG, "## onProgress() : failed " + e.getMessage());
                }
            }
        }

        @Override
        protected void onPostExecute(String reason) {
            if (null != listener) {
                try {
                    if (mIsCancelled) {
                        listener.onUploadCancelled();
                    } else if (null == reason) {
                        listener.onUploadSucceed();
                    } else {
                        listener.onUploadFailed(reason);
                    }
                } catch (Exception e) {
                    Log.e(LOG_TAG, "## onPostExecute() : failed " + e.getMessage());
                }
            }
        }
    }.execute();
}

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

/**
 * Remove features in a new transaction.<br>
 * Do not dispose datastore.//  w  w w . ja  v  a 2s. c o m
 * 
 * @param dataStore
 * @param delFilter
 * @param typeName the typeName of the index as a geotools feature. It usually is the mosaic name.
 * 
 * @return true if success
 * @throws IOException in case something wrong happens
 * 
 */
private static boolean removeFeatures(final DataStore dataStore, final String typeName, final Filter delFilter)
        throws IOException {
    if (delFilter == null) {
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("The file list is not used to query datastore: Probably it is empty");
        }
        return true;
    }

    // get a feature store to remove features in one step
    SimpleFeatureSource featureSource = dataStore.getFeatureSource(typeName);
    if (featureSource instanceof SimpleFeatureStore) {
        // we have write access to the feature data
        SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource;

        // add some new features
        final String handle = "ImageMosaicUpdater:" + Thread.currentThread().getId();
        Transaction t = new DefaultTransaction(handle);
        featureStore.setTransaction(t);
        try {
            featureStore.removeFeatures(delFilter);
            t.commit();
        } catch (Exception ex) {
            if (LOGGER.isErrorEnabled()) {
                LOGGER.error(ex.getLocalizedMessage(), ex);
            }
            t.rollback();

            return false;
        } finally {
            t.close();
        }
    } else {
        if (LOGGER.isErrorEnabled()) {
            LOGGER.error("Unable to acquire a FeatureStore");
        }
        return false;
    }

    return true;
}

From source file:com.mycompany.asyncreq.GetThread.java

@Override
public void run() {
    try {//  w ww.j a  v  a  2  s .  c  o  m
        Future<HttpResponse> future = client.execute(request, context, null);
        HttpResponse response = future.get();
        MatcherAssert.assertThat(response.getStatusLine().getReasonPhrase(), equals(200));
        Boolean isDone = true;
        Scanner scan = new Scanner(System.in);
        File f = new File("my.txt");
        FileWriter fr = new FileWriter(f);
        BufferedWriter bwr = new BufferedWriter(fr);
        BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent())));
        while ((br.readLine()) != null) {

            bwr.write(new Scanner(System.in).nextLine());

        }
    } catch (Exception ex) {
        System.out.println(ex.getLocalizedMessage());
    }
}

From source file:org.openmrs.module.providermanagement.fragment.controller.PatientEditFragmentController.java

public FragmentActionResult addProviders(@RequestParam(value = "patient", required = true) Patient patient,
        @RequestParam(value = "relationshipType", required = true) RelationshipType relationshipType,
        @RequestParam(value = "providers", required = true) List<Person> providers) {

    try {//from  w  w  w  .  j  a  va 2 s.c  o m
        for (Person provider : providers) {
            Context.getService(ProviderManagementService.class).assignPatientToProvider(patient, provider,
                    relationshipType);
        }
        return new SuccessResult();
    } catch (Exception e) {
        return new FailureResult(e.getLocalizedMessage());
    }
}