aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/geocoder/JsonGeocoder.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-06-11 15:04:51 -0700
committerAnton Tananaev <anton@traccar.org>2022-06-11 15:04:51 -0700
commit7c08991f12b4958135fdffc26f272677c03630ad (patch)
treec1111ec78bad1dd8b0e4eb8f0c9194095d154d57 /src/main/java/org/traccar/geocoder/JsonGeocoder.java
parent4025a42c42e34bb620f4263de05781a10ddc7a9d (diff)
downloadtrackermap-server-7c08991f12b4958135fdffc26f272677c03630ad.tar.gz
trackermap-server-7c08991f12b4958135fdffc26f272677c03630ad.tar.bz2
trackermap-server-7c08991f12b4958135fdffc26f272677c03630ad.zip
Inject network client
Diffstat (limited to 'src/main/java/org/traccar/geocoder/JsonGeocoder.java')
-rw-r--r--src/main/java/org/traccar/geocoder/JsonGeocoder.java9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/main/java/org/traccar/geocoder/JsonGeocoder.java b/src/main/java/org/traccar/geocoder/JsonGeocoder.java
index f20aa79d6..0262de18c 100644
--- a/src/main/java/org/traccar/geocoder/JsonGeocoder.java
+++ b/src/main/java/org/traccar/geocoder/JsonGeocoder.java
@@ -17,13 +17,12 @@ package org.traccar.geocoder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.traccar.Context;
import org.traccar.Main;
import org.traccar.database.StatisticsManager;
import javax.json.JsonObject;
import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.client.Invocation;
+import javax.ws.rs.client.Client;
import javax.ws.rs.client.InvocationCallback;
import java.util.AbstractMap;
import java.util.Collections;
@@ -34,12 +33,14 @@ public abstract class JsonGeocoder implements Geocoder {
private static final Logger LOGGER = LoggerFactory.getLogger(JsonGeocoder.class);
+ private final Client client;
private final String url;
private final AddressFormat addressFormat;
private Map<Map.Entry<Double, Double>, String> cache;
- public JsonGeocoder(String url, final int cacheSize, AddressFormat addressFormat) {
+ public JsonGeocoder(Client client, String url, final int cacheSize, AddressFormat addressFormat) {
+ this.client = client;
this.url = url;
this.addressFormat = addressFormat;
if (cacheSize > 0) {
@@ -101,7 +102,7 @@ public abstract class JsonGeocoder implements Geocoder {
Main.getInjector().getInstance(StatisticsManager.class).registerGeocoderRequest();
}
- Invocation.Builder request = Context.getClient().target(String.format(url, latitude, longitude)).request();
+ var request = client.target(String.format(url, latitude, longitude)).request();
if (callback != null) {
request.async().get(new InvocationCallback<JsonObject>() {