GoogleApps client giving SocketTimeOutException only

江枫思渺然 提交于 2019-12-11 09:09:57

问题


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();

回答1:


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);
    }
 }


来源:https://stackoverflow.com/questions/27843439/googleapps-client-giving-sockettimeoutexception-only

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!