Found this after a long time! There is a separate HttpRequestInitializer object for a batch HTTP and an atomic HTTP request to Google. I had earlier changed the HttpRequestInitializer object of the atomic requests (expecting the same to have affect on batch requests) as below:
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();
This resulted in the set read timeout for atomic requests. The batch request, sent using batch.execute()
still had the default read timeout.
To change the same for the batch requests, I changed this in my 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.
}
});