aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/geocode/JsonReverseGeocoder.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-06-26 09:25:17 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2015-06-26 09:25:17 +1200
commita6d6797aad992068406bfcfaeb2290662951fa41 (patch)
tree5922ff4bfbb10564e746c4044577098ec9020da2 /src/org/traccar/geocode/JsonReverseGeocoder.java
parent9067f6f540441b839584ff90e5ff858f5433f0c7 (diff)
downloadtrackermap-server-a6d6797aad992068406bfcfaeb2290662951fa41.tar.gz
trackermap-server-a6d6797aad992068406bfcfaeb2290662951fa41.tar.bz2
trackermap-server-a6d6797aad992068406bfcfaeb2290662951fa41.zip
Revert Apache HTTP client
This reverts commit 9067f6f540441b839584ff90e5ff858f5433f0c7.
Diffstat (limited to 'src/org/traccar/geocode/JsonReverseGeocoder.java')
-rw-r--r--src/org/traccar/geocode/JsonReverseGeocoder.java34
1 files changed, 12 insertions, 22 deletions
diff --git a/src/org/traccar/geocode/JsonReverseGeocoder.java b/src/org/traccar/geocode/JsonReverseGeocoder.java
index 3f5fe8bed..684bfa0c1 100644
--- a/src/org/traccar/geocode/JsonReverseGeocoder.java
+++ b/src/org/traccar/geocode/JsonReverseGeocoder.java
@@ -15,17 +15,15 @@
*/
package org.traccar.geocode;
-import org.apache.http.HttpEntity;
-import org.apache.http.client.methods.CloseableHttpResponse;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClients;
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;
+import java.net.URL;
+import java.net.URLConnection;
public abstract class JsonReverseGeocoder implements ReverseGeocoder {
@@ -39,29 +37,21 @@ public abstract class JsonReverseGeocoder implements ReverseGeocoder {
public String getAddress(AddressFormat format, double latitude, double longitude) {
try {
- CloseableHttpClient httpClient = HttpClients.createDefault();
+ HttpURLConnection conn = (HttpURLConnection) new URL(String.format(url, latitude, longitude)).openConnection();
try {
- CloseableHttpResponse response = httpClient.execute(new HttpGet(String.format(url, latitude, longitude)));
+ Reader reader = new InputStreamReader(conn.getInputStream());
try {
- HttpEntity entity = response.getEntity();
- if (entity != null) {
- JsonReader reader = Json.createReader(new InputStreamReader(entity.getContent()));
- try {
- Address address = parseAddress(reader.readObject());
- if (address != null) {
- return format.format(address);
- }
- } finally {
- reader.close();
- }
+ Address address = parseAddress(Json.createReader(reader).readObject());
+ if (address != null) {
+ return format.format(address);
}
} finally {
- response.close();
+ reader.close();
}
} finally {
- httpClient.close();
+ conn.disconnect();
}
- } catch (Exception error) {
+ } catch(Exception error) {
Log.warning(error);
}