Example usage for java.lang Exception toString

List of usage examples for java.lang Exception toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:org.androidnerds.reader.util.api.Authentication.java

/**
 * This method generates a quick token to send with API requests that require
 * editing content. This method is called as the API request is being built so
 * that it doesn't expire prior to the actual execution.
 *
 * @param sid - the user's authentication token from ClientLogin
 * @return token - the edit token generated by the server.
 *
 *//*  w  w w.  ja va 2s  . c o  m*/
public static String generateFastToken(String sid) {
    try {
        BasicClientCookie cookie = Authentication.buildCookie(sid);
        DefaultHttpClient client = new DefaultHttpClient();

        client.getCookieStore().addCookie(cookie);

        HttpGet get = new HttpGet(TOKEN_URL);
        HttpResponse response = client.execute(get);
        HttpEntity entity = response.getEntity();

        Log.d(TAG, "Server Response: " + response.getStatusLine());

        InputStream in = entity.getContent();
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        String line = null;

        while ((line = reader.readLine()) != null) {
            Log.d(TAG, "Response Content: " + line);
        }

        reader.close();
        client.getConnectionManager().shutdown();

        return line;
    } catch (Exception e) {
        Log.d(TAG, "Exception caught:: " + e.toString());
        return null;
    }
}

From source file:edu.usc.polar.CoreNLP.java

public static String parseExample(String doc) {
    try {/*from w  ww . j a va 2 s.  co m*/
        AutoDetectParser parser = new AutoDetectParser();
        BodyContentHandler handler = new BodyContentHandler();
        Metadata metadata = new Metadata();

        InputStream stream = new FileInputStream(doc);
        //ParsingExample.class.getResourceAsStream(doc) ;
        //   System.out.println(stream.toString());
        parser.parse(stream, handler, metadata);
        return handler.toString();

    } catch (Exception e) {
        return "ERROR - " + e.toString();
    }

}

From source file:com.ctb.tdc.web.utils.EasySSLProtocolSocketFactory.java

private static SSLContext createEasySSLContext() {
    try {//from  w w w . ja v a2s  .co m
        SSLContext context = SSLContext.getInstance("SSL");
        context.init(null, new TrustManager[] { new EasyX509TrustManager(null) },
                new java.security.SecureRandom());
        return context;
    } catch (Exception e) {
        throw new HttpClientError(e.toString());
    }
}

From source file:com.example.android.samplesync.client.User.java

/**
 * Creates and returns an instance of the user from the provided JSON data.
 * //w  w w  .  j av a 2  s .  c om
 * @param user The JSONObject containing user data
 * @return user The new instance of Voiper user created from the JSON data.
 */
public static User valueOf(JSONObject user) {
    try {
        final String userName = user.getString("u");
        final String firstName = user.has("f") ? user.getString("f") : null;
        final String lastName = user.has("l") ? user.getString("l") : null;
        final String cellPhone = user.has("m") ? user.getString("m") : null;
        final String officePhone = user.has("o") ? user.getString("o") : null;
        final String homePhone = user.has("h") ? user.getString("h") : null;
        final String email = user.has("e") ? user.getString("e") : null;
        final boolean deleted = user.has("d") ? user.getBoolean("d") : false;
        final int userId = user.getInt("i");
        return new User(userName, firstName, lastName, cellPhone, officePhone, homePhone, email, deleted,
                userId);
    } catch (final Exception ex) {
        Log.i("User", "Error parsing JSON user object" + ex.toString());

    }
    return null;

}

From source file:gov.nist.appvet.tool.sigverifier.util.ReportUtil.java

/** This method should be used for sending files back to AppVet. */
public static boolean sendInNewHttpRequest(String appId, String reportFilePath, ToolStatus reportStatus) {
    HttpParams httpParameters = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParameters, 30000);
    HttpConnectionParams.setSoTimeout(httpParameters, 1200000);
    HttpClient httpClient = new DefaultHttpClient(httpParameters);
    httpClient = SSLWrapper.wrapClient(httpClient);

    try {//from  ww  w .j a  v a 2 s  .co  m
        /*
         * To send reports back to AppVet, the following parameters must be
         * sent: - command: SUBMIT_REPORT - username: AppVet username -
         * password: AppVet password - appid: The app ID - toolid: The ID of
         * this tool - toolrisk: The risk assessment (LOW, MODERATE, HIGH,
         * ERROR) - report: The report file.
         */
        MultipartEntity entity = new MultipartEntity();
        entity.addPart("command", new StringBody("SUBMIT_REPORT", Charset.forName("UTF-8")));
        entity.addPart("username", new StringBody(Properties.appvetUsername, Charset.forName("UTF-8")));
        entity.addPart("password", new StringBody(Properties.appvetPassword, Charset.forName("UTF-8")));
        entity.addPart("appid", new StringBody(appId, Charset.forName("UTF-8")));
        entity.addPart("toolid", new StringBody(Properties.toolId, Charset.forName("UTF-8")));
        entity.addPart("toolrisk", new StringBody(reportStatus.name(), Charset.forName("UTF-8")));
        File report = new File(reportFilePath);
        FileBody fileBody = new FileBody(report);
        entity.addPart("file", fileBody);
        HttpPost httpPost = new HttpPost(Properties.appvetUrl);
        httpPost.setEntity(entity);
        // Send the report to AppVet
        log.debug("Sending report file to AppVet");
        final HttpResponse response = httpClient.execute(httpPost);
        log.debug("Received from AppVet: " + response.getStatusLine());
        HttpEntity httpEntity = response.getEntity();
        InputStream is = httpEntity.getContent();
        String result = IOUtils.toString(is, "UTF-8");
        log.info(result);
        // Clean up
        httpPost = null;
        return true;
    } catch (Exception e) {
        log.error(e.toString());
        return false;
    }
}

From source file:org.hawkular.alerts.rest.ResponseUtil.java

public static Response internalError(Exception e) {
    if (e.getMessage() == null) {
        return internalError(e.toString());
    } else {//from www  . j  a  v a 2 s  .c om
        return internalError(e.getMessage());
    }
}

From source file:ch.truesolutions.payit.https.EasySSLProtocolSocketFactory.java

private static SSLContext createEasySSLContext() {
    try {/*from  ww w.j  a  va2  s.  co m*/
        // DS create a KeyStore todo
        KeyStore keyStore = KeyStore.getInstance("JKS");

        SSLContext context = SSLContext.getInstance("SSL");
        context.init(null, new TrustManager[] { new EasyX509TrustManager(keyStore) }, null);
        return context;
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
        throw new RuntimeException(e.toString());
    }
}

From source file:edu.usc.polar.OpenNLP.java

public static void dir(String path, String[] args) {
    try {/*from   ww w .  j a va 2  s.c om*/

        File root = new File(path);
        if (root.isFile()) {

            if (counter >= 1000 || file == null) {
                counter = 0;
                jsonCount++;
                file = new File("C:\\Users\\Snehal\\Documents\\tikaSimilarityTestSet\\OpenNLP\\NER_" + jsonCount
                        + ".json");
                if (jsonFile != null) {
                    jsonFile.write("{\"NER_OpenNLP\":");
                    jsonFile.write(jsonArray.toJSONString());
                    jsonFile.write("}");
                    System.out.println(jsonArray.toJSONString());
                    jsonFile.close();
                }
                jsonFile = new FileWriter(file);
                jsonArray = new JSONArray();
            }

            if (!root.getName().equals((".DS_Store"))) {
                ApacheOpenNLP(root.getAbsolutePath(), args);
                counter++;
            }
        } else {
            File[] list = root.listFiles();
            if (list == null) {
                return;
            }
            for (File f : list) {
                if (f.isDirectory()) {
                    dir(f.getAbsolutePath(), args);
                    System.out.println("Dir:" + f.getAbsoluteFile());
                } else {
                    if (counter >= 1000 || file == null) {
                        counter = 0;
                        jsonCount++;
                        file = new File("C:\\Users\\Snehal\\Documents\\tikaSimilarityTestSet\\OpenNLP\\NER_"
                                + jsonCount + ".json");
                        //  System.out.print("check"+jsonArray.toJSONString());
                        if (jsonFile != null) {
                            jsonFile.write("{\"NER_OpenNLP\":");
                            jsonFile.write(jsonArray.toJSONString());
                            jsonFile.write("}");
                            System.out.println(jsonArray.toJSONString());
                            jsonFile.close();
                        }
                        jsonFile = new FileWriter(file);
                        jsonArray = new JSONArray();
                    }

                    if (!f.getName().equals((".DS_Store"))) {
                        ApacheOpenNLP(f.getAbsolutePath(), args);
                        counter++;
                        // add json   
                    }
                }
            }
        }
    } catch (Exception e) {
        e.toString();

    }
}

From source file:azureml_besapp.AzureML_BESApp.java

/**
 * Read the JSON schema from the file rrsJson.json
 * //w w w  .  j  a  v  a 2 s  .  c om
 * @param filename It expects a fully qualified file name that contains input JSON file
 */
public static void readJson(String filename) {
    try {
        File apiFile = new File(filename);
        Scanner sc = new Scanner(apiFile);
        jsonBody = "";
        while (sc.hasNext()) {
            jsonBody += sc.nextLine() + "\n";
        }
    } catch (Exception e) {
        System.out.println(e.toString());
    }
}

From source file:edu.usc.polar.NLTKRest.java

public static void dir(String path, String[] args) {
    try {/*from   w w  w.  j a v a 2s  .c o  m*/

        File root = new File(path);
        if (root.isFile()) {

            if (counter >= 1000 || file == null) {
                counter = 0;
                jsonCount++;
                file = new File("C:\\Users\\Snehal\\Documents\\tikaSimilarityTestSet\\NLTKRest\\NER_"
                        + jsonCount + ".json");
                if (jsonFile != null) {
                    jsonFile.write("{\"NER_NLTKRest\":");
                    jsonFile.write(jsonArray.toJSONString());
                    jsonFile.write("}");
                    //   System.out.println(jsonArray.toJSONString());
                    jsonFile.close();
                }
                jsonFile = new FileWriter(file);
                jsonArray = new JSONArray();
            }

            if (!root.getName().equals((".DS_Store"))) {
                ApacheNLTKRest(root.getAbsolutePath(), args);
                counter++;
            }
        } else {
            File[] list = root.listFiles();
            if (list == null) {
                return;
            }
            for (File f : list) {
                if (f.isDirectory()) {
                    dir(f.getAbsolutePath(), args);
                    System.out.println("Dir:" + f.getAbsoluteFile());
                } else {
                    if (counter >= 1000 || file == null) {
                        counter = 0;
                        jsonCount++;
                        file = new File("C:\\Users\\Snehal\\Documents\\tikaSimilarityTestSet\\NLTKRest\\NER_"
                                + jsonCount + ".json");
                        //  System.out.print("check"+jsonArray.toJSONString());
                        if (jsonFile != null) {
                            jsonFile.write("{\"NER_NLTKRest\":");
                            jsonFile.write(jsonArray.toJSONString());
                            jsonFile.write("}");
                            System.out.println(jsonArray.toJSONString());
                            jsonFile.close();
                        }
                        jsonFile = new FileWriter(file);
                        jsonArray = new JSONArray();
                    }

                    if (!f.getName().equals((".DS_Store"))) {
                        ApacheNLTKRest(f.getAbsolutePath(), args);
                        counter++;
                        // add json   
                    }
                }
            }
        }
    } catch (Exception e) {
        System.err.print(e.toString());

    }
}