IOException when sending more than ~100 blocked areas

Hi,
I’m trying to calculate routes using the block_area feature. When I send just a few locations with radius the locations are blocked and graphhopper routes around them, but when I give it more than about 100 locations in the block_area argument, it fails with following exception:

2020-07-07 11:51:40.501 27045-27149/… E/…: calculateRoute().doInBackground(): Exception caught after 0 seconds!
io.swagger.client.ApiException: java.io.IOException: stream was reset: CANCEL
at io.swagger.client.ApiClient.execute(ApiClient.java:843)
at io.swagger.client.api.RoutingApiApi.getRouteWithHttpInfo(RoutingApiApi.java:274)
at io.swagger.client.api.RoutingApiApi.getRoute(RoutingApiApi.java:235)
at de…Service$4.doInBackground(…Service.java:1235)
at …Service$4.doInBackground(…Service.java:1143)
at android.os.AsyncTask$2.call(AsyncTask.java:333)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
Caused by: java.io.IOException: stream was reset: CANCEL
at com.squareup.okhttp.internal.framed.FramedStream.getResponseHeaders(FramedStream.java:146)
at com.squareup.okhttp.internal.http.Http2xStream.readResponseHeaders(Http2xStream.java:150)
at com.squareup.okhttp.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:737)
at com.squareup.okhttp.internal.http.HttpEngine.access$200(HttpEngine.java:87)
at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:722)
at com.squareup.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:576)
at com.squareup.okhttp.Call.getResponse(Call.java:287)
at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:243)
at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:205)
at com.squareup.okhttp.Call.execute(Call.java:80)
at io.swagger.client.ApiClient.execute(ApiClient.java:839)
at io.swagger.client.api.RoutingApiApi.getRouteWithHttpInfo(RoutingApiApi.java:274)
at io.swagger.client.api.RoutingApiApi.getRoute(RoutingApiApi.java:235)
at …Service$4.doInBackground(…Service.java:1235)
at …Service$4.doInBackground(…Service.java:1143)
at android.os.AsyncTask$2.call(AsyncTask.java:333)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)

Now I have two questions:

  1. Why does it fail?
  2. I want to send several hundred blocked location with each request, how can I fix this issue?

Regards,
Samuel

In general it is not recommended to use so many blocked areas as performance could degrade and sometimes it is a sign that the data should better be in OpenStreetMap.

You should be able to retrieve the error message via parsing the error outputstream.

There could be two problems: the limitation of the block area string length and the limitation of the query string length. If you use a POST request you can avoid the latter: https://docs.graphhopper.com/#operation/postRoute

If you hit the block area string limitation, then you can only reduce the number of blocked areas or the precision of the submitted coordinates to reduce the length.

Thanks for the info.
I’m using the generated API classes and call RoutingApi.getRoute(...). There is no method called RoutingApi.postRoute(...), how can I use POST Route Endpoint using the generated API classes?

You can use the handcrafted client:

https://search.maven.org/artifact/com.graphhopper/directions-api-client-hc

Ok, but we recently made huge effort in replacing the handcrafted client with the generated API sources (as we need Geocoding). It’s very unfortunate that the POST Route Endpoint is mentioned in de Docs but not contained in the API!
One more question: what are the limitation of the block area string length and the limitation of the query string length?

You can always create Java sources from our current spec: https://docs.graphhopper.com/openapi.json that should also include the POST method. See the steps in more detail:
GitHub - graphhopper/directions-api-clients: API clients for various languages for the GraphHopper Directions API

We decided that this procedure should be done from our customers and they would embed the sources in their project directly instead of us publishing generated code to maven central. Only client-hc is pushed from us to maven central.

One more question: what are the limitation of the block area string length and the limitation of the query string length?

We do not expose those limits yet they have changed and there is now the alternative via a POST request for the URL length limitation. But they should be sufficient for the most use cases.

Ah I see, we used an outdated version of the generated sources. I newly created the Java sources and imported them to my project, but it won’t even build because of 14 errors in the sources:

...\io\swagger\client\model\AllOfMatrixRequestVehicle.java:23: error: cannot inherit from final VehicleProfileId
public class AllOfMatrixRequestVehicle extends VehicleProfileId {
                                               ^
...\io\swagger\client\model\AllOfRouteRequestVehicle.java:23: error: cannot inherit from final VehicleProfileId
public class AllOfRouteRequestVehicle extends VehicleProfileId {
                                              ^
...\io\swagger\client\model\AllOfSymmetricalMatrixRequestVehicle.java:23: error: cannot inherit from final VehicleProfileId
public class AllOfSymmetricalMatrixRequestVehicle extends VehicleProfileId {
                                                          ^
...\io\swagger\client\model\RouteRequest.java:144: error: incompatible types: double cannot be converted to BigDecimal
  private BigDecimal alternativeRouteMaxWeightFactor = 1.4;
                                                       ^
...\io\swagger\client\model\RouteRequest.java:147: error: incompatible types: double cannot be converted to BigDecimal
  private BigDecimal alternativeRouteMaxShareFactor = 0.6;
                                                      ^
...\io\swagger\client\model\AllOfMatrixRequestVehicle.java:23: error: enum types are not extensible
public class AllOfMatrixRequestVehicle extends VehicleProfileId {
       ^
...\io\swagger\client\model\AllOfMatrixRequestVehicle.java:26: error: equals(Object) in AllOfMatrixRequestVehicle cannot override equals(Object) in Enum
  public boolean equals(java.lang.Object o) {
                 ^
  overridden method is final
...\io\swagger\client\model\AllOfMatrixRequestVehicle.java:37: error: hashCode() in AllOfMatrixRequestVehicle cannot override hashCode() in Enum
  public int hashCode() {
             ^
  overridden method is final
...\io\swagger\client\model\AllOfRouteRequestVehicle.java:23: error: enum types are not extensible
public class AllOfRouteRequestVehicle extends VehicleProfileId {
       ^
...\io\swagger\client\model\AllOfRouteRequestVehicle.java:26: error: equals(Object) in AllOfRouteRequestVehicle cannot override equals(Object) in Enum
  public boolean equals(java.lang.Object o) {
                 ^
  overridden method is final
...\io\swagger\client\model\AllOfRouteRequestVehicle.java:37: error: hashCode() in AllOfRouteRequestVehicle cannot override hashCode() in Enum
  public int hashCode() {
             ^
  overridden method is final
...\io\swagger\client\model\AllOfSymmetricalMatrixRequestVehicle.java:23: error: enum types are not extensible
public class AllOfSymmetricalMatrixRequestVehicle extends VehicleProfileId {
       ^
...\io\swagger\client\model\AllOfSymmetricalMatrixRequestVehicle.java:26: error: equals(Object) in AllOfSymmetricalMatrixRequestVehicle cannot override equals(Object) in Enum
  public boolean equals(java.lang.Object o) {
                 ^
  overridden method is final
...\io\swagger\client\model\AllOfSymmetricalMatrixRequestVehicle.java:37: error: hashCode() in AllOfSymmetricalMatrixRequestVehicle cannot override hashCode() in Enum
  public int hashCode() {
             ^
  overridden method is final
14 errors

FAILURE: Build failed with an exception.

Am I now to fix those issues? Or is there a stable version of the spec?

The issues still remain. Do you have a solution for me?

Why not use the handcrafted Java client?

Ok, but we recently made huge effort in replacing the handcrafted client with the generated API sources (as we need Geocoding)

Why? Geocoding should be supported too: graphhopper/client-hc/src/main/java/com/graphhopper/api/GraphHopperGeocoding.java at master · graphhopper/graphhopper · GitHub

If you really want to keep using the client based on autogenerated Java sources you can also try this docker image described here: GitHub - graphhopper/directions-api-clients: API clients for various languages for the GraphHopper Directions API