aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/geolocation
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/traccar/geolocation')
-rw-r--r--src/main/java/org/traccar/geolocation/GoogleGeolocationProvider.java8
-rw-r--r--src/main/java/org/traccar/geolocation/MozillaGeolocationProvider.java8
-rw-r--r--src/main/java/org/traccar/geolocation/OpenCellIdGeolocationProvider.java12
-rw-r--r--src/main/java/org/traccar/geolocation/UniversalGeolocationProvider.java12
-rw-r--r--src/main/java/org/traccar/geolocation/UnwiredGeolocationProvider.java16
5 files changed, 32 insertions, 24 deletions
diff --git a/src/main/java/org/traccar/geolocation/GoogleGeolocationProvider.java b/src/main/java/org/traccar/geolocation/GoogleGeolocationProvider.java
index 5901b47cd..8f0f3b704 100644
--- a/src/main/java/org/traccar/geolocation/GoogleGeolocationProvider.java
+++ b/src/main/java/org/traccar/geolocation/GoogleGeolocationProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 - 2022 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,12 +15,14 @@
*/
package org.traccar.geolocation;
+import javax.ws.rs.client.Client;
+
public class GoogleGeolocationProvider extends UniversalGeolocationProvider {
private static final String URL = "https://www.googleapis.com/geolocation/v1/geolocate";
- public GoogleGeolocationProvider(String key) {
- super(URL, key);
+ public GoogleGeolocationProvider(Client client, String key) {
+ super(client, URL, key);
}
}
diff --git a/src/main/java/org/traccar/geolocation/MozillaGeolocationProvider.java b/src/main/java/org/traccar/geolocation/MozillaGeolocationProvider.java
index c6a73a52b..3b4ba4e1f 100644
--- a/src/main/java/org/traccar/geolocation/MozillaGeolocationProvider.java
+++ b/src/main/java/org/traccar/geolocation/MozillaGeolocationProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2022 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,12 +15,14 @@
*/
package org.traccar.geolocation;
+import javax.ws.rs.client.Client;
+
public class MozillaGeolocationProvider extends UniversalGeolocationProvider {
private static final String URL = "https://location.services.mozilla.com/v1/geolocate";
- public MozillaGeolocationProvider(String key) {
- super(URL, key != null ? key : "test");
+ public MozillaGeolocationProvider(Client client, String key) {
+ super(client, URL, key != null ? key : "test");
}
}
diff --git a/src/main/java/org/traccar/geolocation/OpenCellIdGeolocationProvider.java b/src/main/java/org/traccar/geolocation/OpenCellIdGeolocationProvider.java
index 2535970d3..82fcf42ab 100644
--- a/src/main/java/org/traccar/geolocation/OpenCellIdGeolocationProvider.java
+++ b/src/main/java/org/traccar/geolocation/OpenCellIdGeolocationProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2022 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,18 +15,20 @@
*/
package org.traccar.geolocation;
-import org.traccar.Context;
import org.traccar.model.CellTower;
import org.traccar.model.Network;
import javax.json.JsonObject;
+import javax.ws.rs.client.Client;
import javax.ws.rs.client.InvocationCallback;
public class OpenCellIdGeolocationProvider implements GeolocationProvider {
- private String url;
+ private final Client client;
+ private final String url;
- public OpenCellIdGeolocationProvider(String url, String key) {
+ public OpenCellIdGeolocationProvider(Client client, String url, String key) {
+ this.client = client;
if (url == null) {
url = "http://opencellid.org/cell/get";
}
@@ -41,7 +43,7 @@ public class OpenCellIdGeolocationProvider implements GeolocationProvider {
String request = String.format(url, cellTower.getMobileCountryCode(), cellTower.getMobileNetworkCode(),
cellTower.getLocationAreaCode(), cellTower.getCellId());
- Context.getClient().target(request).request().async().get(new InvocationCallback<JsonObject>() {
+ client.target(request).request().async().get(new InvocationCallback<JsonObject>() {
@Override
public void completed(JsonObject json) {
if (json.containsKey("lat") && json.containsKey("lon")) {
diff --git a/src/main/java/org/traccar/geolocation/UniversalGeolocationProvider.java b/src/main/java/org/traccar/geolocation/UniversalGeolocationProvider.java
index 33cd84a47..7a3f71ee1 100644
--- a/src/main/java/org/traccar/geolocation/UniversalGeolocationProvider.java
+++ b/src/main/java/org/traccar/geolocation/UniversalGeolocationProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 - 2018 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 - 2022 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,26 +15,26 @@
*/
package org.traccar.geolocation;
-import org.traccar.Context;
import org.traccar.model.Network;
import javax.json.JsonObject;
-import javax.ws.rs.client.AsyncInvoker;
+import javax.ws.rs.client.Client;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.InvocationCallback;
public class UniversalGeolocationProvider implements GeolocationProvider {
+ private final Client client;
private final String url;
- public UniversalGeolocationProvider(String url, String key) {
+ public UniversalGeolocationProvider(Client client, String url, String key) {
+ this.client = client;
this.url = url + "?key=" + key;
}
@Override
public void getLocation(Network network, final LocationProviderCallback callback) {
- AsyncInvoker invoker = Context.getClient().target(url).request().async();
- invoker.post(Entity.json(network), new InvocationCallback<JsonObject>() {
+ client.target(url).request().async().post(Entity.json(network), new InvocationCallback<JsonObject>() {
@Override
public void completed(JsonObject json) {
if (json.containsKey("error")) {
diff --git a/src/main/java/org/traccar/geolocation/UnwiredGeolocationProvider.java b/src/main/java/org/traccar/geolocation/UnwiredGeolocationProvider.java
index 963bcb688..14893b6a3 100644
--- a/src/main/java/org/traccar/geolocation/UnwiredGeolocationProvider.java
+++ b/src/main/java/org/traccar/geolocation/UnwiredGeolocationProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 - 2018 Anton Tananaev (anton@traccar.org)
+ * Copyright 2017 - 2022 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,22 +19,23 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
-import org.traccar.Context;
import org.traccar.model.CellTower;
import org.traccar.model.Network;
import org.traccar.model.WifiAccessPoint;
import javax.json.JsonObject;
+import javax.ws.rs.client.Client;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.InvocationCallback;
import java.util.Collection;
public class UnwiredGeolocationProvider implements GeolocationProvider {
- private String url;
- private String key;
+ private final Client client;
+ private final String url;
+ private final String key;
- private ObjectMapper objectMapper;
+ private final ObjectMapper objectMapper;
private abstract static class NetworkMixIn {
@JsonProperty("mcc")
@@ -73,7 +74,8 @@ public class UnwiredGeolocationProvider implements GeolocationProvider {
abstract Integer getSignalStrength();
}
- public UnwiredGeolocationProvider(String url, String key) {
+ public UnwiredGeolocationProvider(Client client, String url, String key) {
+ this.client = client;
this.url = url;
this.key = key;
@@ -88,7 +90,7 @@ public class UnwiredGeolocationProvider implements GeolocationProvider {
ObjectNode json = objectMapper.valueToTree(network);
json.put("token", key);
- Context.getClient().target(url).request().async().post(Entity.json(json), new InvocationCallback<JsonObject>() {
+ client.target(url).request().async().post(Entity.json(json), new InvocationCallback<JsonObject>() {
@Override
public void completed(JsonObject json) {
if (json.getString("status").equals("error")) {