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:bala.padio.Settings.java

public static void updateChannel() {
    // find the update url
    String settingUrl = getConfig(ConfSettingUrl, null);
    if (settingUrl == null) {
        Log.e(TAG, "Setting url not found");
        return;//from w  ww  .j  a v  a2s.co  m
    }

    // get the channel config
    String jsonString = DownloadFromUrl(settingUrl);
    Log.d(TAG, "Remote config: " + jsonString);
    if (jsonString == null) {
        Log.e(TAG, "Unable to get settings from server");
        return;
    }

    // persist channel data
    try {
        JSONObject jsonSetting = new JSONObject(jsonString);
        JSONArray languages = jsonSetting.getJSONArray("language");
        JSONArray jsonLanguageName = new JSONArray();
        for (int l = 0; l < languages.length(); l++) {
            JSONObject jsonLanguage = languages.getJSONObject(l);
            String languageName = jsonLanguage.getString("name");

            // clear existing channel list
            clearConfig(languageName);

            // save each channel to the storage
            JSONArray channels = jsonLanguage.getJSONArray("channel");
            for (int c = 0; c < channels.length(); c++) {
                JSONObject jsonChannel = channels.getJSONObject(c);
                setConfig(jsonChannel.getString("id"), jsonChannel.toString(), languageName);
            }
            jsonLanguageName.put(languageName);
        }
        setConfig(ConfLanguageList, jsonLanguageName.toString());

        // set default language, first language in the configuration
        if (getDefaultLanguage() == null) {
            setDefaultLanguage(languages.getJSONObject(0).getString("name"));
        }
    } catch (Exception ex) {
        Log.e(TAG, ex.toString());
    }
}

From source file:com.keybox.manage.db.SystemStatusDB.java

/**
 * returns key placement status of system
 *
 * @param systemId system id/*from ww  w. j  a  v a 2 s .  co  m*/
 * @param userId user id
 */
public static HostSystem getSystemStatus(Long systemId, Long userId) {

    Connection con = null;
    HostSystem hostSystem = null;
    try {
        con = DBUtils.getConn();

        PreparedStatement stmt = con.prepareStatement("select * from status where id=? and user_id=?");
        stmt.setLong(1, systemId);
        stmt.setLong(2, userId);
        ResultSet rs = stmt.executeQuery();

        while (rs.next()) {
            hostSystem = SystemDB.getSystem(con, rs.getLong("id"));
            hostSystem.setStatusCd(rs.getString(STATUS_CD));
        }
        DBUtils.closeRs(rs);
        DBUtils.closeStmt(stmt);

    } catch (Exception e) {
        log.error(e.toString(), e);
    }
    DBUtils.closeConn(con);
    return hostSystem;

}

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

/**
 * Creates and returns an instance of the RawContact from the provided JSON data.
 *
 * @param user The JSONObject containing user data
 * @return user The new instance of Sample RawContact created from the JSON data.
 *///from  w  w w.  j ava2 s . co  m
public static RawContact valueOf(JSONObject contact) {

    try {
        final String userName = !contact.isNull("u") ? contact.getString("u") : null;
        final int serverContactId = !contact.isNull("i") ? contact.getInt("i") : -1;
        // If we didn't get either a username or serverId for the contact, then
        // we can't do anything with it locally...
        if ((userName == null) && (serverContactId <= 0)) {
            throw new JSONException("JSON contact missing required 'u' or 'i' fields");
        }

        final int rawContactId = !contact.isNull("c") ? contact.getInt("c") : -1;
        final String firstName = !contact.isNull("f") ? contact.getString("f") : null;
        final String lastName = !contact.isNull("l") ? contact.getString("l") : null;
        final String cellPhone = !contact.isNull("m") ? contact.getString("m") : null;
        final String officePhone = !contact.isNull("o") ? contact.getString("o") : null;
        final String homePhone = !contact.isNull("h") ? contact.getString("h") : null;
        final String email = !contact.isNull("e") ? contact.getString("e") : null;
        final String status = !contact.isNull("s") ? contact.getString("s") : null;
        final String avatarUrl = !contact.isNull("a") ? contact.getString("a") : null;
        final boolean deleted = !contact.isNull("d") ? contact.getBoolean("d") : false;
        final long syncState = !contact.isNull("x") ? contact.getLong("x") : 0;
        return new RawContact(userName, null, firstName, lastName, cellPhone, officePhone, homePhone, email,
                status, avatarUrl, deleted, serverContactId, rawContactId, syncState, false);
    } catch (final Exception ex) {
        Log.i(TAG, "Error parsing JSON contact object" + ex.toString());
    }
    return null;
}

From source file:com.keybox.manage.db.SystemStatusDB.java

/**
 * set the initial status for selected systems
 *
 * @param systemSelectIds systems ids to set initial status
 * @param userId user id/*from w  w w  .j  a  v a  2  s . com*/
 * @param userType user type
 */
public static void setInitialSystemStatus(List<Long> systemSelectIds, Long userId, String userType) {
    Connection con = null;
    try {
        con = DBUtils.getConn();

        //checks perms if to see if in assigned profiles
        if (!Auth.MANAGER.equals(userType)) {
            systemSelectIds = SystemDB.checkSystemPerms(con, systemSelectIds, userId);
        }

        //deletes all old systems
        deleteAllSystemStatus(con, userId);
        for (Long hostSystemId : systemSelectIds) {

            HostSystem hostSystem = new HostSystem();
            hostSystem.setId(hostSystemId);
            hostSystem.setStatusCd(HostSystem.INITIAL_STATUS);

            //insert new status
            insertSystemStatus(con, hostSystem, userId);
        }

    } catch (Exception e) {
        log.error(e.toString(), e);
    }
    DBUtils.closeConn(con);
}

From source file:com.keybox.manage.db.SystemStatusDB.java

/**
 * returns the first system that authorized keys has not been tried
 *
 * @param userId user id//from www . j av  a 2s .  c om
 * @return hostSystem systems for authorized_keys replacement
 */
public static HostSystem getNextPendingSystem(Long userId) {

    HostSystem hostSystem = null;
    Connection con = null;
    try {
        con = DBUtils.getConn();
        PreparedStatement stmt = con.prepareStatement(
                "select * from status where (status_cd like ? or status_cd like ? or status_cd like ?) and user_id=? order by id asc");
        stmt.setString(1, HostSystem.INITIAL_STATUS);
        stmt.setString(2, HostSystem.AUTH_FAIL_STATUS);
        stmt.setString(3, HostSystem.PUBLIC_KEY_FAIL_STATUS);
        stmt.setLong(4, userId);
        ResultSet rs = stmt.executeQuery();

        if (rs.next()) {
            hostSystem = SystemDB.getSystem(con, rs.getLong("id"));
            hostSystem.setStatusCd(rs.getString(STATUS_CD));
        }
        DBUtils.closeRs(rs);
        DBUtils.closeStmt(stmt);

    } catch (Exception e) {
        log.error(e.toString(), e);
    }
    DBUtils.closeConn(con);
    return hostSystem;

}

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

public static void ApacheNLTKRest(String doc, String args[]) {
    try {//  ww w.j  av  a 2  s  .c  o  m
        String text;
        AutoDetectParser parser = new AutoDetectParser();
        BodyContentHandler handler = new BodyContentHandler();
        Metadata metadata = new Metadata();

        InputStream stream = new FileInputStream(doc);
        // System.out.println(stream.toString());
        parser.parse(stream, handler, metadata);
        // return handler.toString();
        text = handler.toString();
        //System.out.println(text);
        String metaValue = metadata.toString();
        System.out.println("Desc:: " + metadata.toString());

        String[] example = new String[1];
        example[0] = text;
        String name = doc.replace("C:\\Users\\Snehal\\Documents\\TREC-Data\\Data", "polar.usc.edu");
        //System.out.println(text);
        Map<String, Set<String>> list = tikaNLTKRest(text);
        System.out.println(list);
        JSONObject jsonObj = new JSONObject();
        jsonObj.put("DOI", name);
        jsonObj.put("metadata", metaValue.replaceAll("\\s\\s+|\n|\t", " "));
        JSONArray tempArray = new JSONArray();
        JSONObject tempObj = new JSONObject();
        for (Map.Entry<String, Set<String>> entry : list.entrySet()) {
            System.out.println("\"" + entry.getKey() + "/" + ":\"" + entry.getValue() + "\"");
            tempObj.put(entry.getKey(), entry.getValue());
            //          String jsonOut="{ DOI:"+name+"  ,"
            //                + ""+item.first() + "\": \"" + text.substring(item.second(), item.third()).replaceAll("\\s\\s+|\n|\t"," ")+"\""
            //                + "\"metadata\":\""+metaValue+"\""
            //                + "}";
            // System.out.println(jsonOut);
            //     tempObj.put(item.first(),text.substring(item.second(), item.third()).replaceAll("\\s\\s+|\n|\t"," "));
        }
        tempArray.add(tempObj);
        jsonObj.put("NER", tempArray);
        jsonArray.add(jsonObj);

        // System.out.println("---");

    } catch (Exception e) {
        System.out.println("ERROR : NLTKRest" + "|File Name"
                + doc.replaceAll("C:\\Users\\Snehal\\Documents\\TREC-Data", "") + " direct" + e.toString());
    }
}

From source file:cz.incad.kramerius.virtualcollections.VirtualCollectionsManager.java

public static List<VirtualCollection> getVirtualCollections(FedoraAccess fedoraAccess,
        ArrayList<String> languages) throws Exception {
    try {//  w ww.  j ava 2s  .  c o  m
        List<VirtualCollection> vcs = new ArrayList<VirtualCollection>();
        String query = "/terms?terms=true&terms.fl=collection&terms.limit=1000&terms.sort=index&wt=json";
        String solrHost = KConfiguration.getInstance().getSolrHost();
        String uri = solrHost + query;
        InputStream inputStream = RESTHelper.inputStream(uri, "<no_user>", "<no_pass>");

        JSONObject json = new JSONObject(IOUtils.readAsString(inputStream, Charset.forName("UTF-8"), true));
        JSONArray ja = json.getJSONObject("terms").getJSONArray("collection");
        String pid = "";
        for (int i = 0; i < ja.length(); i = i + 2) {
            try {
                pid = ja.getString(i);
                if (!"".equals(pid)) {
                    VirtualCollection vc = doVC(pid, fedoraAccess, languages);
                    if (vc != null) {
                        vcs.add(vc);
                    }
                }
            } catch (Exception vcex) {
                logger.log(Level.WARNING,
                        "Could not get virtual collection for  " + pid + ": " + vcex.toString());

            }
        }
        return vcs;
    } catch (Exception ex) {
        logger.log(Level.SEVERE, "Error getting virtual collections", ex);
        throw new Exception(ex);
    }
}

From source file:net.algart.simagis.imageio.IIOMetadataToJsonConverter.java

private static JSONObject exceptionToJson(Exception e) throws JSONException {
    JSONObject result = new JSONObject();
    result.put("error", e.toString());
    return result;
}

From source file:com.wbtech.ums.NetworkUtil.java

public static MyMessage Post(String url, String data) {
    CobubLog.d(UmsConstants.LOG_TAG, NetworkUtil.class, "URL = " + url);
    CobubLog.d(UmsConstants.LOG_TAG, NetworkUtil.class, "LENGTH:" + data.length() + " *Data = " + data + "*");

    if (!hasInitSSL && UmsConstants.SDK_SECURITY_LEVEL.equals("2")) {
        initSSL();//from   w ww.j av a2s  .c  o  m
        hasInitSSL = true;
    }

    BasicHttpParams httpParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParams, REQUEST_TIMEOUT);
    HttpConnectionParams.setSoTimeout(httpParams, SO_TIMEOUT);
    DefaultHttpClient httpclient = null;

    /*SDK??:
     * 1,CPOS:???sslSDK_SSL=true;??dn(?dnSDK_HTTPS_DNnone)
     * 2,HTTPS???????https?
     * 3,http
    */
    if (UmsConstants.SDK_SECURITY_LEVEL.equals("2")) {
        httpclient = new DefaultHttpClient(httpParams);
        // cpos with dn check
        if (!UmsConstants.SDK_HTTPS_DN.equals("none")) {
            SSLSocketFactory mysf = null;
            try {
                mysf = new CposSSLSocketFactory();
                if (serverUrl == null) {
                    serverUrl = new URL(url);
                    serverPort = ((serverUrl.getPort() == -1) ? serverUrl.getDefaultPort()
                            : serverUrl.getPort());
                }

                httpclient.getConnectionManager().getSchemeRegistry()
                        .register(new Scheme(serverUrl.getProtocol(), mysf, serverPort));

            } catch (Exception e) {
                CobubLog.d(UmsConstants.LOG_TAG, NetworkUtil.class, e.toString());
            }
        }
    } else if (UmsConstants.SDK_SECURITY_LEVEL.equals("1") && url.toLowerCase().startsWith("https")) {
        // for https with company cert
        if (serverPort < 0) {
            serverPort = getPort();
        }
        CobubLog.d(UmsConstants.LOG_TAG, NetworkUtil.class, "InitSSL port is:" + serverPort);
        SchemeRegistry schReg = new SchemeRegistry();
        schReg.register(new Scheme("https", SSLCustomSocketFactory.getSocketFactory(), serverPort));

        ClientConnectionManager connMgr = new ThreadSafeClientConnManager(httpParams, schReg);
        httpclient = new DefaultHttpClient(connMgr, httpParams);
    } else {
        httpclient = new DefaultHttpClient(httpParams);
    }
    processCookieRejected(httpclient);

    MyMessage message = new MyMessage();
    try {
        HttpPost httppost = new HttpPost(url);

        StringEntity se = new StringEntity("content=" + URLEncoder.encode(data), HTTP.UTF_8);
        se.setContentType("application/x-www-form-urlencoded");
        httppost.setEntity(se);

        HttpResponse response = httpclient.execute(httppost);
        CobubLog.d(UmsConstants.LOG_TAG, NetworkUtil.class,
                "Status code=" + response.getStatusLine().getStatusCode());

        String returnXML = EntityUtils.toString(response.getEntity());
        int status = response.getStatusLine().getStatusCode();
        String returnContent = URLDecoder.decode(returnXML, "UTF-8");
        CobubLog.d(UmsConstants.LOG_TAG, NetworkUtil.class, "returnString = " + returnContent);
        //TODO:???200okjson??????????flag<0
        //?flag???
        switch (status) {
        case 200:
            message.setSuccess(isJson(returnContent));
            message.setMsg(returnContent);
            break;
        default:
            Log.e("error", status + returnContent);
            message.setSuccess(false);
            message.setMsg(returnContent);
            break;
        }
    } catch (Exception e) {
        message.setSuccess(false);
        message.setMsg(e.toString());
    }
    return message;
}

From source file:gov.nih.nci.rembrandt.web.helper.PCAAppletHelper.java

public static String generateParams(String sessionId, String taskId) {
    String htm = "";
    DecimalFormat nf = new DecimalFormat("0.0000");

    try {/*from www  .  j a v  a2s . c  om*/
        //retrieve the Finding from cache and build the list of PCAData points
        PrincipalComponentAnalysisFinding principalComponentAnalysisFinding = (PrincipalComponentAnalysisFinding) businessTierCache
                .getSessionFinding(sessionId, taskId);

        ArrayList<PrincipalComponentAnalysisDataPoint> pcaData = new ArrayList();

        Collection<ClinicalFactorType> clinicalFactors = new ArrayList<ClinicalFactorType>();
        List<String> sampleIds = new ArrayList();
        Map<String, PCAresultEntry> pcaResultMap = new HashMap<String, PCAresultEntry>();

        List<PCAresultEntry> pcaResults = principalComponentAnalysisFinding.getResultEntries();
        for (PCAresultEntry pcaEntry : pcaResults) {
            sampleIds.add(pcaEntry.getSampleId());
            pcaResultMap.put(pcaEntry.getSampleId(), pcaEntry);
        }

        Collection<SampleResultset> validatedSampleResultset = ClinicalDataValidator
                .getValidatedSampleResultsetsFromSampleIDs(sampleIds, clinicalFactors);

        if (validatedSampleResultset != null) {
            String id;
            PCAresultEntry entry;

            for (SampleResultset rs : validatedSampleResultset) {
                id = rs.getBiospecimen().getSpecimenName();
                entry = pcaResultMap.get(id);
                PrincipalComponentAnalysisDataPoint pcaPoint = new PrincipalComponentAnalysisDataPoint(id,
                        entry.getPc1(), entry.getPc2(), entry.getPc3());
                String diseaseName = rs.getDisease().getValueObject();
                if (diseaseName != null) {
                    pcaPoint.setDiseaseName(diseaseName);
                } else {
                    pcaPoint.setDiseaseName(DiseaseType.NON_TUMOR.name());
                }
                GenderDE genderDE = rs.getGenderCode();
                if (genderDE != null) {
                    String gt = genderDE.getValueObject();
                    if (gt != null) {
                        GenderType genderType = GenderType.valueOf(gt);
                        if (genderType != null) {
                            pcaPoint.setGender(genderType);
                        }
                    }
                }
                Long survivalLength = rs.getSurvivalLength();
                if (survivalLength != null) {
                    //survival length is stored in days in the DB so divide by 30 to get the 
                    //approx survival in months
                    double survivalInMonths = survivalLength.doubleValue() / 30.0;
                    pcaPoint.setSurvivalInMonths(survivalInMonths);
                }
                pcaData.add(pcaPoint);
            }
        }

        //make a hashmap
        // [key=group] hold the array of double[][]s
        HashMap<String, ArrayList> hm = new HashMap();

        //now we should have a collection of PCADataPts
        double[][] pts = new double[pcaData.size()][3];
        for (int i = 0; i < pcaData.size(); i++) {
            //just create a large 1 set for now
            //are we breaking groups by gender or disease?
            PrincipalComponentAnalysisDataPoint pd = pcaData.get(i);

            pts[i][0] = pd.getPc1value();
            pts[i][1] = pd.getPc2value();
            pts[i][2] = pd.getPc3value();
            ArrayList<double[]> al;

            try {
                if (hm.containsKey(pd.getDiseaseName())) {
                    //already has it, so add this one
                    al = (ArrayList) hm.get(pd.getDiseaseName());
                } else {
                    al = new ArrayList();
                    hm.put(pd.getDiseaseName(), new ArrayList());
                }
                if (!al.contains(pts[i])) {
                    al.add(pts[i]);
                }
                hm.put(pd.getDiseaseName(), al);
            } catch (Exception e) {
                System.out.print(e.toString());
            }
        }
        int r = hm.size();
        if (r == 1) {
        }
        //hm should now contain a hashmap of all the disease groups

        //generate the param tags
        htm += "<param name=\"key\" value=\"" + taskId + "\" >\n";
        htm += "<param name=\"totalPts\" value=\"" + pts.length + "\" >\n";
        htm += "<param name=\"totalGps\" value=\"" + hm.size() + "\" >\n";
        int ii = 0;
        for (Object k : hm.keySet()) {
            String key = k.toString();
            //for each group

            Color diseaseColor = Color.GRAY;
            if (DiseaseType.valueOf(key) != null) {
                DiseaseType disease = DiseaseType.valueOf(key);
                diseaseColor = disease.getColor();
            }

            ArrayList<double[]> al = hm.get(key);
            htm += "<param name=\"groupLabel_" + ii + "\" value=\"" + key + "\" >\n";
            htm += "<param name=\"groupCount_" + ii + "\" value=\"" + al.size() + "\" >\n";
            htm += "<param name=\"groupColor_" + ii + "\" value=\"" + diseaseColor.getRGB() + "\" >\n";
            int jj = 0;
            for (double[] d : al) {
                String comm = nf.format(d[0]) + "," + nf.format(d[1]) + "," + nf.format(d[2]);
                String h = "<param name=\"pt_" + ii + "_" + jj + "\" value=\"" + comm + "\">\n";
                htm += h;
                jj++;
            }
            ii++;
        }
        /*
         //for bulk rendering
        for(int i=0; i<pts.length; i++)   {
           String comm = String.valueOf(pts[i][0]) + "," +
           String.valueOf(pts[i][1]) + "," +
           String.valueOf(pts[i][2]);
                   
           String h = "<param name=\"pt_"+i+"\" value=\""+ comm +"\">\n";
           //htm += h;
        }
        */

    } //try
    catch (Exception e) {

    }

    return htm;
}