From 550f2acc599b3be7150841c6c4da27ce9f48f231 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Dutoit?= Date: Thu, 12 Oct 2017 15:16:58 +0200 Subject: [PATCH] Added nullcheck --- .../java/ch/mno/copper/collect/WebCollector.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/main/java/ch/mno/copper/collect/WebCollector.java b/src/main/java/ch/mno/copper/collect/WebCollector.java index 536a452..570bdda 100644 --- a/src/main/java/ch/mno/copper/collect/WebCollector.java +++ b/src/main/java/ch/mno/copper/collect/WebCollector.java @@ -60,6 +60,7 @@ public static List query(String url, String username, String password, L results = extractValues(data, valuesKept); } catch (Exception e) { System.err.println("Connector exception (server " + url+ "): " + e.getMessage()); + e.printStackTrace(); if (results==null) { results = new ArrayList<>(valuesKept.size()); } @@ -100,7 +101,9 @@ else if ("contentType".equals(key)) { results.add(res.get(0).toString()); } } else if (o instanceof String) { - results.add((String)o); + results.add((String) o); + } else if (o==null) { + results.add("null"); } else { results.add(o.toString()); } @@ -113,12 +116,5 @@ else if ("contentType".equals(key)) { return results; } - public static void main(String[] args) { - List> values = new ArrayList<>(); - values.add(new ImmutablePair<>("responseCode", "rs")); - values.add(new ImmutablePair<>("status", "s")); - WebCollector.query("http://tom.etat-de-vaud.ch:1530/ws/infra/status", null, null, values); - } - }