File tree Expand file tree Collapse file tree 2 files changed +18
-10
lines changed
client-hc/src/main/java/com/graphhopper/api Expand file tree Collapse file tree 2 files changed +18
-10
lines changed Original file line number Diff line number Diff line change @@ -61,18 +61,24 @@ public OkHttpClient getDownloader() {
61
61
62
62
protected String getJson (String url ) throws IOException {
63
63
Request okRequest = new Request .Builder ().url (url ).build ();
64
- ResponseBody body = downloader .newCall (okRequest ).execute ().body ();
65
- String str = body .string ();
66
- body .close ();
67
- return str ;
64
+ ResponseBody body = null ;
65
+ try {
66
+ body = downloader .newCall (okRequest ).execute ().body ();
67
+ return body .string ();
68
+ } finally {
69
+ Helper .close (body );
70
+ }
68
71
}
69
72
70
73
protected String postJson (String url , JsonNode data ) throws IOException {
71
74
Request okRequest = new Request .Builder ().url (url ).post (RequestBody .create (MT_JSON , data .toString ())).build ();
72
- ResponseBody body = downloader .newCall (okRequest ).execute ().body ();
73
- String str = body .string ();
74
- body .close ();
75
- return str ;
75
+ ResponseBody body = null ;
76
+ try {
77
+ body = downloader .newCall (okRequest ).execute ().body ();
78
+ return body .string ();
79
+ } finally {
80
+ Helper .close (body );
81
+ }
76
82
}
77
83
78
84
protected JsonNode toJSON (String url , String str ) {
Original file line number Diff line number Diff line change @@ -351,11 +351,11 @@ public GraphHopperWeb setOptimize(String optimize) {
351
351
352
352
@ Override
353
353
public GHResponse route (GHRequest request ) {
354
+ ResponseBody rspBody = null ;
354
355
try {
355
356
Request okRequest = createRequest (request );
356
- ResponseBody rspBody = getClientForRequest (request ).newCall (okRequest ).execute ().body ();
357
+ rspBody = getClientForRequest (request ).newCall (okRequest ).execute ().body ();
357
358
JsonNode json = objectMapper .reader ().readTree (rspBody .byteStream ());
358
- rspBody .close ();
359
359
360
360
GHResponse res = new GHResponse ();
361
361
res .addErrors (readErrors (json ));
@@ -376,6 +376,8 @@ public GHResponse route(GHRequest request) {
376
376
377
377
} catch (Exception ex ) {
378
378
throw new RuntimeException ("Problem while fetching path " + request .getPoints () + ": " + ex .getMessage (), ex );
379
+ } finally {
380
+ Helper .close (rspBody );
379
381
}
380
382
}
381
383
You can’t perform that action at this time.
0 commit comments