Reading Exchange Mail with Java

Many times I’ve had to sweep an inbox and do something with the email. Typically the easiest way is to use IMAP.

Since 2007 Microsoft Exchange has had a rich web service interface that seems like a much better approach.

One of the main patterns used is to read an email and then move it to something like an ‘archive’ or ‘error’ directory. Exchange supports arbitrary message properties such as ‘category’ and even custom properties and I’m playing with ideas of using these properties.

Some googling turned up a java API and seems ‘lightly’ supported. I had little luck finding any examples for just reading email.
http://archive.msdn.microsoft.com/ewsjavaapi

I decided to check out the .NET library
http://msdn.microsoft.com/en-us/library/dd633710(v=exchg.80).aspx

and found the 2 APIs are very similar. By writing some samples in c# I was able to quickly port them into Java and something like this should work for you.

You do have to download the Microsoft .jar and a few dependencies to get this working. I’m posting this because I could not find this type of simple example.

tip: If you are unsure of the API domain endpoint look for the wsdl at https://EXCHANGE_API_DOMAIN/EWS/Services.wsdl

Practical Hypermedia for our post ORM world

This post is for people who have started learning about hypermedia and feel that it over complicates the elegance of REST. When I started hearing about hypermedia I felt it was adding architecture acrobatics for the sake of buzzword enhancement. After having applied these techniques in a few places not only have a drunk the cool aid, I’ve setup a stand beside my desk. I look back and try to understand where my initial negative reaction came from. I realized that many of the examples were trivial and did not demonstrate the reality of what hypermedia brings to the table.

The main epiphany I’d like to share is that REST has proven itself as the best way to take an ORM focused approach to an API and Hypermedia is proving itself as the best way to take a business process approach to an API.

A key aspect of Hypermedia that I don’t see used often enough is the notion of a template. The template portion of the spec calls for the API to send down to the client the parameters necessary to call the API itself. This notion is akin to how you load a web page with a blank form and then submit the form directly. You don’t post to twitter by typing a bunch of stuff into the url, you load twitter first and then fill in a textarea.

Essentially in my early experiments I was writing XML api payloads where the template portion was basically an HTML form that the client could decompose and render. The problem that I felt was that I was basically writing a full old school web application that happened to send XML rather than HTML back to the client. Then my client had extra complexity in parsing the XML and implementing all the UX rules to get the client looking and feeling right. I also had to build 2 webapps that both were basically doing the same thing, view, validation and calling a service.

Now lets take a look at doing this for real using AngularJS, JSON and a deadline.

Continue reading