With Android, how do I set the maximum deadline for a Cloud Endpoint request?

六眼飞鱼酱① 提交于 2019-12-22 08:55:27

问题


When making a ClientEndpoint API request from an Android app to an App-Engine service, how do I set a deadline/timeout for the execute() action?

I'm looking for something like:

Foo foo = endpoint.getSomething(id) .setDeadline(2000/*ms*/) .execute();

回答1:


When building the endpoint, specify a connect and read timeout in HttpRequestInitializer. For example, in this case 20 and 10 secs respectively.

SomeEndpoint.Builder endpointBuilder = new SomeEndpoint.Builder(
    AndroidHttp.newCompatibleTransport(),
    new JacksonFactory(), new HttpRequestInitializer() {
        public void initialize(HttpRequest httpRequest) {
            httpRequest.setConnectTimeout(20 * 1000);
            httpRequest.setReadTimeout(10 * 1000);
        }
    });



回答2:


I am not sure if one can control that. Since the Endpoints are hosted in an App Engine environment, standard timeout for any App Engine HTTP Request should apply i.e. 60 seconds.




回答3:


It is possible. You just need to implement your own HttpRequestInitializer where you set connect and read timeouts in its initialize method. This HttpRequestInitializer need to be passed then as a parameter to your endpoint builder constructor.



来源:https://stackoverflow.com/questions/20391173/with-android-how-do-i-set-the-maximum-deadline-for-a-cloud-endpoint-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!