With Android, how do I set a maximum time limit for a Cloud Endpoint request?

When you make an API request ClientEndpointfrom an Android application to an App Engine service, how do I set a deadline / timeout for an action execute()?

I am looking for something like:

Foo foo = endpoint.getSomething(id) .setDeadline(2000/*ms*/) .execute();
+4
source share
3 answers

When building the endpoint, specify the connection and read timeouts in the HttpRequestInitializer. For example, in this case, 20 and 10 seconds, 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);
        }
    });
+8
source

, . App Engine, - HTTP- App Engine , , 60 .

0

It is possible. You just need to implement your own HttpRequestInitializer, where you set the connection and read timeouts to your initialization method. This HttpRequestInitializer must then be passed as a parameter to the constructor of the endpoint builder.

0
source

All Articles