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:dk.kk.ibikecphlib.util.HttpUtils.java

public static JsonNode deleteFromServer(String urlString, JSONObject objectToPost) {
    JsonNode ret = null;//  w  w  w  .j a v a 2  s. c o  m
    LOG.d("DELETE api request, url = " + urlString);
    HttpParams myParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(myParams, CONNECTON_TIMEOUT);
    HttpConnectionParams.setSoTimeout(myParams, CONNECTON_TIMEOUT);
    HttpClient httpclient = new DefaultHttpClient(myParams);
    httpclient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, Config.USER_AGENT);
    HTTPDeleteWithBody httpdelete = null;
    URL url = null;
    try {
        url = new URL(urlString);
        httpdelete = new HTTPDeleteWithBody(url.toString());
        httpdelete.setHeader("Content-type", "application/json");
        httpdelete.setHeader("Accept", ACCEPT);
        httpdelete.setHeader("LANGUAGE_CODE", IBikeApplication.getLanguageString());
        StringEntity se = new StringEntity(objectToPost.toString(), HTTP.UTF_8);
        se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
        httpdelete.setEntity(se);
        HttpResponse response = httpclient.execute(httpdelete);
        String serverResponse = EntityUtils.toString(response.getEntity());
        LOG.d("API response = " + serverResponse);
        ret = Util.stringToJsonNode(serverResponse);
    } catch (Exception e) {
        if (e != null && e.getLocalizedMessage() != null)
            LOG.e(e.getLocalizedMessage());
    }
    return ret;
}

From source file:dk.kk.ibikecphlib.util.HttpUtils.java

public static JsonNode postToServer(String urlString, JSONObject objectToPost) {
    JsonNode ret = null;//from  w w  w. j  a  va2s . com
    LOG.d("POST api request, url = " + urlString + " object = " + objectToPost.toString());
    HttpParams myParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(myParams, CONNECTON_TIMEOUT);
    HttpConnectionParams.setSoTimeout(myParams, CONNECTON_TIMEOUT);
    HttpClient httpclient = new DefaultHttpClient(myParams);
    httpclient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, Config.USER_AGENT);
    HttpPost httppost = null;
    URL url = null;
    try {
        url = new URL(urlString);
        httppost = new HttpPost(url.toString());
        httppost.setHeader("Content-type", "application/json");
        httppost.setHeader("Accept", ACCEPT);
        httppost.setHeader("LANGUAGE_CODE", IBikeApplication.getLanguageString());
        StringEntity se = new StringEntity(objectToPost.toString(), HTTP.UTF_8);// , HTTP.UTF_8
        se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
        httppost.setEntity(se);
        HttpResponse response = httpclient.execute(httppost);
        String serverResponse = EntityUtils.toString(response.getEntity());
        LOG.d("API response = " + serverResponse);
        ret = Util.stringToJsonNode(serverResponse);
    } catch (Exception e) {
        if (e != null && e.getLocalizedMessage() != null) {
            LOG.e(e.getLocalizedMessage());
        }
    }
    return ret;
}

From source file:dk.kk.ibikecphlib.util.HttpUtils.java

public static JsonNode putToServer(String urlString, JSONObject objectToPost) {
    JsonNode ret = null;/* w  ww .  jav a2 s  .c o  m*/
    LOG.d("PUT api request, url = " + urlString);
    HttpParams myParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(myParams, CONNECTON_TIMEOUT);
    HttpConnectionParams.setSoTimeout(myParams, CONNECTON_TIMEOUT);
    HttpClient httpclient = new DefaultHttpClient(myParams);
    httpclient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, Config.USER_AGENT);
    HttpPut httput = null;
    URL url = null;
    try {
        url = new URL(urlString);
        httput = new HttpPut(url.toString());
        httput.setHeader("Content-type", "application/json");
        httput.setHeader("Accept", ACCEPT);
        httput.setHeader("LANGUAGE_CODE", IBikeApplication.getLanguageString());
        StringEntity se = new StringEntity(objectToPost.toString(), HTTP.UTF_8);
        se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
        httput.setEntity(se);
        HttpResponse response = httpclient.execute(httput);
        String serverResponse = EntityUtils.toString(response.getEntity());
        LOG.d("API response = " + serverResponse);
        ret = Util.stringToJsonNode(serverResponse);
    } catch (Exception e) {
        if (e != null && e.getLocalizedMessage() != null) {
            LOG.e(e.getLocalizedMessage());
        }
    }
    return ret;
}

From source file:grisu.frontend.view.swing.files.preview.fileViewers.JobStatusGridFileViewer.java

protected static ImageIcon createImageIcon(String path, String description) {

    ImageIcon icon = null;//  w  w w.j  ava 2 s.  co m
    try {
        icon = new ImageIcon(JobStatusGridFileViewer.class.getClassLoader().getResource(path));
    } catch (final Exception e) {
        myLogger.error(e.getLocalizedMessage(), e);
    }

    return icon;

}

From source file:net.menthor.editor.v2.util.Util.java

public static String getExceptionMessage(Exception ex) {
    ex.printStackTrace();/*from www .  ja  va  2 s  .c o m*/
    String msg = ex.getLocalizedMessage();
    if (msg == null || msg.isEmpty())
        msg = ExceptionUtils.getStackTrace(ex);
    return msg;
}

From source file:com.cprassoc.solr.auth.SolrAuthActionController.java

public static String doPushConfigToSolrAction(SecurityJson json) {
    String result = "";
    try {/*from  w w w.  java  2  s .c om*/
        String mime = "sh";
        if (Utils.isWindows()) {
            mime = "bat";
        }
        String pathToScript = System.getProperty("user.dir") + File.separator + "solrAuth." + mime;
        String jsonstr = json.export();
        String filePath = SolrAuthManager.getProperties().getProperty("solr.install.path") + File.separator
                + "security.json";
        File backup = new File("backup");
        if (!backup.exists()) {
            backup.mkdirs();
        }

        File file = new File(filePath);
        if (file.exists()) {
            // String newFilePath = SolrAuthManager.getProperties().getProperty("solr.install.path") + File.separator + System.currentTimeMillis() + "_security.json";
            // File newFile = new File(newFilePath);
            // file.renameTo(newFile);
            FileUtils.copyFileToDirectory(file, backup);
        }
        FileUtils.writeByteArrayToFile(file, jsonstr.getBytes());
        Thread.sleep(500);
        ProcessBuilder pb = new ProcessBuilder(pathToScript);

        Log.log("Run PUSH command");

        Process process = pb.start();
        if (process.waitFor() == 0) {
            result = "";
        } else {
            result = Utils.streamToString(process.getErrorStream());
            result += "\n" + Utils.streamToString(process.getInputStream());
            Log.log(result);
        }

    } catch (Exception e) {
        e.printStackTrace();
        result = e.getLocalizedMessage();
    }

    return result;
}

From source file:com.spoiledmilk.cykelsuperstier.break_rote.LocalTrainData.java

private static void getTimesForWeekdays(int hour, int minute, ArrayList<ITransportationInfo> times,
        JsonNode timeTableNode, int index1, int index2, int numOfStations) {
    ArrayList<TimeData> allTimes = new ArrayList<TimeData>();
    for (int i = 0; i < timeTableNode.size(); i++) {
        JsonNode intervalNode = timeTableNode.get(i);
        try {/*from   w w w  .  j a v a2 s.  c om*/
            double currentTime = ((double) hour) + ((double) minute) / 100d;
            double startInterval = intervalNode.get("start-time").asDouble();
            double endInterval = intervalNode.get("end-time").asDouble();
            if (endInterval < 1.0)
                endInterval += 24.0;
            if (currentTime >= startInterval && currentTime <= endInterval) {
                JsonNode dataNode = intervalNode.get("data");
                int[] minutesArray = new int[dataNode.size()];
                for (int j = 0; j < minutesArray.length; j++) {
                    minutesArray[j] = dataNode.get(j).asInt();
                }
                int currentHour = hour;
                int currentIndex = 0;
                int count = 0;
                while (currentHour <= endInterval && count < 3 && currentIndex < minutesArray.length) {
                    double time1 = minutesArray[currentIndex + index1];
                    double time2 = minutesArray[currentIndex + index2];
                    if (time1 < 0 || time2 < 0)
                        continue;
                    time1 /= 100d;
                    time1 += currentHour;
                    time2 /= 100d;
                    time2 += currentHour;
                    if (time2 < time1)
                        time2 += 1.0;
                    allTimes.add(new TimeData(time1, time2));
                    currentHour++;
                    count++;
                    currentIndex += numOfStations;
                }
            }
        } catch (Exception e) {
            LOG.e(e.getLocalizedMessage());
        }
    }

    // sort the list
    for (int i = 0; i < allTimes.size() - 1; i++) {
        for (int j = i + 1; j < allTimes.size(); j++) {
            TimeData td1 = allTimes.get(i);
            TimeData td2 = allTimes.get(j);
            if (td1.stationAtime > td2.stationAtime) {
                allTimes.set(i, td2);
                allTimes.set(j, td1);
            }
        }
    }

    LOG.d("sorted times = " + allTimes.toString());

    // return the 3 results
    for (int i = 0; i < 3 && i < allTimes.size(); i++) {
        TimeData temp = allTimes.get(i);
        int time = 0;
        int minutes1 = (int) ((temp.stationAtime - (double) ((int) temp.stationAtime)) * 100);
        int minutes2 = (int) ((temp.stationBtime - (double) ((int) temp.stationBtime)) * 100);
        time = (((int) temp.stationBtime) - ((int) temp.stationAtime)) * 60;
        if (minutes2 >= minutes1)
            time = minutes2 - minutes1;
        else {
            time += 60 - minutes1 + minutes2;
            time -= 60;
        }
        String formattedTime1 = (((int) temp.stationAtime) < 10 ? "0" + ((int) temp.stationAtime)
                : "" + ((int) temp.stationAtime)) + ":" + (minutes1 < 10 ? "0" + minutes1 : "" + minutes1);
        String formattedTime2 = (((int) temp.stationBtime) < 10 ? "0" + ((int) temp.stationBtime)
                : "" + ((int) temp.stationBtime)) + ":" + (minutes2 < 10 ? "0" + minutes2 : "" + minutes2);
        times.add(new LocalTrainData(formattedTime1, formattedTime2, time));
    }

}

From source file:com.spoiledmilk.cykelsuperstier.break_rote.LocalTrainData.java

private static void getTimesForWeekend(int hour, int minute, ArrayList<ITransportationInfo> times,
        JsonNode timeTableNode, int index1, int index2, int numOfStations, JsonNode dataNodeArray) {
    ArrayList<TimeData> allTimes = new ArrayList<TimeData>();
    for (int i = 0; i < timeTableNode.size(); i++) {
        JsonNode intervalNode = timeTableNode.get(i);
        try {//from  ww w  .  j  a  v a 2s. com
            double currentTime = ((double) hour) + ((double) minute) / 100d;
            double startInterval = intervalNode.get("start-time").asDouble();
            double endInterval = intervalNode.get("end-time").asDouble();
            if (endInterval < 1.0)
                endInterval += 24.0;
            if (currentTime >= startInterval && currentTime <= endInterval) {
                JsonNode dataNode = dataNodeArray.get(i);
                int[] minutesArray = new int[dataNode.size()];
                for (int j = 0; j < minutesArray.length; j++) {
                    minutesArray[j] = dataNode.get(j).asInt();
                }
                int currentHour = hour;
                int currentIndex = 0;
                int count = 0;
                while (currentHour <= endInterval && count < 3 && currentIndex < minutesArray.length) {
                    double time1 = minutesArray[currentIndex + index1];
                    double time2 = minutesArray[currentIndex + index2];
                    if (time1 < 0 || time2 < 0)
                        continue;
                    time1 /= 100d;
                    time1 += currentHour;
                    time2 /= 100d;
                    time2 += currentHour;
                    if (time2 < time1)
                        time2 += 1.0;
                    allTimes.add(new TimeData(time1, time2));
                    currentHour++;
                    count++;
                    currentIndex += numOfStations;
                }
            }
        } catch (Exception e) {
            LOG.e(e.getLocalizedMessage());
        }
    }

    // sort the list
    for (int i = 0; i < allTimes.size() - 1; i++) {
        for (int j = i + 1; j < allTimes.size(); j++) {
            TimeData td1 = allTimes.get(i);
            TimeData td2 = allTimes.get(j);
            if (td1.stationAtime > td2.stationAtime) {
                allTimes.set(i, td2);
                allTimes.set(j, td1);
            }
        }
    }

    LOG.d("sorted times = " + allTimes.toString());

    // return the 3 results
    for (int i = 0; i < 3 && i < allTimes.size(); i++) {
        TimeData temp = allTimes.get(i);
        int time = 0;
        int minutes1 = (int) ((temp.stationAtime - (double) ((int) temp.stationAtime)) * 100);
        int minutes2 = (int) ((temp.stationBtime - (double) ((int) temp.stationBtime)) * 100);
        time = (((int) temp.stationBtime) - ((int) temp.stationAtime)) * 60;
        if (minutes2 >= minutes1)
            time = minutes2 - minutes1;
        else {
            time += 60 - minutes1 + minutes2;
            time -= 60;
        }
        String formattedTime1 = (((int) temp.stationAtime) < 10 ? "0" + ((int) temp.stationAtime)
                : "" + ((int) temp.stationAtime)) + ":" + (minutes1 < 10 ? "0" + minutes1 : "" + minutes1);
        String formattedTime2 = (((int) temp.stationBtime) < 10 ? "0" + ((int) temp.stationBtime)
                : "" + ((int) temp.stationBtime)) + ":" + (minutes2 < 10 ? "0" + minutes2 : "" + minutes2);
        times.add(new LocalTrainData(formattedTime1, formattedTime2, time));
    }

}

From source file:edu.du.penrose.systems.util.SendMail.java

/**
 * NOTE VERY WELL!! The sends an ssl email, when used with Fedora libraries this throws a SSL Exception, in order to fix this
 * The following SSL system properties are cleared and then restored after the email is sent. l...<br>
 * /*from   w w w  . j a va  2 s  . c  o m*/
 *    System.clearProperty( "javax.net.ssl.keyStore" );
 *  System.clearProperty( "javax.net.ssl.keyStorePassword" );
 *  System.clearProperty( "javax.net.ssl.keyStoreType" );
 *  System.clearProperty( "javax.net.ssl.trustStore" );
 *  System.clearProperty( "javax.net.ssl.trustStorePassword" );
 *  System.clearProperty( "javax.net.ssl.trustStoreType" );
 *  
 * @param recipients
 * @param subject
 * @param message
 * @param from
 * @param smptServerHost
 * @param smtpUser
 * @param smtpPassword
 * @param port
 * @param sslEmail
 */
public static void postMailWithAuthenication(String recipients[], String subject, String message, String from,
        String smptServerHost, String smtpUser, String smtpPassword, String port, boolean sslEmail) {
    if (from == null || !from.contains("@")) {
        logger.info("Unable to send email, missing from address.");
        return;
    }

    String user = smtpUser.trim();
    String password = smtpPassword.trim();

    int numberOfValidRecipients = 0;
    for (int i = 0; i < recipients.length; i++) {
        if (recipients[i] != null && recipients[i].length() > 0 && recipients[i].contains("@")) {
            numberOfValidRecipients++;
        }
    }

    if (numberOfValidRecipients == 0) {
        logger.info("Unable to send email, missing recipients address.");
        return;
    }

    SimpleEmail email = new SimpleEmail();
    email.setSSL(sslEmail);
    email.setSmtpPort(Integer.valueOf(port));
    email.setAuthentication(user, password);
    email.setHostName(smptServerHost);

    try {
        for (int i = 0; i < numberOfValidRecipients; i++) {
            email.addTo(recipients[i]);
        }
        email.setFrom(from);
        email.setSubject(subject);
        email.setMsg(message);

        //   System.setProperty( "javax.net.debug", "ssl" );

        String keyStore = System.getProperty("javax.net.ssl.keyStore");
        String keyStorePassword = System.getProperty("javax.net.ssl.keyStorePassword");
        String keyStoreType = System.getProperty("javax.net.ssl.keyStoreType");
        String trustStore = System.getProperty("javax.net.ssl.trustStore");
        String trustStorePassword = System.getProperty("javax.net.ssl.trustStorePassword");
        String trustStoreType = System.getProperty("javax.net.ssl.trustStoreType");

        System.clearProperty("javax.net.ssl.keyStore");
        System.clearProperty("javax.net.ssl.keyStorePassword");
        System.clearProperty("javax.net.ssl.keyStoreType");
        System.clearProperty("javax.net.ssl.trustStore");
        System.clearProperty("javax.net.ssl.trustStorePassword");
        System.clearProperty("javax.net.ssl.trustStoreType");

        email.send();

        System.setProperty("javax.net.ssl.keyStore", keyStore);
        System.setProperty("javax.net.ssl.keyStorePassword", keyStorePassword);
        System.setProperty("javax.net.ssl.keyStoreType", keyStoreType);
        System.setProperty("javax.net.ssl.trustStore", trustStore);
        System.setProperty("javax.net.ssl.trustStorePassword", trustStorePassword);
        System.setProperty("javax.net.ssl.trustStoreType", trustStoreType);

    } catch (Exception e) {
        logger.error("ERROR sending email:" + e.getLocalizedMessage());
    }

}

From source file:filehandling.FilePreprocessor.java

public static List<FileData> extractMDFilesFromXMLEmbedding(byte[] bytes, String basename, String extension) {

    List<FileData> returnList = new ArrayList<FileData>();
    try {//from ww w .jav a 2  s.c o m
        FileUtils.writeByteArrayToFile(new File("/tmp/debugData/instreamBeforeExtraction.xml"), bytes);
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        DocumentBuilder dBuilder = dbf.newDocumentBuilder();

        Document doc = dBuilder.parse(new InputSource(new ByteArrayInputStream(bytes)));

        if (Master.DEBUG_LEVEL > Master.LOW) {
            System.out.println("Root element: " + doc.getDocumentElement().getNodeName());
        }

        NodeList entryElements = doc.getElementsByTagNameNS("http://www.w3.org/2005/Atom", "entry");
        for (int i = 0; i < entryElements.getLength(); i++) {
            Element entryElement = (Element) entryElements.item(i);
            FileData fd = null;
            /*
             * First try to find a <link> element pointing to Metadata as
             * this should be included by default
             */
            if (fd == null) {
                NodeList linkElements = entryElement.getElementsByTagNameNS("http://www.w3.org/2005/Atom",
                        "link");
                String iso19139Link = null;
                String iso19139_2Link = null;
                for (int j = 0; j < linkElements.getLength(); j++) {
                    Element linkElement = (Element) linkElements.item(j);
                    String relAttrValue = linkElement.getAttribute("rel");
                    String typeAttributeValue = linkElement.getAttribute("type");
                    if (relAttrValue != null && relAttrValue.equals("alternate")
                            && typeAttributeValue != null) {
                        switch (typeAttributeValue) {
                        case "application/vnd.iso.19139+xml":
                            iso19139Link = linkElement.getAttribute("href");
                            break;
                        case "application/vnd.iso.19139-2+xml":
                            iso19139_2Link = linkElement.getAttribute("href");
                            break;
                        }
                    }
                }
                /* iso19139-2 gets priority */
                String url = iso19139_2Link != null ? iso19139_2Link : iso19139Link;
                if (url != null) {
                    try (InputStream is = FileFetcher.fetchFileFromUrl(url)) {
                        Document doc2 = dBuilder.parse(new InputSource(is));
                        fd = processMDList(doc2.getDocumentElement(), extension, url);
                    }
                }
            }
            /*
             * Fallback to finding Metadata embedded directly in <entry>.
             * There will be either MI_Metadata or MD_Metadata, not both
             */
            if (fd == null) {
                fd = processMDList(entryElement.getElementsByTagName("gmi:MI_Metadata").item(0), extension,
                        null);
            }
            if (fd == null) {
                fd = processMDList(entryElement.getElementsByTagName("gmd:MD_Metadata").item(0), extension,
                        null);
            }

            if (fd != null) {
                returnList.add(fd);
            }
        }
    } catch (Exception e) {
        // TODO: handle exception

        if (Master.DEBUG_LEVEL > Master.LOW)
            System.out.println(e.getLocalizedMessage());
        GUIrefs.displayAlert("Error in FilePreprocessor.extractMDFilesFromXMLEmbedding"
                + StringUtilities.escapeQuotes(e.getMessage()));
    }
    return returnList;
}