From 8a5afddcf7c4d9624045d8d5e8e323675dbe3a40 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 26 Jun 2015 09:55:39 +1200 Subject: Another attempt to fix geocoding --- src/org/traccar/geocode/JsonReverseGeocoder.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/org/traccar/geocode/JsonReverseGeocoder.java b/src/org/traccar/geocode/JsonReverseGeocoder.java index 684bfa0c1..feaaaa0ed 100644 --- a/src/org/traccar/geocode/JsonReverseGeocoder.java +++ b/src/org/traccar/geocode/JsonReverseGeocoder.java @@ -19,6 +19,7 @@ import org.traccar.helper.Log; import javax.json.Json; import javax.json.JsonObject; +import javax.json.JsonReader; import java.io.InputStreamReader; import java.io.Reader; import java.net.HttpURLConnection; @@ -38,10 +39,13 @@ public abstract class JsonReverseGeocoder implements ReverseGeocoder { try { HttpURLConnection conn = (HttpURLConnection) new URL(String.format(url, latitude, longitude)).openConnection(); + conn.setRequestProperty("Connection", "close"); // don't keep-alive connections try { - Reader reader = new InputStreamReader(conn.getInputStream()); + InputStreamReader streamReader = new InputStreamReader(conn.getInputStream()); + JsonReader reader = Json.createReader(streamReader); try { - Address address = parseAddress(Json.createReader(reader).readObject()); + Address address = parseAddress(reader.readObject()); + while (streamReader.read() > 0); // make sure we reached the end if (address != null) { return format.format(address); } -- cgit v1.2.3