diff options
author | Jonathan Bauer | 2014-10-15 18:01:46 +0200 |
---|---|---|
committer | Jonathan Bauer | 2014-10-15 18:01:46 +0200 |
commit | e8bb5a51b4514fc64cff421cb002478c5b259a87 (patch) | |
tree | 38ad16590cf74e875662fec9828fffbb5f83c749 /dozentenmodul/src/main/java/util/News.java | |
parent | user angepasst (diff) | |
download | tutor-module-e8bb5a51b4514fc64cff421cb002478c5b259a87.tar.gz tutor-module-e8bb5a51b4514fc64cff421cb002478c5b259a87.tar.xz tutor-module-e8bb5a51b4514fc64cff421cb002478c5b259a87.zip |
[client] News: print stacktraces to log files aswell
and remove message box, since they are not really needed as the errors are not critical.
Diffstat (limited to 'dozentenmodul/src/main/java/util/News.java')
-rw-r--r-- | dozentenmodul/src/main/java/util/News.java | 51 |
1 files changed, 17 insertions, 34 deletions
diff --git a/dozentenmodul/src/main/java/util/News.java b/dozentenmodul/src/main/java/util/News.java index 22f78c92..aaee7f2a 100644 --- a/dozentenmodul/src/main/java/util/News.java +++ b/dozentenmodul/src/main/java/util/News.java @@ -14,6 +14,7 @@ import javax.xml.parsers.ParserConfigurationException; import models.SessionData; +import org.apache.log4j.Logger; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -33,6 +34,9 @@ import org.xml.sax.SAXException; public class News { + // Logger instance for this class + private final static Logger LOGGER = Logger.getLogger(News.class); + // Private members representing the news private static String headline = null; private static String content = null; @@ -114,20 +118,14 @@ public class News { URL url = null; try { url = new URL("http://" + SessionData.session.getServerAdress() + "/slx-admin/api.php?do=news"); - } catch (MalformedURLException e2) { - e2.printStackTrace(); - // This shouldn't happen, but in case it does, alert user. - JOptionPane.showMessageDialog(null, - "News-URL falsch formatiert!", - "Fehler", JOptionPane.ERROR_MESSAGE); + } catch (MalformedURLException e) { + LOGGER.error("Malformated URL to News-API, see trace: ", e); } - // check for argument + // check is the url got created. if (url == null) { - // no URL, alert user. - JOptionPane.showMessageDialog(null, - "Keine News-URL angegben!", - "Fehler", JOptionPane.ERROR_MESSAGE); + // no URL, log it and return + LOGGER.error("URL to the News-API not defined!"); return; } @@ -139,11 +137,8 @@ public class News { urlCon.setConnectTimeout(5000); // 10 seconds timeout for reading the stream urlCon.setReadTimeout(10000); - } catch (IOException e1) { - e1.printStackTrace(); - JOptionPane.showMessageDialog(null, - "Satellite antwortete auf die Anfrage der News-XML nicht!", - "Fehler", JOptionPane.ERROR_MESSAGE); + } catch (IOException e) { + LOGGER.error("IO error while requesting News URL, see trace: ", e); return; } @@ -151,10 +146,7 @@ public class News { try { is = urlCon.getInputStream(); } catch (IOException e1) { - e1.printStackTrace(); - JOptionPane.showMessageDialog(null, - "Konnte den News-URL-Stream nicht öffnen!", - "Fehler", JOptionPane.ERROR_MESSAGE); + LOGGER.error("Could not open stream to URL '" + url.toString() + "', see trace: ", e1); return; } @@ -164,11 +156,8 @@ public class News { try { builder = factory.newDocumentBuilder(); - } catch (ParserConfigurationException e1) { - e1.printStackTrace(); - JOptionPane.showMessageDialog(null, - "XML-Parser falsch konfiguriert!", - "Fehler", JOptionPane.ERROR_MESSAGE); + } catch (ParserConfigurationException e) { + LOGGER.error("XML parsing configuration error, see trace: ", e); return; } @@ -176,16 +165,10 @@ public class News { try { doc = builder.parse(is); } catch (SAXException e) { - e.printStackTrace(); - JOptionPane.showMessageDialog(null, - "Konnte die News-XML nicht parsen!", - "Fehler", JOptionPane.ERROR_MESSAGE); + LOGGER.error("XML parsing error, see trace: ", e); return; } catch (IOException e) { - JOptionPane.showMessageDialog(null, - "IO-Fehler!", - "Fehler", JOptionPane.ERROR_MESSAGE); - e.printStackTrace(); + LOGGER.error("IO-Error, see trace: ", e); return; } @@ -228,7 +211,7 @@ public class News { try { tmpDate = new Date(Long.parseLong(dateNode.getNodeValue().trim()) * 1000); } catch (NumberFormatException nfe) { - nfe.printStackTrace(); + LOGGER.error("Date format is invalid, see trace: ", nfe); JOptionPane.showMessageDialog(null, "Zeitstempel aus der XML is invalid!", "Fehler", JOptionPane.ERROR_MESSAGE); |