Repository navigation
Closed
Labels
Milestone
Description
In a fresh maven/Java project:
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>client-hc-test</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.graphhopper</groupId>
<artifactId>directions-api-client-hc</artifactId>
<version>5.0</version>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
</project>Main.java (change the key)
import com.graphhopper.api.GHMRequest;
import com.graphhopper.api.GraphHopperMatrixWeb;
import com.graphhopper.api.MatrixResponse;
import com.graphhopper.util.shapes.GHPoint;
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
GraphHopperMatrixWeb matrixClient = new GraphHopperMatrixWeb();
matrixClient.setKey("your_key");
GHMRequest ghmRequest = new GHMRequest();
ghmRequest.addFromPoint(new GHPoint(49.6724, 11.3494));
for (GHPoint to : Arrays.asList(new GHPoint(49.6724, 11.3494), new GHPoint(49.6550, 11.4180))) {
ghmRequest.addToPoint(to);
}
MatrixResponse response = matrixClient.route(ghmRequest);
if (response.hasErrors())
throw new RuntimeException(response.getErrors().toString());
System.out.println("it's over... but apparently it's not...");
}
}mvn compile
mvn exec:java -Dexec.mainClass="Main"-> prints "it's over... but apparently it's not...", but then the process never returns.
Pausing the program with a debugger showed that it hangs in SocketInputStream#socketRead0.
I tried this with Java 8, 11 and 17.
The GHMRequest API is quite confusing: setProfile does not set the profile. This does nothing:
GHMRequest ghmRequest = new GHMRequest();
ghmRequest.setProfile("small_truck");
setPoints does not set the points. This does nothing either.
GHMRequest ghmRequest = new GHMRequest();
ghmRequest.setPoints(points);
It seems very strange that GHMRequest extends from GHRequest. This is probably the reason setProfile and setPoints do not work. Apparently we have to use addPoint,addAllPoint etc. instead.
Activity
karussell commentedon Apr 7, 2022
The /route endpoint has the same problem. But not for localhost. When switching to http1.1 it returns immediately:
So the hanging could be an http2 problem of okhttp or a server side problem where the http2 connection isn't closed (something like: the server thinks the connection is just idle (-> hence the timeout after 3m) and the client thinks it is already done).
update: I tried a simple rust program
and it did not hang although it should support http2 by default. Same with our JavaScript client. So it is more likely some okhttp problem.
The okhttp-only version is as follows and hangs:
karussell commentedon Apr 10, 2022
Upgrading to the latest 4.9.3 okhttp seems to fix this hanging problem (4.1.0 has the same problem, but >=4.2.0 is fine). (This 4.x version adds a kotlin lib as dependency)
Can you confirm this?
easbar commentedon Apr 17, 2022
I tried, but I get slightly different results: