Localhost request URL works using curl but not using java client

For testing, i run a local GraphhopperWeb instance and issue routing requests to it, using graphhopper-core and graphhopper-api-client-hc, both at version 0.11.0).

This is where it is used in the java client:

GraphHopperWeb ghw = new GraphHopperWeb("localhost:8989/route");
    ghw.setDownloader(new OkHttpClient.Builder().
                    connectTimeout(5, TimeUnit.SECONDS).
                    readTimeout(5, TimeUnit.SECONDS).build());
....
GHPoint from = new GHPoint(pickupLatitude, pickupLongitude);
GHPoint to = new GHPoint(dropoffLatitude, dropoffLongitude);
....
GHRequest req = new GHRequest(from, to).
    setVehicle("car").
    setLocale(locale).
    setAlgorithm(Parameters.Algorithms.DIJKSTRA_BI);
req.getHints().put("elevation", false);
req.getHints().put("calc_points", true);
req.getHints().put("instructions", true);
....
GHResponse rsp = ghw.route(req);

The java client fails at the GHResponse... line above, with the following message

Exception in thread "main" java.lang.RuntimeException: Problem while fetching path  [-33.693462,151.2748485, -33.697175,151.300789]: unexpected url: localhost:8989/route?point=-33.693462,151.274849&point=-33.697175,151.300789&&type=json&instructions=true&points_encoded=true&calc_points=true&algorithm=dijkstrabi&locale=en_GB&elevation=false&optimize=false&vehicle=car
at com.graphhopper.api.GraphHopperWeb.route(GraphHopperWeb.java:378)

If I issue a curl request with that url, it returns a plausible response without any complaint.

How can i get the request to work from the java client?

I would be grateful for any adviceā€¦

Can you try http://localhost:8989/route instead?

1 Like

Thanks - prepending http:// to the url has solved the problem, as you suggested.

I had misread a previous post in this forum.

Thanks for your prompt and helpful response to my query.

1 Like