aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-06-24 10:11:43 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2015-06-24 10:11:43 +1200
commit55744465b536fec0595ff2489d8e0fdf3008c0ff (patch)
tree8fff35bf1b79968b4325635ae9af1a6dd9a0411c /src/org/traccar
parent5832b1b982049de7242f5378b08b3dd24477eeee (diff)
downloadtrackermap-server-55744465b536fec0595ff2489d8e0fdf3008c0ff.tar.gz
trackermap-server-55744465b536fec0595ff2489d8e0fdf3008c0ff.tar.bz2
trackermap-server-55744465b536fec0595ff2489d8e0fdf3008c0ff.zip
Clean up HTTP connection
Diffstat (limited to 'src/org/traccar')
-rw-r--r--src/org/traccar/geocode/JsonReverseGeocoder.java17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/org/traccar/geocode/JsonReverseGeocoder.java b/src/org/traccar/geocode/JsonReverseGeocoder.java
index cd7dafae5..684bfa0c1 100644
--- a/src/org/traccar/geocode/JsonReverseGeocoder.java
+++ b/src/org/traccar/geocode/JsonReverseGeocoder.java
@@ -21,6 +21,7 @@ import javax.json.Json;
import javax.json.JsonObject;
import java.io.InputStreamReader;
import java.io.Reader;
+import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
@@ -36,15 +37,19 @@ public abstract class JsonReverseGeocoder implements ReverseGeocoder {
public String getAddress(AddressFormat format, double latitude, double longitude) {
try {
- URLConnection conn = new URL(String.format(url, latitude, longitude)).openConnection();
- Reader reader = new InputStreamReader(conn.getInputStream());
+ HttpURLConnection conn = (HttpURLConnection) new URL(String.format(url, latitude, longitude)).openConnection();
try {
- Address address = parseAddress(Json.createReader(reader).readObject());
- if (address != null) {
- return format.format(address);
+ Reader reader = new InputStreamReader(conn.getInputStream());
+ try {
+ Address address = parseAddress(Json.createReader(reader).readObject());
+ if (address != null) {
+ return format.format(address);
+ }
+ } finally {
+ reader.close();
}
} finally {
- reader.close();
+ conn.disconnect();
}
} catch(Exception error) {
Log.warning(error);