written by cschalk
Whether you are an avid Eclipse IDE user or not, the task of building OpenSocial applications has now taken a leap forward with the introduction of the Eclipse based OpenSocial Development Environment (OSDE). With OSDE, it is now possible to build OpenSocial applications directly within Eclipse, as opposed to a live sandbox environment. This means you can easily develop OpenSocial compliant applications entirely in a stand alone manner, within the context of a modern Integrated Development Environment (IDE). OSDE provides a rich set of features that both enable and enhance OpenSocial application development for both the client within a gadget, or even on a server using the Java RESTful client libraries.
It's features include:
Note: An accompanying screencast demonstration of OSDE is available here!
The simplest way to appreciate all of the features together, is to step through a walkthrough of building both a typical OpenSocial gadget application, as well as a Java client application. But before building an application, here's a quick review of how to install the OSDE plugin.
Installing the OSDE plugin into Eclipse is a simple 1-step process as it doesn't have any complicated dependencies. It requires that you have Eclipse version 3.4.1 or later ('JavaEE Developers' package is recommended) at a minimum as well as a Java SE Development Kit 5.0 or higher. Installation can be done by accessing your Eclipse's 'Software Updates' and adding the new site: "http://opensocial-development-environment.googlecode.com/svn/update-site/site.xml". Once added, you can then easily install the plugin. Upon successful installation of the plugin, your Eclipse IDE requires a restart, and then you're ready to start building applications using OSDE!
For this walkthrough, we will create the typical OpenSocial "HelloWorld" application, which is a basic app that displays the viewer's friends. Before we can have a running app that displays friends however, we'll need to start the local Shindig server and populate the H2 database with some people/friends data. Fortunately this step is easily done by either:
To load the sample social data, we need to start the local shindig server first. This is done by clicking the "Launch Apache Shindig server" button on Eclipse's main toolbar, or by selecting 'Launch Apache Shindig' from the OSDE menu. You will see Shindig start up in the console.
Now that Shindig has started, we can populate the database by selecting 'Create sample data in Shindig' from the OSDE menu. Alternatively we could also use the database interface windows in the console to create custom data on the fly. This interface allows you to edit, people/relationship, activities and persistent data directly.
Now that we have setup some social data, we'll create a new OSDE project. To do this, we select 'Create new project...-> OpenSocial Project' from the main menu.
The first page of the OpenSocial project creator wizard allows us to define some of the core aspects of the gadget applications, such as the app title, author email as well other gadget options such as which version of OpenSocial etc.
The next step allows for the creation of 'views' of the application. These include 'canvas', 'profile', 'preview' and 'home'. For a simple app, we can create both a 'canvas' view and a 'profile' view, which is consistent with many OpenSocial containers.
For this tutorial, please enable all the following options as well:
Once both canvas and profile views are created, we'll click Finish to generate the project.
As you can see, the enhanced gadget editor allows us to easily edit the properties of the gadget spec (gadget.xml) by selecting the tabbed options at the bottom. For this example "Helloworld" gadget, we'll click the Source tab and edit the gadget spec directly.
In building this simple app, we can replace the default code in the canvas view portion of gadget spec from:
As you select to run the application, a dialog appears prompting you to enter any runtime parameters such as the 'View', the 'Owner', the 'Viewer' as well as localization features such as Country and Language. You can also specify whether you want to run the gadget in a external browser, or in the Eclipse built-in browser.
As the application starts up, a default runtime page appears with the gadget rendered. As you can see, the results of the friends query for the user 'john.doe' is rendered in the gadget.
Now that we have create and run an OpenSocial application. We can now create a new Java client application that uses the Java client libraries. To create a out Java RESTful client project, we again right-click the gadget spec (gadget.xml) and select OSDE->Create Java Project for Restful Protocol.
The project wizard allows you to name the project and specify other settings such as the src and bin directories. Once created, the project will have a sample Java client that displays the friends of a user. To display the same friends from the sample userid 'john.doe', we can edit the Java code and specify the VIEWER_ID as "john.doe".
Now that we've specified the VIEWER_ID as 'john.doe', we can run the application by right-clicking the file Sample.java, and selecting Run As-> Java Application. Note, the Shindig server should remain running for the client application to work. As the client launches, you'll notice in the console the results, which in this case are the same friends that were displayed in the previous gadget application.
This concludes our brief walkthrough of the new OSDE Eclipse plugin. As you can see with this tool, it is very easy to develop and test both OpenSocial gadget applications, as well as Java client applications. As OSDE is very new, it is still in the process of evolving, so stay tuned for new features as they are developed. To follow OSDE's progress, please visit the new Google code project: http://code.google.com/p/opensocial-development-environment
User Guide >