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 5bc2777bf66d2db77071bdc2051fd8c5071790a6 Author: servantie <servantie.c@gmail.com> Date: Wed Jun 8 10:00:30 2016 +0200 removed a check for empty url in synchronizeSingleTask as it is checked before the method is called (on the addition of tasks to the list to sync) --- .../chorem/jtimer/io/TimerTaskSynchronizer.java | 127 ++++++++++----------- 1 file changed, 62 insertions(+), 65 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java index 425c1f4..e2e480c 100644 --- a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java +++ b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java @@ -35,6 +35,9 @@ public class TimerTaskSynchronizer implements DataEventListener { /** Timezone */ protected String timezone = "+0100"; + /** + * TimerTaskSynchronizer constructor + */ public TimerTaskSynchronizer() { timer = new Timer(); timer.schedule(new UpdateTask(), autoSyncDelay, autoSyncDelay); @@ -58,7 +61,7 @@ public class TimerTaskSynchronizer implements DataEventListener { * @param timezone */ public void setTimezone(String timezone) { - if (!timezone.isEmpty() && !timezone.equals(null)) { + if (!timezone.isEmpty()) { this.timezone = timezone; } } @@ -68,6 +71,7 @@ public class TimerTaskSynchronizer implements DataEventListener { */ protected class UpdateTask extends java.util.TimerTask { + @Override public void run() { if (log.isDebugEnabled()) { log.debug("Synchronizer wake up"); @@ -101,7 +105,8 @@ public class TimerTaskSynchronizer implements DataEventListener { } } - tasksToSync = remainingTasks; + tasksToSync.clear(); + tasksToSync.addAll(remainingTasks); } } } @@ -118,64 +123,61 @@ public class TimerTaskSynchronizer implements DataEventListener { String charset = "UTF-8"; HttpURLConnection connection; URL url; - if (syncURL != null) { - try { - url = new URL(syncURL); - } catch (MalformedURLException e) { - e.printStackTrace(); - //abort synchronization of this task if the url is wrong - return false; - } - try { - connection = (HttpURLConnection) url.openConnection(); - } catch (IOException e) { - e.printStackTrace(); - //abort synchronization of this task if connection impossible - return false; - } - connection.setUseCaches(false); - connection.setDoInput(true); - connection.setDoOutput(true); - connection.setRequestProperty("Content-Length", "" + updateJsonString.length()); - connection.setRequestProperty("Accept-Charset", charset); - connection.setRequestProperty("Content-Type", "application/json"); - try { - connection.setRequestMethod("POST"); - } catch (ProtocolException e) { - e.printStackTrace(); - } - byte[] postDataBytes = new byte[0]; - try { - postDataBytes = updateJsonString.getBytes("UTF-8"); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } - try { - connection.getOutputStream().write(postDataBytes); - } catch (IOException e) { - e.printStackTrace(); - } - //get the header fields - Map<String, List<String>> map = connection.getHeaderFields(); - boolean hasUpdated = false; - //check for answer from server - for (Map.Entry<String, List<String>> entry : map.entrySet()) { - for (String s : entry.getValue()) { - //positive answer, synchronization accepted - if (s.equals("HTTP/1.1 200 OK")) { - hasUpdated = true; - } + try { + url = new URL(syncURL); + } catch (MalformedURLException e) { + log.error("URL malformed"); + //abort synchronization of this task if the url is wrong + return false; + } + try { + connection = (HttpURLConnection) url.openConnection(); + } catch (IOException e) { + log.error("couldn't open connection"); + //abort synchronization of this task if connection impossible + return false; + } + connection.setUseCaches(false); + connection.setDoInput(true); + connection.setDoOutput(true); + connection.setRequestProperty("Content-Length", "" + Integer.toString(updateJsonString.length())); + connection.setRequestProperty("Accept-Charset", charset); + connection.setRequestProperty("Content-Type", "application/json"); + try { + connection.setRequestMethod("POST"); + } catch (ProtocolException e) { + log.error("Protocol error."); + } + byte[] postDataBytes = new byte[0]; + try { + postDataBytes = updateJsonString.getBytes("UTF-8"); + } catch (UnsupportedEncodingException e) { + log.error("Problem with encoding"); + } + try { + connection.getOutputStream().write(postDataBytes); + } catch (IOException e) { + log.error("Problem with the Outputstream"); + } + //get the header fields + Map<String, List<String>> map = connection.getHeaderFields(); + boolean hasUpdated = false; + //check for answer from server + for (Map.Entry<String, List<String>> entry : map.entrySet()) { + for (String s : entry.getValue()) { + //positive answer, synchronization accepted + if ("HTTP/1.1 200 OK".equals(s)) { + hasUpdated = true; } } - if (hasUpdated) { - task.setLastSync(LocalDateTime.now()); - return true; - } else { - log.error("Sync error"); - return false; - } } - return false; + if (hasUpdated) { + task.setLastSync(LocalDateTime.now()); + return true; + } else { + log.error("Sync error"); + return false; + } } @Override @@ -269,10 +271,8 @@ public class TimerTaskSynchronizer implements DataEventListener { public void stopTask(TimerTask task) { if (!tasksToSync.contains(task)) { //add it only if the URL is not empty - if (task.getSynchronisingURL() != null) { - if (task.getSynchronisingURL().isEmpty()) { - tasksToSync.add(task); - } + if ((task.getSynchronisingURL() != null) && !(task.getSynchronisingURL().isEmpty())) { + tasksToSync.add(task); } } } @@ -291,11 +291,8 @@ public class TimerTaskSynchronizer implements DataEventListener { public void modifyTaskURL(TimerTask task, String newURL) { if (!tasksToSync.contains(task)) { //add it only if the URL is not empty - //add it only if the URL is not empty - if (task.getSynchronisingURL() != null) { - if (task.getSynchronisingURL().isEmpty()) { + if ((task.getSynchronisingURL() != null) && !(task.getSynchronisingURL().isEmpty())){ tasksToSync.add(task); - } } } } -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.