|
1 | 1 | package com.osrm.client; |
2 | 2 |
|
| 3 | +import java.io.UnsupportedEncodingException; |
| 4 | +import java.net.URLEncoder; |
| 5 | +import java.nio.charset.StandardCharsets; |
3 | 6 | import java.util.ArrayList; |
4 | 7 | import java.util.List; |
5 | 8 | import java.util.concurrent.TimeUnit; |
@@ -46,10 +49,7 @@ public OSRMDistanceResponse getDistanceMatrix(List<GeoLocation> locations, doubl |
46 | 49 |
|
47 | 50 | paramsString += "&speedRate=" + speedRate; |
48 | 51 | paramsString += "&country=" + country; |
49 | | - |
50 | | - if (startTime != null && !startTime.isEmpty()) { |
51 | | - paramsString += "&start_time=" + startTime; |
52 | | - } |
| 52 | + paramsString += encodeStartTime(startTime); |
53 | 53 |
|
54 | 54 | RequestBody body = RequestBody.create(mediaType, "loc=" + paramsString); |
55 | 55 |
|
@@ -79,6 +79,20 @@ public OSRMDistanceResponse getDistanceMatrix(List<GeoLocation> locations, doubl |
79 | 79 | throw new DistanceMatrixResponseException("OSRM Error: " + response); |
80 | 80 | } |
81 | 81 |
|
| 82 | + private String encodeStartTime(String startTime) { |
| 83 | + String paramsString = ""; |
| 84 | + if (startTime == null || startTime.isEmpty()) { |
| 85 | + return paramsString; |
| 86 | + } |
| 87 | + try { |
| 88 | + String encodedStartTime = URLEncoder.encode(startTime, StandardCharsets.UTF_8.toString()); |
| 89 | + paramsString += "&start_time=" + encodedStartTime; |
| 90 | + } catch (Exception e){ |
| 91 | + throw new OptimizationDistanceMatrixException("Error while encoding startTime parameter"); |
| 92 | + } |
| 93 | + return paramsString; |
| 94 | + } |
| 95 | + |
82 | 96 | private UnsuccessfulResponse getUnsuccessfulResponse(Response response){ |
83 | 97 | try { |
84 | 98 | if (response.body() != null) { |
|
0 commit comments