Change READ TIMEOUT for HTTP batch request when using Google APIs Client Library for Java

I make batch requests to add members to groups. To do this, I use OAuth2.0 and get an object of type Class Credential. When it is executed, batch.execute () throws

java.net.SocketTimeoutException : Read timed out

To change the timeout limit, this is the solution I found: GoogleApps client providing only SocketTimeOutException

But I cannot change the timeout of the Credential object that I create.

Credential credential = new AuthorizationCodeInstalledApp(
                flow, new LocalServerReceiver()).authorize("user");

NOTE. Credentials implement the HttpRequestInitializer.

Thanks in advance!

+4
source share
1 answer

! HttpRequestInitializer HTTP HTTP- Google. HttpRequestInitializer (, ), :

new Directory.Builder(
                HTTP_TRANSPORT, JSON_FACTORY,new HttpRequestInitializer() {
            @Override
            public void initialize(HttpRequest httpRequest) throws IOException {
                credential.initialize(httpRequest);
                httpRequest.setConnectTimeout(3);  // 3 minutes connect timeout
                httpRequest.setReadTimeout(3);  // 3 minutes read timeout
                System.out.println("Hello"); // Just to track when a http request is made.

            }
        }).setApplicationName(APPLICATION_NAME).build();

. , batch.execute(), - - . , BatchRequest intializaiton:

BatchRequest batch = service.batch(new HttpRequestInitializer() {
                @Override
                public void initialize(HttpRequest request) throws IOException {
                    credential.initialize(request);
                    request.setConnectTimeout(10 * 60000);
                    request.setReadTimeout(10 * 60000);
                    System.out.println(request.getReadTimeout() + 2); //Just to track when a batch http request is made.
                }
            });
+4

All Articles