简体   繁体   English

Web服务不再起作用

[英]the web service does not work anymore

In my application I must use a routing web service and I use OSRM Server API 在我的应用程序中,我必须使用路由Web服务,并且必须使用OSRM Server API

https://github.com/Project-OSRM/osrm-backend/wiki/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. 我不知道为什么,但是直到昨天早上才对Server-api起作用。 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 http://router.project-osrm.org/viaroute?loc= “ + p.getLat()+”,“ + p.getLon()+”&loc =“ + d.getLat()+”,“ + d .getLon();我使用Java和REST协议

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 . 在@scai提供的链接中查看firebug,您可以看到Content-Encoding == gzip You should set the Accept-Encoding header. 您应该设置Accept-Encoding标头。 You can do that with the convenience chain method acceptEncoding , on the InvocationBuilder . 您可以使用InvocationBuilder上的便捷链方法acceptEncoding来实现。 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. 不确定您使用的JAX-RS客户端库,但stadard客户端API并未附带任何用于过滤gzip的过滤器/拦截器,但是如果您使用的是Jersey客户端,则可以向客户端注册GZipEncoder

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. 如果您不使用Jersey,我确定您所使用的任何实现都应具有一些GZIP过滤器。 I know Resteasy does. 我知道Resteasy会的。 If your implementation doesn't have one, you can always use Java's GZIPInputStream to wrap the response stream 如果您的实现没有实现,则始终可以使用Java的GZIPInputStream包装响应流

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM