From 5449930102d9a1dc6ef6bb09f6bcbdcb2f8bf150 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 3 Oct 2018 12:09:10 +1300 Subject: Fix geocoder issue (#4073) --- pom.xml | 4 ++-- src/org/traccar/Context.java | 20 ++++++++++++-------- test/org/traccar/FilterHandlerTest.java | 6 +----- test/org/traccar/geocoder/GeocoderTest.java | 2 +- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/pom.xml b/pom.xml index a7203f8c6..a14389b3d 100644 --- a/pom.xml +++ b/pom.xml @@ -12,8 +12,8 @@ UTF-8 9.4.12.v20180830 - 2.26 - 2.8.4 + 2.27 + 2.8.10 diff --git a/src/org/traccar/Context.java b/src/org/traccar/Context.java index ca2091148..d652c7cbd 100644 --- a/src/org/traccar/Context.java +++ b/src/org/traccar/Context.java @@ -25,8 +25,6 @@ import java.time.format.DateTimeFormatter; import java.util.Properties; import com.fasterxml.jackson.datatype.jsr353.JSR353Module; -import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider; -import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider; import org.apache.velocity.app.VelocityEngine; import org.eclipse.jetty.util.URIUtil; import org.slf4j.Logger; @@ -90,6 +88,7 @@ import org.traccar.web.WebServer; import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.ext.ContextResolver; public final class Context { @@ -315,6 +314,15 @@ public final class Context { config.getDouble("event.motion.speedThreshold", 0.01)); } + private static class ObjectMapperContextResolver implements ContextResolver { + + @Override + public ObjectMapper getContext(Class clazz) { + return objectMapper; + } + + } + public static Geocoder initGeocoder() { String type = config.getString("geocoder.type", "google"); String url = config.getString("geocoder.url"); @@ -372,9 +380,7 @@ public final class Context { objectMapper.enable(SerializationFeature.INDENT_OUTPUT); } - JacksonJsonProvider jsonProvider = - new JacksonJaxbJsonProvider(objectMapper, JacksonJaxbJsonProvider.DEFAULT_ANNOTATIONS); - client = ClientBuilder.newClient().register(jsonProvider); + client = ClientBuilder.newClient().register(new ObjectMapperContextResolver()); if (config.hasKey("database.url")) { @@ -504,9 +510,7 @@ public final class Context { config = new Config(); objectMapper = new ObjectMapper(); objectMapper.registerModule(new JSR353Module()); - JacksonJsonProvider jsonProvider = - new JacksonJaxbJsonProvider(objectMapper, JacksonJaxbJsonProvider.DEFAULT_ANNOTATIONS); - client = ClientBuilder.newClient().register(jsonProvider); + client = ClientBuilder.newClient().register(new ObjectMapperContextResolver()); identityManager = testIdentityManager; } diff --git a/test/org/traccar/FilterHandlerTest.java b/test/org/traccar/FilterHandlerTest.java index a8fa14fac..818583eb7 100644 --- a/test/org/traccar/FilterHandlerTest.java +++ b/test/org/traccar/FilterHandlerTest.java @@ -10,11 +10,7 @@ import java.util.Date; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -public class FilterHandlerTest { - - static { - Context.init(new TestIdentityManager()); - } +public class FilterHandlerTest extends BaseTest { private FilterHandler filtingHandler; private FilterHandler passingHandler; diff --git a/test/org/traccar/geocoder/GeocoderTest.java b/test/org/traccar/geocoder/GeocoderTest.java index 7b3c6662c..167b71bc2 100644 --- a/test/org/traccar/geocoder/GeocoderTest.java +++ b/test/org/traccar/geocoder/GeocoderTest.java @@ -13,7 +13,7 @@ public class GeocoderTest { @Test public void test() throws InterruptedException { Locale.setDefault(Locale.US); - testGoogle(); + testBan(); } private String address; -- cgit v1.2.3