2 |
|
|
3 |
import java.util.Collection; |
import java.util.Collection; |
4 |
import java.util.logging.Level; |
import java.util.logging.Level; |
|
import java.util.logging.Logger; |
|
5 |
|
|
6 |
import com.google.gson.Gson; |
import com.google.gson.Gson; |
7 |
|
|
8 |
|
import dk.daoas.adressevedligehold.ServiceConfig; |
9 |
import dk.daoas.adressevedligehold.beans.Address; |
import dk.daoas.adressevedligehold.beans.Address; |
10 |
|
import dk.daoas.adressevedligehold.tasks.TaskLogger; |
11 |
import dk.daoas.adressevedligehold.util.HttpUtil; |
import dk.daoas.adressevedligehold.util.HttpUtil; |
12 |
|
|
13 |
|
|
14 |
public class OSRMHelper { |
public class OSRMHelper { |
15 |
|
|
16 |
|
|
17 |
final static Logger logger = Logger.getLogger( OSRMHelper.class.toString() ); |
private TaskLogger logger = TaskLogger.getInstance(); |
18 |
|
|
19 |
|
|
20 |
Gson gson = new Gson(); |
Gson gson = new Gson(); |
21 |
|
|
22 |
//static OSRMBinding binding = null; |
final static int PORT = 5000; |
23 |
|
final String base_url = "http://" + ServiceConfig.getInstance().osrmHost + ":" + PORT; |
24 |
|
|
|
final String host = "127.0.0.1"; |
|
|
//final String host = "10.30.2.103"; |
|
|
final int port = 5000; |
|
|
final String base_url = "http://" + host + ":" + port; |
|
|
|
|
|
|
|
|
public Address getNearestTableHttp(Address a1, Collection<Address> haystack) { |
|
25 |
|
|
26 |
|
public Address getNearestTableHttp(Address a1, Collection<Address> haystack) throws Exception { |
27 |
|
|
28 |
|
|
29 |
Address bedsteAddress = null; |
Address bedsteAddress = null; |
42 |
|
|
43 |
try { |
try { |
44 |
|
|
45 |
String txtResponse = HttpUtil.getContentString(sb.toString(), 500, "UTF-8"); |
String txtResponse = HttpUtil.getContentString(sb.toString(), 750, "UTF-8"); |
46 |
|
|
47 |
OSRMDistanceTable table = gson.fromJson(txtResponse, OSRMDistanceTable.class); |
OSRMDistanceTable table = gson.fromJson(txtResponse, OSRMDistanceTable.class); |
48 |
|
|
62 |
System.out.println(txtResponse); |
System.out.println(txtResponse); |
63 |
|
|
64 |
|
|
65 |
System.exit(0); |
throw new Exception("Wrong number of results in matrix"); |
66 |
} |
} |
67 |
|
|
68 |
int bedsteTid = Integer.MAX_VALUE; |
int bedsteTid = Integer.MAX_VALUE; |
79 |
logger.log(Level.SEVERE, "Lookup failed", e); |
logger.log(Level.SEVERE, "Lookup failed", e); |
80 |
System.out.println( sb.toString() ); |
System.out.println( sb.toString() ); |
81 |
System.out.println( a1 ); |
System.out.println( a1 ); |
82 |
System.exit(1); |
throw e; //Re-throw |
83 |
} |
} |
84 |
|
|
85 |
//return gson.fromJson(txtResponse, OSRMResponse.class); |
//return gson.fromJson(txtResponse, OSRMResponse.class); |