26 |
|
|
27 |
public static void main(String[] args) throws IOException { |
public static void main(String[] args) throws IOException { |
28 |
ServiceConfig conf = new ServiceConfig(); |
ServiceConfig conf = new ServiceConfig(); |
29 |
|
conf.osmTimeout = 1000; |
30 |
|
|
31 |
int post = 8700; |
int post = 8700; |
32 |
String vej = "Enebarvej"; |
String vej = "Enebarvej"; |
36 |
long stop1 = System.currentTimeMillis(); |
long stop1 = System.currentTimeMillis(); |
37 |
|
|
38 |
long start2 = System.currentTimeMillis(); |
long start2 = System.currentTimeMillis(); |
39 |
System.out.println( "OSM:" + GeocodeHelper.openstreetmapHelper(post, vej) ); |
System.out.println( "OSM:" + GeocodeHelper.openstreetmapHelper(conf, post, vej) ); |
40 |
long stop2 = System.currentTimeMillis(); |
long stop2 = System.currentTimeMillis(); |
41 |
|
|
42 |
System.out.println("Google: " + (stop1-start1)); |
System.out.println("Google: " + (stop1-start1)); |
43 |
System.out.println("OSM: " + (stop2-start2)); |
System.out.println("OSM: " + (stop2-start2)); |
44 |
} |
} |
45 |
|
|
46 |
public static String openstreetmapHelper(int postnr, String vejnavn) { |
public static String openstreetmapHelper(ServiceConfig conf, int postnr, String vejnavn) { |
47 |
|
|
48 |
try { |
try { |
49 |
|
|
50 |
OSMInvocation wrapper = new OSMInvocation( postnr, vejnavn ); |
OSMInvocation wrapper = new OSMInvocation( conf, postnr, vejnavn ); |
51 |
CircuitBreaker breaker = CircuitBreakerManager.getManager().getCircuitBreaker("osm"); |
CircuitBreaker breaker = CircuitBreakerManager.getManager().getCircuitBreaker("osm"); |
52 |
|
|
53 |
return (String) breaker.invoke(wrapper); |
return (String) breaker.invoke(wrapper); |
78 |
public static class OSMInvocation implements CircuitInvocation { |
public static class OSMInvocation implements CircuitInvocation { |
79 |
int postnr; |
int postnr; |
80 |
String vejnavn; |
String vejnavn; |
81 |
|
ServiceConfig conf; |
82 |
|
|
83 |
public OSMInvocation(int postnr, String vejnavn) { |
public OSMInvocation(ServiceConfig conf, int postnr, String vejnavn) { |
84 |
|
this.conf = conf; |
85 |
this.postnr= postnr; |
this.postnr= postnr; |
86 |
this.vejnavn = vejnavn; |
this.vejnavn = vejnavn; |
87 |
} |
} |
95 |
//String url = "http://nominatim.openstreetmap.org/search?country=DK&street=" + encVej + "&format=json&addressdetails=1"; |
//String url = "http://nominatim.openstreetmap.org/search?country=DK&street=" + encVej + "&format=json&addressdetails=1"; |
96 |
//System.out.println (url); |
//System.out.println (url); |
97 |
|
|
98 |
String json = HttpUtil.getContentString(url, 1000); |
String json = HttpUtil.getContentString(url, conf.osmTimeout); |
99 |
//System.out.println(json); |
//System.out.println(json); |
100 |
|
|
101 |
Gson gson = new Gson(); |
Gson gson = new Gson(); |