--- dao/DaoAdresseService/src/dk/daoas/daoadresseservice/GeocodeHelper.java 2015/02/24 11:19:40 2360 +++ dao/DaoAdresseService/src/dk/daoas/daoadresseservice/GeocodeHelper.java 2015/02/24 13:00:46 2368 @@ -26,6 +26,7 @@ public static void main(String[] args) throws IOException { ServiceConfig conf = new ServiceConfig(); + conf.osmTimeout = 1000; int post = 8700; String vej = "Enebarvej"; @@ -35,18 +36,18 @@ long stop1 = System.currentTimeMillis(); long start2 = System.currentTimeMillis(); - System.out.println( "OSM:" + GeocodeHelper.openstreetmapHelper(post, vej) ); + System.out.println( "OSM:" + GeocodeHelper.openstreetmapHelper(conf, post, vej) ); long stop2 = System.currentTimeMillis(); System.out.println("Google: " + (stop1-start1)); System.out.println("OSM: " + (stop2-start2)); } - public static String openstreetmapHelper(int postnr, String vejnavn) { + public static String openstreetmapHelper(ServiceConfig conf, int postnr, String vejnavn) { try { - OSMInvocation wrapper = new OSMInvocation( postnr, vejnavn ); + OSMInvocation wrapper = new OSMInvocation( conf, postnr, vejnavn ); CircuitBreaker breaker = CircuitBreakerManager.getManager().getCircuitBreaker("osm"); return (String) breaker.invoke(wrapper); @@ -77,26 +78,33 @@ public static class OSMInvocation implements CircuitInvocation { int postnr; String vejnavn; + ServiceConfig conf; - public OSMInvocation(int postnr, String vejnavn) { + public OSMInvocation(ServiceConfig conf, int postnr, String vejnavn) { + this.conf = conf; this.postnr= postnr; this.vejnavn = vejnavn; } @Override public String proceed() throws Exception { + //TimingHelper timer = new TimingHelper(); String encVej = URLEncoder.encode(vejnavn, "UTF-8"); - String url = "http://nominatim.openstreetmap.org/search?country=DK&street=" + encVej + "&postalcode=" + postnr + "&format=json&addressdetails=1"; + + String url = conf.nominatimBase + "/search?country=DK&street=" + encVej + "&postalcode=" + postnr + "&format=json&addressdetails=1"; + //String url = "http://nominatim.openstreetmap.org/search?country=DK&street=" + encVej + "&format=json&addressdetails=1"; //System.out.println (url); - String json = HttpUtil.getContentString(url, 1000); + String json = HttpUtil.getContentString(url, conf.osmTimeout); //System.out.println(json); Gson gson = new Gson(); OSMAddress adrList[] = gson.fromJson(json, OSMAddress[].class); + //timer.printElapsed("OSM elapsed"); + //System.out.println("Count: " + adrList.length); if (adrList.length != 1) return null; @@ -131,12 +139,13 @@ } else { geocoder = new Geocoder(); } - + //TimingHelper timer = new TimingHelper(); String search = vejnavn + ", " + postnr + ", Denmark"; GeocoderRequest geocoderRequest = new GeocoderRequestBuilder().setAddress(search).setLanguage("en").getGeocoderRequest(); GeocodeResponse geocoderResponse = geocoder.geocode(geocoderRequest); + //timer.printElapsed("Google elapsed"); //System.out.println( "Status: >" + geocoderResponse.getStatus() + "<"); if ( geocoderResponse.getStatus() != GeocoderStatus.OK) {