A colleague recently asked me if I knew anything about consuming OData from a Java deployment in Windows Azure. My answer at the time was “no”, but with a quick pointer to http://code.google.com/p/odata4j/ I know the answer would soon change to “yes”. In this short post, I’ll show you how I used this tutorial, Deploying a Java Application to Windows Azure with Command-line Ant, to quickly comsume OData from Java running in Windows Azure.
Note: This post is not an investigation of the odata4j API. It is simply a look at how to deploy odata4j to Windows Azure. However, I will note that I didn’t see any functionality in the odata4j API for generating classes from an OData feed (unlike the OData SDK for PHP). This means that you need to know the structure of the feed you are consuming when writing code.
As I mentioned in the intro, to get my OData/JSP page running in Windows Azure, I basically followed this tutorial, written by Ben Lobaugh. Using Ben’s tutorial as a guide, you really only need to change a few things:
1. Download and install odata4j. In the You can download odata4j here: http://code.google.com/p/odata4j/. After you have downloaded and unzipped the archive, move the odata4j-bundle-0.4.jar file to the /lib/ext directory of your Java installation.
2. Create your jre6.zip archive with the odata4j files included. In the Select the Java Runtime Environment section of Ben’s tutorial, you are directed to create a .zip archive from your Java installation. Make sure you have added the odata4j-bundle-0.4.jar file to the /lib/ext directory of your Java installation before creating the archive.
3. Change the HelloWorld.jsp code to use the odata4j API. In the Preparing your Java application section of Ben’s tutorial, you need to write code that uses the odata4j API. Here’s a very simple example:
Note the references to org.odata4j.consumer and org.odata4j.core at the top of the page.
That’s it. If you follow the rest of Ben’s tutorial for testing your application in the Compute Emulator and deploying it to Windows Azure, you should have your application up and running quickly.
Next up, the Restlet OData extension. 🙂