2012-11-12 66 views
1

我正在使用EWSJavaAPI 1.1.5。我試圖用無效的憑據登錄,但我沒有任何例外。如何在EWS Java API中驗證憑證

請告知如何檢測和處理無效登錄。

這裏是我的代碼:

String host = "myhost"; 
ExchangeService service = null; 
try { 
    service = new ExchangeService(); 
    ExchangeCredentials credentials = new WebCredentials("wrongemail", 
     "wrongpass"); 
    service.setCredentials(credentials); 
    service.setUrl(new java.net.URI("https://" + host 
     + "/EWS/Exchange.asmx")); 
} catch (Exception e) { 
    e.printStackTrace(); 
} 

回答

1

發現了它,我不得不把服務綁定到一個文件夾:

Folder.bind(service, WellKnownFolderName.Inbox); 

如果憑據是錯誤的,HttpErrorException被拋出。