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"
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));