Skip to content

Commit

Permalink
Fix geocoder issue (traccar#4073)
Browse files Browse the repository at this point in the history
  • Loading branch information
tananaev committed Oct 2, 2018
1 parent 4d6719f commit 5449930
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jetty.version>9.4.12.v20180830</jetty.version>
<jersey.version>2.26</jersey.version>
<jackson.version>2.8.4</jackson.version>
<jersey.version>2.27</jersey.version>
<jackson.version>2.8.10</jackson.version>
</properties>

<dependencies>
Expand Down
20 changes: 12 additions & 8 deletions src/org/traccar/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
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;
Expand Down Expand Up @@ -90,6 +88,7 @@

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.ext.ContextResolver;

public final class Context {

Expand Down Expand Up @@ -315,6 +314,15 @@ public static TripsConfig initTripsConfig() {
config.getDouble("event.motion.speedThreshold", 0.01));
}

private static class ObjectMapperContextResolver implements ContextResolver<ObjectMapper> {

@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");
Expand Down Expand Up @@ -372,9 +380,7 @@ public static void init(String configFile) throws Exception {
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")) {
Expand Down Expand Up @@ -504,9 +510,7 @@ public static void init(IdentityManager testIdentityManager) {
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;
}

Expand Down
6 changes: 1 addition & 5 deletions test/org/traccar/FilterHandlerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@
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;
Expand Down
2 changes: 1 addition & 1 deletion test/org/traccar/geocoder/GeocoderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class GeocoderTest {
@Test
public void test() throws InterruptedException {
Locale.setDefault(Locale.US);
testGoogle();
testBan();
}

private String address;
Expand Down

0 comments on commit 5449930

Please sign in to comment.