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

a 夏天 提交于 2019-12-05 13:37:10
Rori Stumpf

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

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.

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.

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