2014-01-16 17 views
0

我正在使用vmware API。通過使用這個API,我可以獲得ESX設備的信息。現在我想使用這個API來獲取有關vCenter信息,但得到的異常:如何使用Java刪除安全證書的異常?

java.rmi.RemoteException: VI SDK invoke exception:javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: Certificates does not conform to algorithm constraints

下面是一個代碼:

    public void realesx(){ 
    System.out.println("Running ESX Realtime for host ..."+host); 
    JSONObject esxcmdout = new JSONObject(); 
    String url = "https://" + host + "/sdk/vimService"; 
    try { 
    ServiceInstance si = new ServiceInstance(new URL(url), user, pass,true); 
    System.out.println("host :"+host+"---"+si.getAboutInfo().getFullName()); 

    System.out.println(" Version is .. " +si.getAboutInfo().version); 
    System.out.println(" os type is .. " +si.getAboutInfo().osType); 
    System.out.println("Vendor is .. " + si.getAboutInfo().vendor); 
    System.out.println("name is" + si.getAboutInfo().name); 

ManagedEntity[] managedEntities = new InventoryNavigator(
      si.getRootFolder()).searchManagedEntities("VirtualMachine"); 
ManagedEntity[] hostmanagedEntities = new InventoryNavigator(
      si.getRootFolder()).searchManagedEntities("HostSystem"); 

for (ManagedEntity hostmanagedEntity : hostmanagedEntities) { 
HostSystem hostsys = (HostSystem) hostmanagedEntity; 

String ESXhostname = hostsys.getName(); 
//System.out.println("main system version is .. " + hostsys.getConfig()); 

HostListSummary hls = hostsys.getSummary(); 
     HostHardwareSummary hosthwi = hls.getHardware(); 
     HostListSummaryQuickStats hqs = hls.getQuickStats(); 
     Datastore[] HDS = hostsys.getDatastores(); 
     StringBuilder DS = new StringBuilder(); 
     for (int i=0;i <HDS.length;i++){ 
      DatastoreSummary dsm =HDS[i].getSummary(); 

      DS.append(dsm.name+":"+dsm.capacity+":"+dsm.freeSpace+"-"); 
     } 

int MEM=hqs.overallMemoryUsage; 
int UPT=hqs.getUptime(); 
Integer CPU=hqs.getOverallCpuUsage(); 

String esxkey = "ESXRealInfo"; 
String esxvalue = "ESXhostname-" + ESXhostname 
     + ";CPU Usage-" + CPU + ";MEM Usage-" 
     + MEM + ";UPTIME-" + UPT+"; Datastores -"+DS; 
try { 
    esxcmdout.put(esxkey, esxvalue); 
} catch (JSONException e) { 
    // TODO Auto-generated catch block 
e.printStackTrace(); 
} 
} 

si.getServerConnection().logout(); 
} 

catch (InvalidProperty e) { 
    // TODO Auto-generated catch block 
    e.printStackTrace(); 
} catch (RuntimeFault e) { 
    // TODO Auto-generated catch block 
    e.printStackTrace(); 
} catch (RemoteException e) { 
    // TODO Auto-generated catch block 
    e.printStackTrace(); 
} catch (MalformedURLException e) { 
    // TODO Auto-generated catch block 
    e.printStackTrace(); 
} 


} 

此代碼工作正常,收集ESX設備的信息。如何解決vcenter的證書錯誤?有沒有其他方法可以做到這一點?

回答

1

獲取此例外情況的原因之一是,使用MD2算法和HTTP客戶端(您的代碼)使用JAVA 7對HTTPs服務器(在您的案例中爲vCenter Server)提供的證書進行簽名。有關更多信息,請參見this細節。嘗試以下兩個選項之一。

  1. 使用Java 6
  2. 文件JDK_HOME/JRE/lib/security中/ java.security

檢查註釋掉行 「jdk.certpath.disabledAlgorithms = MD2」 如果錯誤被解決。