EWS Java API 1.1 creating appointment - missing TimeZoneDefinition

3k Views Asked by At

I have an Exchange Server 2007 SP1 and want to create an appointment with the EWS Java API 1.1. I got an Exception that I have to set the time zone definition first.

    appointment.setStartTimeZone(new TimeZoneDefinition(){{
        setName( "W. Europe Standard Time" );
    }}); 

I tried to set it directly but got this exception:

The time zone definition is invalid or unsupported

I saw some workarounds where you have to edit the Java API (like skipping the TimeZoneDefinition validation) but if its possible I dont want to do any changes there. I hope someone knows how I can set the TimeZoneDefinition properly (without modifying the base Java API).

Edit: In .NET it seems you can set the TimeZoneDefinition directly like:

appointment.StartTimeZone = TimeZoneInfo.Local;

But I cant find anything like this in the Java API

1

There are 1 best solutions below

0
On

I faced the same problem - and tried mostly everything (besides from editig the java ews api itself) to make Appointments with StartTimeZone work with Exchange 2007 SP1 in my Spring Web Application - without success.

I found comments like: Unfortunately, Exchange 2007 SP1 does not support the StartTimeZone property of EWS. If you want to use that property, you must use Exchange 2010. That i should go, look for less "flacky" Java Exchange Framework.

I wasnt pleased and as i heard there is no such problem in the .NET universe i decided to go with the following solution:

I set up a self-hosted Nancy Server.

see the Nancy Documentation

And wrote a simple NancyModule:

namespace WebServiceNancy
{
public class APIModul : NancyModule
{
    public APIModul() : base("/")
    {

        Post["/saveFooApp"] = _ =>
        {   
            var jsonApp = this.Bind<AppData>();
            string ewsURL = "https://saveFooApp/ews/exchange.asmx";
            System.Uri ewsUri = new System.Uri(ewsURL);

            ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
            service.Url = ewsUri;

            service.Credentials = new WebCredentials(jsonApp.Username, jsonApp.Password);

            Appointment app = new Appointment(service);
            app.Subject = jsonApp.Title;
            app.Start = jsonApp.Start;
            app.End = jsonApp.End;

            app.Save(WellKnownFolderName.Calendar);

            return Response.AsText("OK").WithStatusCode(HttpStatusCode.OK);
        };
    }
}


public class AppData
{
    public string Title { get; set; }
    public DateTime Start { get; set; }
    public DateTime End { get; set; }
    public string Username { get; set; }
    public string Password { get; set; }
}
}

Now i can call this WS from my Spring Controller by passing my Appointment Data as a json Object via RestTemplate:

SimpleDateFormat formatter = new  SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String startDate = formatter.format(fooMeeting.getMeetingStart());
String endDate = formatter.format(fooMeeting.getMeetingEnd());

JSONObject obj = new JSONObject();
obj.put("title", fooMeeting.getTitle());
obj.put("start", startDate);
obj.put("end", endDate);
obj.put("username", fooUser.getUsername());                 
obj.put("password", fooUser.getPassword());

RestTemplate rt = new RestTemplate();

HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);

JSONSerializer jsonSer = new JSONSerializer();

HttpEntity<String> entity = new HttpEntity<String>(jsonSer.serialize(obj), headers);

ResponseEntity<String> response = rt.exchange("http://localhost:8282/saveFooApp", HttpMethod.POST, entity, String.class);               
System.out.println(response.getStatusCode());

Ofc u need to decide if you want to use some kind of password encryption when passing credentials from one server to another - and how you implement your error handling.

  • but it works like a charm for me

  • and i am feeling very confident about future requests regarding other EWS funcionalities.