1

I would like to read all appointments from one user between some dates. And get from them the information about what, from when till when, which color (category) it has, the state if out of office. I didn't found a sample which worked. Can you show me a sample for that.

I'm using win7 and EWS Java API 1.2 from MS

1 Answers1

1

Use a CalendarView with a start and end date on the Calendar folder to get everything within a set date range. Place the properties you'd like in a PropertySet, set it in the CalendarView, and use ExchangeService.findAppointments() to get them:

CalendarView view = new CalendarView(startDate, endDate);
PropertySet p = new PropertySet(ItemSchema.Categories, AppointmentSchema.Start, 
    AppointmentSchema.End);
view.setPropertySet(p);
FindItemsResults<Appointment> find = service.findAppointments(
    WellKnownFolderName.Calendar, view);

Iterate through the FindItemsResults and get what you need. I'm not sure if it's necessary, but various operations won't always return the information you need even if you request it with the PropertySet. If that's the case, then you'll need to use Appointment.load(PropertySet) or ExchangeService.loadPropertiesForItems(Items, PropertySet) to get them. I'm not sure what you mean by out of office on the Appointment itself. Do you mean the status of the Appoinment? The state as in province? By out of office, do you mean outside of the office of the user or if the user has a status of "Out of Office" (aka OOF) when the Appointment is scheduled?

user1017413
  • 2,023
  • 4
  • 26
  • 41
  • Thank you for the answer. I tried it but got an exception. I think its a problem with the code before. With the connection.. I have: url = "http://servername/EWS/Exchange.asmx"; ExchangeService es = new ExchangeService(ExchangeVersion.Exchange2007_SP1); ExchangeCredentials credentials = new WebCredentials(user, pwd); es.setURL(new URI(url)); es.setUseDefaultCredentials(false); es.setCredentials(credentials); es.setPreAuthenticate(true); Then your code where it crashes by: FindItemsResults find = es.findAppointments(WellKnownFolderName.Calendar, view); – Mrogath_Development Jul 17 '14 at 06:06
  • The exception: microsoft.exchange.webservices.data.EWSHttpException: Connection not established at microsoft.exchange.webservices.data.HttpClientWebRequest.throwIfConnIsNull(Unknown Source) at microsoft.exchange.webservices.data.HttpClientWebRequest.getResponseHeaders(Unknown Source) at microsoft.exchange.webservices.data.ExchangeServiceBase.processHttpResponseHeaders(Unknown Source) I think I have the wrong URL but do you know how i can check that? Or is it possible that some services on the exchange server not run? – Mrogath_Development Jul 17 '14 at 06:09
  • That exception is boilerplate due to a bug in EWS Java. You can either try to fix it (SimpleServiceRequest closes the response if something goes wrong, then tries to read it again later) or use a TraceListener to get a look at the XML itself to see where the error lies. It might be an outright error in the response or it might have an issue parsing the XML. – user1017413 Jul 21 '14 at 16:39
  • Can you show how I create the connection and set the destination user where I want to grep the information? – Mrogath_Development Aug 07 '14 at 12:36