1
votes

In my application I must use a routing web service and I use OSRM Server API

https://github.com/Project-OSRM/osrm-backend/wiki/Server-api

I don't know why but until yesterday morming the Server-api works. Now it doesn't work and It gives me a bad request

http://router.project-osrm.org/viaroute?loc="+p.getLat()+","+p.getLon()+"&loc="+d.getLat()+","+d.getLon(); I use java and REST protocol

String sito="http://router.project-osrm.org/viaroute?loc="+p.getLat()+","+p.getLon()+"&loc="+d.getLat()+","+d.getLon()";
       Client client = ClientBuilder.newClient();

                WebTarget target = client.target(sito);


                Response res = target.request().get();


               System.out.println(res.readEntity(String.class));

I Obtain the "BAD GATEWAY"

1
What language are you using? Could you post an example of the code you're using? - GoBusto
@GoBusto I have edit the post - prova
Yes it looks definitely like Java. I added the corresponding tag. - scai
@prova The service works fine, see for example router.project-osrm.org/… (on the map). You have to tell us more about your problem. - scai
yes I think the problem is the library for REST call or something like that.I don't understand how it is possible that it worked from September to yesterday and now It's not work and give me "502 Bad Gateway" - prova

1 Answers

0
votes

Looking in firebug in the link provided by @scai, you can see the Content-Encoding == gzip. You should set the Accept-Encoding header. You can do that with the convenience chain method acceptEncoding, on the InvocationBuilder. So do something like

    WebTarget target = client.target(uri);
    String response = target.request()
            .accept("application/json")
            .acceptEncoding("gzip")
            .get(String.class);

Not sure the JAX-RS client library you're using, but the stadard Client API doesn't come with any filters/interceptors to decode the gzip, but if you're using Jersey client, then you can register the GZipEncoder with the client.

client.register(org.glassfish.jersey.message.GZipEncoder.class);

Tested and this works fine for me. Had the same problem as you before making the above changes.

If you're not working with Jersey, I'm sure what ever implementation you are using should have some GZIP filter. I know Resteasy does. If your implementation doesn't have one, you can always use Java's GZIPInputStream to wrap the response stream

Response response = target.request()
        .accept("application/json")
        .acceptEncoding("gzip")
        .get();

GZIPInputStream is = new GZIPInputStream(
                          response.readEntity(InputStream.class));