aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2016-12-31 11:41:56 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2016-12-31 11:41:56 +1300
commit679c2852e3c4987091e0b84b7e7d80a9f72964a0 (patch)
treec0fe0ab222bbd251b25e3520c5f62c68669fbaa2
parent68569c05fb4be377baed5cd0ecb1b75176d24f01 (diff)
downloadtrackermap-server-679c2852e3c4987091e0b84b7e7d80a9f72964a0.tar.gz
trackermap-server-679c2852e3c4987091e0b84b7e7d80a9f72964a0.tar.bz2
trackermap-server-679c2852e3c4987091e0b84b7e7d80a9f72964a0.zip
Add exception classes and more renames
-rw-r--r--src/org/traccar/BasePipelineFactory.java20
-rw-r--r--src/org/traccar/Context.java46
-rw-r--r--src/org/traccar/GeocoderHandler.java (renamed from src/org/traccar/ReverseGeocoderHandler.java)10
-rw-r--r--src/org/traccar/GeolocationHandler.java (renamed from src/org/traccar/LocationProviderHandler.java)6
-rw-r--r--src/org/traccar/geocoder/BingMapsGeocoder.java (renamed from src/org/traccar/geocoder/BingMapsReverseGeocoder.java)4
-rw-r--r--src/org/traccar/geocoder/FactualGeocoder.java (renamed from src/org/traccar/geocoder/FactualReverseGeocoder.java)4
-rw-r--r--src/org/traccar/geocoder/GeocodeFarmGeocoder.java (renamed from src/org/traccar/geocoder/GeocodeFarmReverseGeocoder.java)6
-rw-r--r--src/org/traccar/geocoder/Geocoder.java (renamed from src/org/traccar/geocoder/ReverseGeocoder.java)2
-rw-r--r--src/org/traccar/geocoder/GeocoderException.java24
-rw-r--r--src/org/traccar/geocoder/GisgraphyGeocoder.java (renamed from src/org/traccar/geocoder/GisgraphyReverseGeocoder.java)6
-rw-r--r--src/org/traccar/geocoder/GoogleGeocoder.java (renamed from src/org/traccar/geocoder/GoogleReverseGeocoder.java)8
-rw-r--r--src/org/traccar/geocoder/JsonGeocoder.java (renamed from src/org/traccar/geocoder/JsonReverseGeocoder.java)6
-rw-r--r--src/org/traccar/geocoder/MapQuestGeocoder.java (renamed from src/org/traccar/geocoder/MapQuestReverseGeocoder.java)4
-rw-r--r--src/org/traccar/geocoder/NominatimGeocoder.java (renamed from src/org/traccar/geocoder/NominatimReverseGeocoder.java)8
-rw-r--r--src/org/traccar/geocoder/OpenCageGeocoder.java (renamed from src/org/traccar/geocoder/OpenCageReverseGeocoder.java)4
-rw-r--r--src/org/traccar/geolocation/GeolocationException.java24
-rw-r--r--src/org/traccar/geolocation/OpenCellIdGeolocationProvider.java4
-rw-r--r--src/org/traccar/geolocation/UniversalGeolocationProvider.java3
-rw-r--r--test/org/traccar/geocoder/GeocoderTest.java (renamed from test/org/traccar/geocoder/ReverseGeocoderTest.java)22
19 files changed, 130 insertions, 81 deletions
diff --git a/src/org/traccar/BasePipelineFactory.java b/src/org/traccar/BasePipelineFactory.java
index 94a6d85aa..d949c9c9c 100644
--- a/src/org/traccar/BasePipelineFactory.java
+++ b/src/org/traccar/BasePipelineFactory.java
@@ -48,8 +48,8 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory {
private FilterHandler filterHandler;
private CoordinatesHandler coordinatesHandler;
private DistanceHandler distanceHandler;
- private ReverseGeocoderHandler reverseGeocoderHandler;
- private LocationProviderHandler locationProviderHandler;
+ private GeocoderHandler geocoderHandler;
+ private GeolocationHandler geolocationHandler;
private HemisphereHandler hemisphereHandler;
private CopyAttributesHandler copyAttributesHandler;
@@ -125,13 +125,13 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory {
coordinatesHandler = new CoordinatesHandler();
}
- if (Context.getReverseGeocoder() != null) {
- reverseGeocoderHandler = new ReverseGeocoderHandler(
- Context.getReverseGeocoder(), Context.getConfig().getBoolean("geocoder.processInvalidPositions"));
+ if (Context.getGeocoder() != null) {
+ geocoderHandler = new GeocoderHandler(
+ Context.getGeocoder(), Context.getConfig().getBoolean("geocoder.processInvalidPositions"));
}
if (Context.getGeolocationProvider() != null) {
- locationProviderHandler = new LocationProviderHandler(
+ geolocationHandler = new GeolocationHandler(
Context.getGeolocationProvider(), Context.getConfig().getBoolean("location.processInvalidPositions"));
}
@@ -189,11 +189,11 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory {
if (hemisphereHandler != null) {
pipeline.addLast("hemisphere", hemisphereHandler);
}
- if (reverseGeocoderHandler != null) {
- pipeline.addLast("geocoder", reverseGeocoderHandler);
+ if (geocoderHandler != null) {
+ pipeline.addLast("geocoder", geocoderHandler);
}
- if (locationProviderHandler != null) {
- pipeline.addLast("location", locationProviderHandler);
+ if (geolocationHandler != null) {
+ pipeline.addLast("location", geolocationHandler);
}
pipeline.addLast("remoteAddress", new RemoteAddressHandler());
diff --git a/src/org/traccar/Context.java b/src/org/traccar/Context.java
index 72d5dd9f8..46294edfa 100644
--- a/src/org/traccar/Context.java
+++ b/src/org/traccar/Context.java
@@ -34,15 +34,15 @@ import org.traccar.database.NotificationManager;
import org.traccar.database.PermissionsManager;
import org.traccar.database.GeofenceManager;
import org.traccar.database.StatisticsManager;
-import org.traccar.geocoder.BingMapsReverseGeocoder;
-import org.traccar.geocoder.FactualReverseGeocoder;
-import org.traccar.geocoder.GeocodeFarmReverseGeocoder;
-import org.traccar.geocoder.GisgraphyReverseGeocoder;
-import org.traccar.geocoder.GoogleReverseGeocoder;
-import org.traccar.geocoder.MapQuestReverseGeocoder;
-import org.traccar.geocoder.NominatimReverseGeocoder;
-import org.traccar.geocoder.OpenCageReverseGeocoder;
-import org.traccar.geocoder.ReverseGeocoder;
+import org.traccar.geocoder.BingMapsGeocoder;
+import org.traccar.geocoder.FactualGeocoder;
+import org.traccar.geocoder.GeocodeFarmGeocoder;
+import org.traccar.geocoder.GisgraphyGeocoder;
+import org.traccar.geocoder.GoogleGeocoder;
+import org.traccar.geocoder.MapQuestGeocoder;
+import org.traccar.geocoder.NominatimGeocoder;
+import org.traccar.geocoder.OpenCageGeocoder;
+import org.traccar.geocoder.Geocoder;
import org.traccar.helper.Log;
import org.traccar.geolocation.GoogleGeolocationProvider;
import org.traccar.geolocation.GeolocationProvider;
@@ -104,10 +104,10 @@ public final class Context {
return permissionsManager;
}
- private static ReverseGeocoder reverseGeocoder;
+ private static Geocoder geocoder;
- public static ReverseGeocoder getReverseGeocoder() {
- return reverseGeocoder;
+ public static Geocoder getGeocoder() {
+ return geocoder;
}
private static GeolocationProvider geolocationProvider;
@@ -213,37 +213,37 @@ public final class Context {
switch (type) {
case "nominatim":
if (key != null) {
- reverseGeocoder = new NominatimReverseGeocoder(url, key, cacheSize);
+ geocoder = new NominatimGeocoder(url, key, cacheSize);
} else {
- reverseGeocoder = new NominatimReverseGeocoder(url, cacheSize);
+ geocoder = new NominatimGeocoder(url, cacheSize);
}
break;
case "gisgraphy":
- reverseGeocoder = new GisgraphyReverseGeocoder(url, cacheSize);
+ geocoder = new GisgraphyGeocoder(url, cacheSize);
break;
case "mapquest":
- reverseGeocoder = new MapQuestReverseGeocoder(url, key, cacheSize);
+ geocoder = new MapQuestGeocoder(url, key, cacheSize);
break;
case "opencage":
- reverseGeocoder = new OpenCageReverseGeocoder(url, key, cacheSize);
+ geocoder = new OpenCageGeocoder(url, key, cacheSize);
break;
case "bingmaps":
- reverseGeocoder = new BingMapsReverseGeocoder(url, key, cacheSize);
+ geocoder = new BingMapsGeocoder(url, key, cacheSize);
break;
case "factual":
- reverseGeocoder = new FactualReverseGeocoder(url, key, cacheSize);
+ geocoder = new FactualGeocoder(url, key, cacheSize);
break;
case "geocodefarm":
if (key != null) {
- reverseGeocoder = new GeocodeFarmReverseGeocoder(key, cacheSize);
+ geocoder = new GeocodeFarmGeocoder(key, cacheSize);
} else {
- reverseGeocoder = new GeocodeFarmReverseGeocoder(cacheSize);
+ geocoder = new GeocodeFarmGeocoder(cacheSize);
}
default:
if (key != null) {
- reverseGeocoder = new GoogleReverseGeocoder(key, cacheSize);
+ geocoder = new GoogleGeocoder(key, cacheSize);
} else {
- reverseGeocoder = new GoogleReverseGeocoder(cacheSize);
+ geocoder = new GoogleGeocoder(cacheSize);
}
break;
}
diff --git a/src/org/traccar/ReverseGeocoderHandler.java b/src/org/traccar/GeocoderHandler.java
index 5813c1136..8933cadac 100644
--- a/src/org/traccar/ReverseGeocoderHandler.java
+++ b/src/org/traccar/GeocoderHandler.java
@@ -21,17 +21,17 @@ import org.jboss.netty.channel.ChannelUpstreamHandler;
import org.jboss.netty.channel.Channels;
import org.jboss.netty.channel.MessageEvent;
import org.traccar.geocoder.AddressFormat;
-import org.traccar.geocoder.ReverseGeocoder;
+import org.traccar.geocoder.Geocoder;
import org.traccar.helper.Log;
import org.traccar.model.Position;
-public class ReverseGeocoderHandler implements ChannelUpstreamHandler {
+public class GeocoderHandler implements ChannelUpstreamHandler {
- private final ReverseGeocoder geocoder;
+ private final Geocoder geocoder;
private final boolean processInvalidPositions;
private final AddressFormat addressFormat;
- public ReverseGeocoderHandler(ReverseGeocoder geocoder, boolean processInvalidPositions) {
+ public GeocoderHandler(Geocoder geocoder, boolean processInvalidPositions) {
this.geocoder = geocoder;
this.processInvalidPositions = processInvalidPositions;
@@ -56,7 +56,7 @@ public class ReverseGeocoderHandler implements ChannelUpstreamHandler {
final Position position = (Position) message;
if (processInvalidPositions || position.getValid()) {
geocoder.getAddress(addressFormat, position.getLatitude(), position.getLongitude(),
- new ReverseGeocoder.ReverseGeocoderCallback() {
+ new Geocoder.ReverseGeocoderCallback() {
@Override
public void onSuccess(String address) {
position.setAddress(address);
diff --git a/src/org/traccar/LocationProviderHandler.java b/src/org/traccar/GeolocationHandler.java
index bf37a8b88..1e9bd6772 100644
--- a/src/org/traccar/LocationProviderHandler.java
+++ b/src/org/traccar/GeolocationHandler.java
@@ -24,12 +24,12 @@ import org.traccar.helper.Log;
import org.traccar.geolocation.GeolocationProvider;
import org.traccar.model.Position;
-public class LocationProviderHandler implements ChannelUpstreamHandler {
+public class GeolocationHandler implements ChannelUpstreamHandler {
private final GeolocationProvider geolocationProvider;
private final boolean processInvalidPositions;
- public LocationProviderHandler(GeolocationProvider geolocationProvider, boolean processInvalidPositions) {
+ public GeolocationHandler(GeolocationProvider geolocationProvider, boolean processInvalidPositions) {
this.geolocationProvider = geolocationProvider;
this.processInvalidPositions = processInvalidPositions;
}
@@ -61,7 +61,7 @@ public class LocationProviderHandler implements ChannelUpstreamHandler {
@Override
public void onFailure(Throwable e) {
- Log.warning("Geolocation failed", e);
+ Log.warning(e);
Channels.fireMessageReceived(ctx, position, event.getRemoteAddress());
}
});
diff --git a/src/org/traccar/geocoder/BingMapsReverseGeocoder.java b/src/org/traccar/geocoder/BingMapsGeocoder.java
index 46354d06a..a9b36219a 100644
--- a/src/org/traccar/geocoder/BingMapsReverseGeocoder.java
+++ b/src/org/traccar/geocoder/BingMapsGeocoder.java
@@ -18,9 +18,9 @@ package org.traccar.geocoder;
import javax.json.JsonArray;
import javax.json.JsonObject;
-public class BingMapsReverseGeocoder extends JsonReverseGeocoder {
+public class BingMapsGeocoder extends JsonGeocoder {
- public BingMapsReverseGeocoder(String url, String key, int cacheSize) {
+ public BingMapsGeocoder(String url, String key, int cacheSize) {
super(url + "/Locations/%f,%f?key=" + key + "&include=ciso2", cacheSize);
}
diff --git a/src/org/traccar/geocoder/FactualReverseGeocoder.java b/src/org/traccar/geocoder/FactualGeocoder.java
index f1137893e..0c76e4625 100644
--- a/src/org/traccar/geocoder/FactualReverseGeocoder.java
+++ b/src/org/traccar/geocoder/FactualGeocoder.java
@@ -17,9 +17,9 @@ package org.traccar.geocoder;
import javax.json.JsonObject;
-public class FactualReverseGeocoder extends JsonReverseGeocoder {
+public class FactualGeocoder extends JsonGeocoder {
- public FactualReverseGeocoder(String url, String key, int cacheSize) {
+ public FactualGeocoder(String url, String key, int cacheSize) {
super(url + "?latitude=%f&longitude=%f&KEY=" + key, cacheSize);
}
diff --git a/src/org/traccar/geocoder/GeocodeFarmReverseGeocoder.java b/src/org/traccar/geocoder/GeocodeFarmGeocoder.java
index ca69a9026..585095606 100644
--- a/src/org/traccar/geocoder/GeocodeFarmReverseGeocoder.java
+++ b/src/org/traccar/geocoder/GeocodeFarmGeocoder.java
@@ -17,15 +17,15 @@ package org.traccar.geocoder;
import javax.json.JsonObject;
-public class GeocodeFarmReverseGeocoder extends JsonReverseGeocoder {
+public class GeocodeFarmGeocoder extends JsonGeocoder {
private static final String URL = "https://www.geocode.farm/v3/json/reverse/";
- public GeocodeFarmReverseGeocoder(int cacheSize) {
+ public GeocodeFarmGeocoder(int cacheSize) {
super(URL + "?lat=%f&lon=%f&country=us&lang=en&count=1", cacheSize);
}
- public GeocodeFarmReverseGeocoder(String key, int cacheSize) {
+ public GeocodeFarmGeocoder(String key, int cacheSize) {
super(URL + "?lat=%f&lon=%f&country=us&lang=en&count=1&key=" + key, cacheSize);
}
diff --git a/src/org/traccar/geocoder/ReverseGeocoder.java b/src/org/traccar/geocoder/Geocoder.java
index 2f6d6d82b..3ce3fb67f 100644
--- a/src/org/traccar/geocoder/ReverseGeocoder.java
+++ b/src/org/traccar/geocoder/Geocoder.java
@@ -15,7 +15,7 @@
*/
package org.traccar.geocoder;
-public interface ReverseGeocoder {
+public interface Geocoder {
interface ReverseGeocoderCallback {
diff --git a/src/org/traccar/geocoder/GeocoderException.java b/src/org/traccar/geocoder/GeocoderException.java
new file mode 100644
index 000000000..608916641
--- /dev/null
+++ b/src/org/traccar/geocoder/GeocoderException.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2016 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.traccar.geocoder;
+
+public class GeocoderException extends RuntimeException {
+
+ public GeocoderException(String message) {
+ super(message);
+ }
+
+}
diff --git a/src/org/traccar/geocoder/GisgraphyReverseGeocoder.java b/src/org/traccar/geocoder/GisgraphyGeocoder.java
index b656120d9..1432166e9 100644
--- a/src/org/traccar/geocoder/GisgraphyReverseGeocoder.java
+++ b/src/org/traccar/geocoder/GisgraphyGeocoder.java
@@ -17,13 +17,13 @@ package org.traccar.geocoder;
import javax.json.JsonObject;
-public class GisgraphyReverseGeocoder extends JsonReverseGeocoder {
+public class GisgraphyGeocoder extends JsonGeocoder {
- public GisgraphyReverseGeocoder() {
+ public GisgraphyGeocoder() {
this("http://services.gisgraphy.com/reversegeocoding/search", 0);
}
- public GisgraphyReverseGeocoder(String url, int cacheSize) {
+ public GisgraphyGeocoder(String url, int cacheSize) {
super(url + "?format=json&lat=%f&lng=%f&from=1&to=1", cacheSize);
}
diff --git a/src/org/traccar/geocoder/GoogleReverseGeocoder.java b/src/org/traccar/geocoder/GoogleGeocoder.java
index f644079d3..0506e701a 100644
--- a/src/org/traccar/geocoder/GoogleReverseGeocoder.java
+++ b/src/org/traccar/geocoder/GoogleGeocoder.java
@@ -19,17 +19,17 @@ import javax.json.JsonArray;
import javax.json.JsonObject;
import javax.json.JsonString;
-public class GoogleReverseGeocoder extends JsonReverseGeocoder {
+public class GoogleGeocoder extends JsonGeocoder {
- public GoogleReverseGeocoder() {
+ public GoogleGeocoder() {
this(0);
}
- public GoogleReverseGeocoder(int cacheSize) {
+ public GoogleGeocoder(int cacheSize) {
super("http://maps.googleapis.com/maps/api/geocode/json?latlng=%f,%f", cacheSize);
}
- public GoogleReverseGeocoder(String key, int cacheSize) {
+ public GoogleGeocoder(String key, int cacheSize) {
super("https://maps.googleapis.com/maps/api/geocode/json?latlng=%f,%f&key=" + key, cacheSize);
}
diff --git a/src/org/traccar/geocoder/JsonReverseGeocoder.java b/src/org/traccar/geocoder/JsonGeocoder.java
index 808b7c83f..6d1380729 100644
--- a/src/org/traccar/geocoder/JsonReverseGeocoder.java
+++ b/src/org/traccar/geocoder/JsonGeocoder.java
@@ -27,13 +27,13 @@ import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
-public abstract class JsonReverseGeocoder implements ReverseGeocoder {
+public abstract class JsonGeocoder implements Geocoder {
private final String url;
private Map<Map.Entry<Double, Double>, String> cache;
- public JsonReverseGeocoder(String url, final int cacheSize) {
+ public JsonGeocoder(String url, final int cacheSize) {
this.url = url;
if (cacheSize > 0) {
this.cache = Collections.synchronizedMap(new LinkedHashMap<Map.Entry<Double, Double>, String>() {
@@ -71,7 +71,7 @@ public abstract class JsonReverseGeocoder implements ReverseGeocoder {
}
callback.onSuccess(formattedAddress);
} else {
- callback.onFailure(new IllegalArgumentException("Empty address"));
+ callback.onFailure(new GeocoderException("Empty address"));
}
}
return null;
diff --git a/src/org/traccar/geocoder/MapQuestReverseGeocoder.java b/src/org/traccar/geocoder/MapQuestGeocoder.java
index 9c0a0e891..7d7217e91 100644
--- a/src/org/traccar/geocoder/MapQuestReverseGeocoder.java
+++ b/src/org/traccar/geocoder/MapQuestGeocoder.java
@@ -18,9 +18,9 @@ package org.traccar.geocoder;
import javax.json.JsonArray;
import javax.json.JsonObject;
-public class MapQuestReverseGeocoder extends JsonReverseGeocoder {
+public class MapQuestGeocoder extends JsonGeocoder {
- public MapQuestReverseGeocoder(String url, String key, int cacheSize) {
+ public MapQuestGeocoder(String url, String key, int cacheSize) {
super(url + "?key=" + key + "&location=%f,%f", cacheSize);
}
diff --git a/src/org/traccar/geocoder/NominatimReverseGeocoder.java b/src/org/traccar/geocoder/NominatimGeocoder.java
index faeaf247f..b0ee39c6a 100644
--- a/src/org/traccar/geocoder/NominatimReverseGeocoder.java
+++ b/src/org/traccar/geocoder/NominatimGeocoder.java
@@ -17,17 +17,17 @@ package org.traccar.geocoder;
import javax.json.JsonObject;
-public class NominatimReverseGeocoder extends JsonReverseGeocoder {
+public class NominatimGeocoder extends JsonGeocoder {
- public NominatimReverseGeocoder() {
+ public NominatimGeocoder() {
this("http://nominatim.openstreetmap.org/reverse", 0);
}
- public NominatimReverseGeocoder(String url, int cacheSize) {
+ public NominatimGeocoder(String url, int cacheSize) {
super(url + "?format=json&lat=%f&lon=%f&zoom=18&addressdetails=1", cacheSize);
}
- public NominatimReverseGeocoder(String url, String key, int cacheSize) {
+ public NominatimGeocoder(String url, String key, int cacheSize) {
super(url + "?format=json&lat=%f&lon=%f&zoom=18&addressdetails=1&key=" + key, cacheSize);
}
diff --git a/src/org/traccar/geocoder/OpenCageReverseGeocoder.java b/src/org/traccar/geocoder/OpenCageGeocoder.java
index a913a9288..9fa56a4a3 100644
--- a/src/org/traccar/geocoder/OpenCageReverseGeocoder.java
+++ b/src/org/traccar/geocoder/OpenCageGeocoder.java
@@ -19,9 +19,9 @@ package org.traccar.geocoder;
import javax.json.JsonArray;
import javax.json.JsonObject;
-public class OpenCageReverseGeocoder extends JsonReverseGeocoder {
+public class OpenCageGeocoder extends JsonGeocoder {
- public OpenCageReverseGeocoder(String url, String key, int cacheSize) {
+ public OpenCageGeocoder(String url, String key, int cacheSize) {
super(url + "/json?q=%f,%f&key=" + key, cacheSize);
}
diff --git a/src/org/traccar/geolocation/GeolocationException.java b/src/org/traccar/geolocation/GeolocationException.java
new file mode 100644
index 000000000..5847cc807
--- /dev/null
+++ b/src/org/traccar/geolocation/GeolocationException.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2016 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.traccar.geolocation;
+
+public class GeolocationException extends RuntimeException {
+
+ public GeolocationException(String message) {
+ super(message);
+ }
+
+}
diff --git a/src/org/traccar/geolocation/OpenCellIdGeolocationProvider.java b/src/org/traccar/geolocation/OpenCellIdGeolocationProvider.java
index 7d129e3e9..d6e45b550 100644
--- a/src/org/traccar/geolocation/OpenCellIdGeolocationProvider.java
+++ b/src/org/traccar/geolocation/OpenCellIdGeolocationProvider.java
@@ -55,7 +55,7 @@ public class OpenCellIdGeolocationProvider implements GeolocationProvider {
json.getJsonNumber("lat").doubleValue(),
json.getJsonNumber("lon").doubleValue(), 0);
} else {
- callback.onFailure(new IllegalArgumentException("Coordinates are missing"));
+ callback.onFailure(new GeolocationException("Coordinates are missing"));
}
}
return null;
@@ -68,7 +68,7 @@ public class OpenCellIdGeolocationProvider implements GeolocationProvider {
});
} else {
- callback.onFailure(new IllegalArgumentException("No network information"));
+ callback.onFailure(new GeolocationException("No network information"));
}
}
diff --git a/src/org/traccar/geolocation/UniversalGeolocationProvider.java b/src/org/traccar/geolocation/UniversalGeolocationProvider.java
index 320d0774b..48152f7df 100644
--- a/src/org/traccar/geolocation/UniversalGeolocationProvider.java
+++ b/src/org/traccar/geolocation/UniversalGeolocationProvider.java
@@ -43,7 +43,8 @@ public class UniversalGeolocationProvider implements GeolocationProvider {
try (JsonReader reader = Json.createReader(response.getResponseBodyAsStream())) {
JsonObject json = reader.readObject();
if (json.containsKey("error")) {
- callback.onFailure(new RuntimeException(json.getJsonObject("error").getString("message")));
+ callback.onFailure(
+ new GeolocationException(json.getJsonObject("error").getString("message")));
} else {
JsonObject location = json.getJsonObject("location");
callback.onSuccess(
diff --git a/test/org/traccar/geocoder/ReverseGeocoderTest.java b/test/org/traccar/geocoder/GeocoderTest.java
index 73753c96c..012f8bacd 100644
--- a/test/org/traccar/geocoder/ReverseGeocoderTest.java
+++ b/test/org/traccar/geocoder/GeocoderTest.java
@@ -3,7 +3,7 @@ package org.traccar.geocoder;
import org.junit.Assert;
import org.junit.Test;
-public class ReverseGeocoderTest {
+public class GeocoderTest {
private boolean enable = false;
@@ -31,9 +31,9 @@ public class ReverseGeocoderTest {
}
public void testGoogle() throws InterruptedException {
- ReverseGeocoder reverseGeocoder = new GoogleReverseGeocoder();
+ Geocoder geocoder = new GoogleGeocoder();
- reverseGeocoder.getAddress(new AddressFormat(), 37.4217550, -122.0846330, new ReverseGeocoder.ReverseGeocoderCallback() {
+ geocoder.getAddress(new AddressFormat(), 37.4217550, -122.0846330, new Geocoder.ReverseGeocoderCallback() {
@Override
public void onSuccess(String address) {
setAddress(address);
@@ -47,9 +47,9 @@ public class ReverseGeocoderTest {
}
public void testNominatim() throws InterruptedException {
- ReverseGeocoder reverseGeocoder = new NominatimReverseGeocoder();
+ Geocoder geocoder = new NominatimGeocoder();
- reverseGeocoder.getAddress(new AddressFormat(), 40.7337807, -73.9974401, new ReverseGeocoder.ReverseGeocoderCallback() {
+ geocoder.getAddress(new AddressFormat(), 40.7337807, -73.9974401, new Geocoder.ReverseGeocoderCallback() {
@Override
public void onSuccess(String address) {
setAddress(address);
@@ -63,9 +63,9 @@ public class ReverseGeocoderTest {
}
public void testGisgraphy() throws InterruptedException {
- ReverseGeocoder reverseGeocoder = new GisgraphyReverseGeocoder();
+ Geocoder geocoder = new GisgraphyGeocoder();
- reverseGeocoder.getAddress(new AddressFormat(), 48.8530000, 2.3400000, new ReverseGeocoder.ReverseGeocoderCallback() {
+ geocoder.getAddress(new AddressFormat(), 48.8530000, 2.3400000, new Geocoder.ReverseGeocoderCallback() {
@Override
public void onSuccess(String address) {
setAddress(address);
@@ -79,10 +79,10 @@ public class ReverseGeocoderTest {
}
public void testOpenCage() throws InterruptedException {
- ReverseGeocoder reverseGeocoder = new OpenCageReverseGeocoder(
+ Geocoder geocoder = new OpenCageGeocoder(
"http://api.opencagedata.com/geocode/v1", "SECRET", 0);
- reverseGeocoder.getAddress(new AddressFormat(), 34.116302, -118.051519, new ReverseGeocoder.ReverseGeocoderCallback() {
+ geocoder.getAddress(new AddressFormat(), 34.116302, -118.051519, new Geocoder.ReverseGeocoderCallback() {
@Override
public void onSuccess(String address) {
setAddress(address);
@@ -96,9 +96,9 @@ public class ReverseGeocoderTest {
}
public void testGeocodeFarm() throws InterruptedException {
- ReverseGeocoder reverseGeocoder = new GeocodeFarmReverseGeocoder(0);
+ Geocoder geocoder = new GeocodeFarmGeocoder(0);
- reverseGeocoder.getAddress(new AddressFormat(), 34.116302, -118.051519, new ReverseGeocoder.ReverseGeocoderCallback() {
+ geocoder.getAddress(new AddressFormat(), 34.116302, -118.051519, new Geocoder.ReverseGeocoderCallback() {
@Override
public void onSuccess(String address) {
setAddress(address);