GoogleApps client giving SocketTimeOutException only
T

1

1

We wrote a client to create a user on googleapps using the GoogleNetHttpTransport, but we are getting a socketTimeoutException when making the user as Super Admin through superadmin api. Connecting User has superAdmin Privileges itself.

How to increase the ReadTimeOut/SocketTimeout when we are using the GoogleNetHttpTransport. Please find below code snippent on connecting to target and making the client

httpTransport = GoogleNetHttpTransport.newTrustedTransport() ;
GoogleCredential credential = new GoogleCredential.Builder()
                    .setTransport(httpTransport)
                    .setJsonFactory(JSON_FACTORY)
                    .setServiceAccountId(serviceAccountId)
                    .setServiceAccountScopes(scopes)
                    .setServiceAccountUser(superAdminUserMail)
                    .setServiceAccountPrivateKeyFromP12File(privateKeyFile).build();

client = new Directory.Builder(httpTransport, JSON_FACTORY,credential)
                      .setApplicationName(APPLICATION_NAME).
                      .setHttpRequestInitializer(credential).build();

//Getting the sockt/timeout exception 
client.users().makeAdmin(userID, admin).execute();
Tufthunter answered 8/1, 2015 at 15:18 Comment(0)
T
3

Create your own HttpRequestInitializer:

new HttpRequestInitializer() {
   @Override
    public void initialize(HttpRequest request) throws IOException {
      credential.initialize(request);
      request.setConnectTimeout(CONNECT_TIMEOUT);
      request.setReadTimeout(READ_TIMEOUT);
    }
 }
Triploid answered 8/1, 2015 at 17:8 Comment(2)
Thanks qtxo, This solved my issue. Thank you very much. I just have another question, Is there any recommened transport need to be used for managing users and groups in googleapps? I see in doc that they hava apacheHttpTransport along with the NetHttpTransport?Tufthunter
I never tried ApacheHttpTransport because the HttpClient version dependency (4.0.1) is too old for other libraries I use in my app.Triploid

© 2022 - 2024 — McMap. All rights reserved.