When I use com.microsoft.ews-java-api:2.0, try to connect to mail server to get all calendar data. But an error come up, EOFException, Remote host closed connection during handshake. Is there something that I missed? Below is my code:
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;
}
}
Below is the error detail, I opened -Djavax.net.debug=ssl,handshake to get more log.
http://note.youdao.com/noteshare?id=1c989b1a560c3900b80cbfd03bf80b61&sub=7276898CB2F24EE292031F4DBC837917
The exchange server bersion is 2007, which was setup 10 years ago.