private synchronized Folder getRootFolder()

in cloud-vmware-server/src/main/java/jetbrains/buildServer/clouds/vmware/connector/VMWareApiConnectorImpl.java [116:165]


  private synchronized Folder getRootFolder() throws VmwareCheckedCloudException {
    try {
      if (myServiceInstance != null) {
        final SessionManager sessionManager = myServiceInstance.getSessionManager();
        if (sessionManager == null || sessionManager.getCurrentSession() == null) {
          myServiceInstance = null;
        }
      }
    } catch (Exception ex){
      ex.printStackTrace();
      myServiceInstance = null;
    }

    if (myServiceInstance == null){
      try {
        SSLSocketFactory factory = null;
        if(myTrustStoreProvider != null){
          final KeyStore trustStore = myTrustStoreProvider.getTrustStore();
          if (trustStore != null) {
            factory = SSLContextUtil.createUserSSLContext(trustStore).getSocketFactory();
          }
        }
        boolean forceCertificateCheck = TeamCityProperties.getBooleanOrTrue("teamcity.vmware.force.certificate.check");

        if (forceCertificateCheck && factory != null){
          myServiceInstance = new ServiceInstance(myInstanceURL,
                                                  myUsername,
                                                  myPassword,
                                                  factory,
                                                  10 * 1000,
                                                  30 * 1000);
        } else {
          myServiceInstance = new ServiceInstance(myInstanceURL, myUsername, myPassword, true, 10 * 1000, 30 * 1000);
        }
      } catch (MalformedURLException e) {
        throw new VmwareCheckedCloudException("Invalid server URL", e);
      } catch (RemoteException e) {
        if (e.getCause() != null) {
          final String message = SimpleErrorMessages.getInstance().getFriendlyErrorMessage(e, "Unknown error");
          if (e.getCause() instanceof SSLException){
            throw new VmwareCheckedCloudException("An SSL error occurred while connecting to vCenter (is server certificate uploaded to \"SSL / HTTPS Certificates\" of the Root project?):" + message, e.getCause());
          } else {
            throw new VmwareCheckedCloudException(message, e.getCause());
          }
        } else
          throw new VmwareCheckedCloudException(e);
      }
    }
    return myServiceInstance.getRootFolder();
  }