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();
satya
  • 109
  • 2
  • 14

1 Answers1

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);
    }
 }
qtxo
  • 1,378
  • 12
  • 12
  • 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? – satya Jan 12 '15 at 08:45
  • I never tried ApacheHttpTransport because the HttpClient version dependency (4.0.1) is too old for other libraries I use in my app. – qtxo Jan 13 '15 at 05:13