Когда я использую com.microsoft.ews-java-api: 2.0, попробуйте подключиться к почтовому серверу, чтобы получить все данные календаря. Но возникла ошибка, EOFException, Удаленный хост закрыл соединение во время рукопожатия.
Есть что-то, что я пропустил?
Ниже мой код:
public class Test {
private static ExchangeService service;
private static Integer NUMBER_EMAILS_FETCH = 5; // only latest 5 emails/appointments are fetched.
private static Logger mLog = Logger.getLogger(ExchangeTest.class);
static {
try {
service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
} catch (Exception e) {
e.printStackTrace();
}
}
public Test(String url, String mail, String pwd) throws Exception {
// The url is like https://10.2.xxx.xxx/EWS/Exchange.asmx, which is internal mail server
service.setUrl(new URI(url));
ExchangeCredentials credentials = new WebCredentials(mail, pwd);
service.setCredentials(credentials);
}
public Map readAppointment(Appointment appointment) {
Map appointmentData = new HashMap();
try {
appointmentData.put("appointmentItemId", appointment.getId().toString());
appointmentData.put("appointmentSubject", appointment.getSubject());
appointmentData.put("appointmentStartTime", appointment.getStart() + "");
appointmentData.put("appointmentEndTime", appointment.getEnd() + "");
} catch (ServiceLocalException e) {
mLog.error("--------------------exception-----555555555555555-----");
e.printStackTrace();
mLog.error("--------------------exception-----66666666666666666666-----");
}
return appointmentData;
}
public List<Map<String, String>> readAppointments() {
List<Map<String, String>> apntmtDataList = new ArrayList<>();
Calendar now = Calendar.getInstance();
Date startDate = Calendar.getInstance().getTime();
now.add(Calendar.DATE, 30);
Date endDate = now.getTime();
try {
CalendarFolder calendarFolder = CalendarFolder.bind(service, WellKnownFolderName.Calendar, new PropertySet());// Here throws exception
CalendarView cView = new CalendarView(startDate, endDate, 5);
cView.setPropertySet(new PropertySet(AppointmentSchema.Subject, AppointmentSchema.Start, AppointmentSchema.End));// we can set other properties
FindItemsResults<Appointment> appointments = calendarFolder.findAppointments(cView);
int i = 1;
List<Appointment> appList = appointments.getItems();
for (Appointment appointment : appList) {
System.out.println("\nAPPOINTMENT #" + (i++) + ":");
Map appointmentData = new HashMap();
appointmentData = readAppointment(appointment);
System.out.println("subject : " + appointmentData.get("appointmentSubject").toString());
System.out.println("On : " + appointmentData.get("appointmentStartTime").toString());
apntmtDataList.add(appointmentData);
}
} catch (Exception e) {
mLog.error("--------------------exception-----77777777777777777-----");
e.printStackTrace();
mLog.error("--------------------exception-----8888888888888888-----");
}
return apntmtDataList;
}
}
Ниже подробно об ошибке, я открыл -Djavax.net.debug = ssl, рукопожатие, чтобы получить больше журнала.
http://note.youdao.com/noteshare?id=1c989b1a560c3900b80cbfd03bf80b61&sub=7276898CB2F24EE292031F4DBC837917
Сервер обмена Exchange 2007, который был установлен 10 лет назад.