I am making batch requests for adding members to groups. For this I am using OAuth2.0 and obtaining the object of class type Credential.When executed, the batch.execute() throws a
java.net.SocketTimeoutException : Read timed out
To change the timeout limit, this is the solution I found : GoogleApps client giving SocketTimeOutException only
But I am not able to change the timeout of the Credential object I am creating.
Credential credential = new AuthorizationCodeInstalledApp(
flow, new LocalServerReceiver()).authorize("user");
NOTE : Credential implements HttpRequestInitializer.
Thanks in advance!
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.
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With