获取 microsoft.exchange.webservices.data.ServiceLocalException:https ://outlook.xxxxxxxxx.com/ews/Exchange.asmx :连接错误
尝试使用 EWS JAVA API 访问交换服务器时。
已经有 EWSJavaAPI_1.2.1.jar、EWSJavaAPI_1.2original.jar、EWSJavaAPIWithJars_1.2.1.jar、httpclient-4.2.5.jar、httpcore-4.2.4.jar、jcifs-1.3.17.jar、commons-codec-1.7。 jar,类路径中的 commons-logging-1.1.1.jar。
这是详细的错误
microsoft.exchange.webservices.data.ServiceLocalException: https://outlook.xxxxxxxxx.com/ews/Exchange.asmx : Connection error
at microsoft.exchange.webservices.data.ExchangeServiceBase.prepareHttpWebRequestForUrl(Unknown Source)
at microsoft.exchange.webservices.data.ExchangeService.prepareHttpWebRequest(Unknown Source)
at microsoft.exchange.webservices.data.ServiceRequestBase.buildEwsHttpWebRequest(Unknown Source)
at microsoft.exchange.webservices.data.ServiceRequestBase.validateAndEmitRequest(Unknown Source)
at microsoft.exchange.webservices.data.SimpleServiceRequestBase.internalExecute(Unknown Source)
at microsoft.exchange.webservices.data.MultiResponseServiceRequest.execute(Unknown Source)
at microsoft.exchange.webservices.data.ExchangeService.bindToFolder(Unknown Source)
at microsoft.exchange.webservices.data.ExchangeService.bindToFolder(Unknown Source)
at microsoft.exchange.webservices.data.Folder.bind(Unknown Source)
at microsoft.exchange.webservices.data.Folder.bind(Unknown Source)
at com.xxxxxxx.action.MSExchangeEmailService.readEmails(MSExchangeEmailService.java:105)
at com.xxxxxxx.action.MSExchangeEmailService.main(MSExchangeEmailService.java:47)
这是下面的示例代码
public static void main(String[] args) {
MSExchangeEmailService msees = new MSExchangeEmailService();
msees.readEmails();
//msees.readAppointments();
}
static{
try{
service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
//service = new ExchangeService(ExchangeVersion.Exchange2007_SP1); //depending on the version of your Exchange.
service.setUrl(new URI("https://outlook.xxxxxxxxx.com/ews/Exchange.asmx"));
}catch (Exception e) {
e.printStackTrace();
}
}
public MSExchangeEmailService() {
ExchangeCredentials credentials = new WebCredentials("xxxx@xxxxx.com","xxxx","xxxxx");
service.setCredentials(credentials);
service.setTraceEnabled( true );
}
public List readEmails(){
List msgDataList = new ArrayList();
try{
Folder folder = Folder.bind( service, WellKnownFolderName.Inbox );
FindItemsResults<Item> results = service.findItems(folder.getId(), new ItemView(NUMBER_EMAILS_FETCH));
int i =1;
for (Item item : results){
Map messageData = new HashMap();
messageData = readEmailItem(item.getId());
System.out.println("\nEmails #" + (i++ ) + ":" );
System.out.println("subject : " + messageData.get("subject").toString());
System.out.println("Sender : " + messageData.get("senderName").toString());
msgDataList.add(messageData);
}
}catch (Exception e) { e.printStackTrace();}
return msgDataList;
}