This is an automated email from the git hooks/post-receive script. New commit to branch feature/sync in repository jtimer. See https://gitlab.nuiton.org/chorem/jtimer.git commit 30d6c44aa473105a6392a4336219c6eb159169b3 Author: servantie <servantie.c@gmail.com> Date: Thu Jun 16 10:38:10 2016 +0200 checking for response codes and sending error messages to user (if needed) --- .../chorem/jtimer/io/TimerTaskSynchronizer.java | 1 - .../jtimer/ui/report/TimerTaskUpdaterView.java | 45 +++++++++++++++------- .../resources/TimerTaskUpdaterView.properties | 7 +++- .../resources/TimerTaskUpdaterView_fr.properties | 9 ++++- 4 files changed, 44 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java index b4fb1a1..0fececb 100644 --- a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java +++ b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java @@ -158,7 +158,6 @@ public class TimerTaskSynchronizer implements DataEventListener { } else { log.info("Error"); - } } catch (MalformedURLException e) { log.error("URL malformed"); diff --git a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java index 91bd5fe..263ded8 100644 --- a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java +++ b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java @@ -444,6 +444,8 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, URL url; byte[] postDataBytes; boolean hasUpdated = false; + String message = ""; + String title = getResourceMap().getString("action.updateErrorTitle"); try { url = new URL(syncURL); connection = (HttpURLConnection) url.openConnection(); @@ -457,31 +459,45 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, postDataBytes = updateJsonString.getBytes(charset); connection.getOutputStream().write(postDataBytes); int code = connection.getResponseCode(); - if (code == 200) { + if ((code == 200) || (code == 2001) || (code == 202)) { hasUpdated = true; } else if (code == 400) { - log.error("Bad Request"); + log.debug("Bad Request"); + message = getResourceMap().getString("action.update400"); + } + else if (code == 404) { + log.debug("Not Found"); + message = getResourceMap().getString("action.update404"); + } + else if (code == 500) { + log.debug("Server Error"); + message = getResourceMap().getString("action.update500"); } else { - log.info("Error"); + log.debug("Error"); + message = getResourceMap().getString("action.updateError"); } connection.disconnect(); + } catch (MalformedURLException e) { - log.error("URL malformed"); + log.debug("URL malformed"); + message = getResourceMap().getString("action.updateURLError"); } catch (ProtocolException e) { - log.error("Protocol error."); + log.debug("Protocol error."); + message = getResourceMap().getString("action.updateProtocolError"); } catch (UnsupportedEncodingException e) { - log.error("Problem with encoding"); + log.debug("Problem with encoding"); + message = getResourceMap().getString("action.updateEncodingError"); } catch (IOException e) { - log.error("Problem with the connection"); - } - if (hasUpdated) { + log.debug("Problem with the connection"); + message = getResourceMap().getString("action.updateError"); + } finally { + if (hasUpdated) { task.setLastSync(LocalDateTime.now(),syncURL); - } else { - String message = getResourceMap().getString("action.updateError"); - String title = getResourceMap().getString("action.updateErrorTitle"); - errorBox(message, title); + } else if (!message.isEmpty()){ + errorBox(message, title); + } } //advise that it's done, to grey-out the send sync button boolean oldValue = canUpdate; @@ -498,6 +514,7 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, { JOptionPane.showMessageDialog(null, errorMessage, titleBar, JOptionPane.ERROR_MESSAGE); } + @Override public void changedUpdate(DocumentEvent e) { documentChanged(); @@ -524,7 +541,7 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, /** * when an item is added to the list, - * add it to the urls + * add it to the url displayed, and to the syncInfo of the task */ public void itemAdded(){ String urlToAdd = (String) urlComboBox.getSelectedItem(); diff --git a/src/main/resources/org/chorem/jtimer/ui/report/resources/TimerTaskUpdaterView.properties b/src/main/resources/org/chorem/jtimer/ui/report/resources/TimerTaskUpdaterView.properties index dca4916..70ef7be 100644 --- a/src/main/resources/org/chorem/jtimer/ui/report/resources/TimerTaskUpdaterView.properties +++ b/src/main/resources/org/chorem/jtimer/ui/report/resources/TimerTaskUpdaterView.properties @@ -56,5 +56,10 @@ closeView.Action.text = &Close closeView.Action.icon = dialog-close.png closeView.Action.shortDescription = Close -action.updateError = Synchronisation failed, check URL ? +action.updateError = Synchronisation failed +action.update400 = Bad Request +action.update404 = Not found +action.update500 = Server error action.updateErrorTitle = Synchronisation error +action.updateEncodingError = Encoding error +action.updateURLError = URL error \ No newline at end of file diff --git a/src/main/resources/org/chorem/jtimer/ui/report/resources/TimerTaskUpdaterView_fr.properties b/src/main/resources/org/chorem/jtimer/ui/report/resources/TimerTaskUpdaterView_fr.properties index 9dd1b73..329a948 100644 --- a/src/main/resources/org/chorem/jtimer/ui/report/resources/TimerTaskUpdaterView_fr.properties +++ b/src/main/resources/org/chorem/jtimer/ui/report/resources/TimerTaskUpdaterView_fr.properties @@ -56,5 +56,10 @@ closeView.Action.text = &Fermer closeView.Action.icon = dialog-close.png closeView.Action.shortDescription = Fermer -action.updateError = Erreur de synchronisation, v\u00E9rifier l'URL ? -action.updateErrorTitle = Erreur de synchronisation \ No newline at end of file +action.updateError = Probl\u00E8me avec la connexion +action.updateErrorTitle = Erreur de synchronisation +action.update400 = Mauvaise requ\u00EAte +action.update404 = Mauvaise URL +action.update500 = Erreur du serveur +action.updateEncodingError = Erreur d'encodage +action.updateURLError = Erreur d'URL \ No newline at end of file -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.