Chris Schalk, Google Developer Advocate
Chris Chabot, Apache Shindig Committer
(updated on 5/30/08)
The goal of these tutorials is to provide you with sufficient background on how to checkout, build and develop with Shindig with a goal of turning it into your own social networking site.
Important Notice: Since Shindig is a new and evolving Open Source project that has yet to release in an official alpha or beta release capacity, working with it does require some relatively advanced software development skills. Please check to see if the pre-requisites for the lab exercises are within your capacity before attempting them.
These tutorials are segmented into the following portions:
Java Exercises - These exercises are for those comfortable with the Java programming language as they deal with the Java version of Shindig.
PHP Exercises - These exercises are for those who use PHP as their programming language. These steps get you up and running with a PHP version of Shindig. Note: Labs 4 and 5 are entirely independent of the Java version of Shindig used in labs 1-3. Java developers needn't bother with these exercises and PHP developers needn't bother with the Java exercises.
Goals of these exercises
These exercises are meant to familiarize yourself with Shindig software development. You shouldn't have to complete all the exercises within 2 hours, instead you can start these and then continue to work on them on your own time. As you complete these exercises you will have a firm understanding of how to work with the Shindig code and potentially becoming a contributing member of this project!
This lab explains how to check out the entire Shindig code base and build and run the Java portion of Shindig.
These steps were taken and adapted from: http://incubator.apache.org/shindig/#tab-building
In order to build Shindig, you must have the following:
Create a subdirectory on your filesystem and checkout the Shindig code from its Subversion repository.
Here's an example of making a Shindig directory in a Unix based environment.
mkdir ~/src/shindig (this is also referred to as <shindig_home> later in the exercises) cd ~/src/shindig svn co http://svn.apache.org/repos/asf/incubator/shindig/trunk/ . To build the entire Shindig and run tests, perform the following:
cd ~/src/shindig/ mvn (This executes a top level build of Shindig) mvn -Prun This will start Shindig in a local Jetty server that will run at localhost:8080. Note: mvn -Prun is the same as changing to the ..shindig/java/server and executing:
mvn jetty:run-war To run the Jetty server on a different port, use:
mvn -Djetty.port=<port> jetty:run-warOnce you are running locally using the Jetty server, you can check to see if Shindig is running by visiting:
Some further facts about the SampleContainer
You'll notice that the samplecontainer as a default points to a test OpenSocial application at:
This is a very basic HelloWorld OpenSocial application example.
Feel free to inspect the source files for the sample container. They are located in <shindig_home>/javascript/samplecontainer
These include:
---------------------------------------------------------
This lab explains how to work with Shindig in Eclipse.
To improve the Java development experience, it's helpful to use an IDE such as Eclipse. It is relatively easy to setup Shindig to be able to be run or debugged directly from Eclipse as opposed to running from a command line.
The following steps for running Shindig from Eclipse are based on these original instructions:
http://incubator.apache.org/shindig/#eclipseProject
Note: This lab is entirely optional and is not required to build and run Shindig. Lab 3 also does not require this lab be completed as a pre-requisite.
Installing Maven to work with your Eclipse IDE
The first steps to enabling Eclipse to work with Shindig is to install the Maven plugin for Eclipse. This will allow you to build Shindig from Eclipse using Maven's dependencies.
To get started, in your home directory, create an empty Maven settings file:
~/eclipse/workspaces/shindig would work fine
Creating a Java project in Eclipse for the Shindig code
Before creating an Eclipse project to work with Shindig code, it's helpful to understand the Shindig Java code organization. The Java code for Shindig is divided into 3 separate code projects and a utility Web project for running Shindig:
Although it is possible to create Eclipse Java projects for each of these Shindig projects, you will not be able to compile using Maven within Eclipse because of the project's interdependencies. Instead you should simply create a single Java project that maps to the entire Shindig codebase. This allows Maven to successfully compile the source code across all Java projects from within Eclipse.
To create an Eclipse Java project for Shindig do the following:
Note: As Eclipse attempts to compile the source code, it will fail. This is because Maven manages the dependencies for Shindig. To enable successful compilation, you'll need to enabled Maven dependency management.
Enabling Maven for your new Eclipse projects
After creating your Eclipse project:
Maven : Enable Dependency Management Maven: Enable nested modules The Java classes should then compile cleanly within Eclipse. (The red x's should disappear)
Note: At times, the Maven plug-in seems to get out of sync with the code and will show that it is no longer cleanly compiling in Eclipse i.e. you'll see the red x's again. To fix this, you can right-click the project and disable dependency management, then redo the steps above for re-enabling maven dependency management.
Creating run and debug profiles in Eclipse
Running Shindig out of the box is possible by using the included Jetty server. Maven can start Jetty directly with the command, "mvn jetty:run" or "mvn jetty:run-war". These would be executed in the <shindig_home>/java directory. Shindig however now uses a higher level "mvn -Prun" which also starts Jetty as well but it is launched directly from the <shindig_home> directory. In order to run Shindig from Eclipse, you can set up run and debug profiles within Eclipse that execute this same high level mvn command ("mvn -Prun").
To create an external tools run profile to execute the command "mvn -Prun", do the following:
(Running Jetty from mvn steps adapted from: http://cwiki.apache.org/WICKET/maven-jetty-plugin.html )
You can now launch Shindig with a JPDA port of 4000.
To debug Shindig, you'll need to create a Debug profile.
This step allows you to launch your Shindig project in debug mode and attach to Jetty.
Launching Shindig in debug mode
Launching Shindig in your debugger is actually a 2 step process.
This lab explains how to integrate Shindig with an external database. This is done by showing an example of how to implement the three interface that Shindig provides: ActivitiesService, PeopleService and DataService. The codelab steps through how to customize Shindig with this code along with setting up a MySQL database to serve as the backend database.
Important Note: This lab uses both:
You can download these files and use them later in this lab. For the SQL script, simply right-click on the link and save as "opensocial_mysql.sql" on your filesystem.
For the patch file, be sure to unzip it into the "sql-patch.patch" text file before attempting to patch Shindig. Also to apply this patch, you'll need to have the command line "patch" utility on your system. If you don't have this, on your system, instructions are provided later in the lab explaining how to obtain/install this.
Note: If you don't have the "patch" utility and can't install it, as a backup, you can manually patch your Shindig with the contents from here: shindig_sql.zip. See the included readme file for instructions on how to manually patch Shindig with the SQL code.
Installing MySQL on your system
This tutorial uses a MySQL database as a backend data store to Shindig. If you don't have a MySQL database, the steps for downloading and installing a MySQL database can be found here:
http://www.mysql.com/
The free "community server" edition of MySQL which runs on all the major OS platforms is sufficient for these exercises and can be found at: http://dev.mysql.com/downloads/
After installing the MySQL database, you might want to also install the GUI Tools available for MySQL. These are available at:
http://dev.mysql.com/downloads/gui-tools/5.0.html
Although the GUI Tools are not required, the 'MySQL Administrator' tool is extremely helpful when setting up any MySQL database. It can be downloaded from the MySQL website.
Setting up a MySQL schema for OpenSocial
> mysql -u root -p
mysql> create database opensocial;
After creation of the new database, create a new user named 'opensocial' with a password 'opensocial'.
Note:
These default username and password values correspond to a Java class (SQLDataLayer.java) which makes a connection to a local database with the same username and password. If you use another username and password here, you'll have to edit this Java class. More info on the Java class is provided later in the tutorial.
mysql>use opensocial; mysql>create user opensocial identified by 'opensocial'; mysql>grant all on opensocial.* to 'opensocial'@'localhost' identified by 'opensocial';
3. Install SQL objects using provided script: opensocial_mysql.sql: (be sure to return to the OS prompt again using 'mysql>quit;' and then execute:)
>mysql -u opensocial --password="opensocial" opensocial < /<path_to>/opensocial_mysql.sql
4. Check to see if database installed correctly.
>mysql -u opensocial --password="opensocial" opensocial mysql> show tables; (You should see:) +----------------------+ | Tables_in_opensocial | +----------------------+ | activities | | activity_media_items | | activity_streams | | addresses | | movies | | music | | organizations | | people | | person_appdata | | person_friends | | quotes | | urls | +----------------------+
Feel free to issue some more queries:
To see all people preloaded:
mysql>select os_id, name from people;
To see all activities:
mysql>select * from activities;
Congratulations! You now have an OpenSocial schema installed on your MySQL database!
This portion of the codelab involves customizing Shindig to communicate with your newly installed database with OpenSocial data. The changes required for this are to add a new set of Java classes that implement the PeopleService, ActivitiesService and DataService interface but instead of reading from a static XML file, they provide a two way communication with a backend MySQL database.
For this exercise you will use a "patch" file to patch your build of Shindig with the necessary Java classes and example code. The link for the patch file was mentioned at the beginning of this lab.
After downloading the patch file into a location such as /tmp/sql-patch.patch.gz, unzip it. You should now have a text file: /tmp/sql-patch.patch.
A quick note on the "patch" utility used in this lab.
To apply the "sql-patch" patch, you will use the command line patch utility. Unix environments including MacOS have this utility already. For Windows users, you'll need to download a GNU version of the "patch" from here:
http://gnuwin32.sourceforge.net/packages/patch.htm
Applying the patch
patch -Np0 < /tmp/sql-patch.patch
// Customize as needed private static final String DB_URL = "jdbc:mysql://localhost:3306/opensocial"; private static final String DB_UID = "your_opensocial_username"; private static final String DB_PW = "your_opensocial_password";
http://localhost:8080/gadgets/files/samplecontainer/samplecontainer.html
Also, to experiment with a simpler client page, use:
http://localhost:8080/gadgets/files/samplecontainer/simplecontainer.html
This second link points to a simplified version of a Shindig samplecontainer client page and allows you to easily test 3 simple included example OpenSocial applications that use the the three services of OpenSocial; Activities, People, and Data.
Both lab 4 and 5 explain how to work with the PHP version of Shindig. Please contact Chris Chabot through the shindig-dev mailing list for further questions.
Important: In order to successfully work with this lab, you must have the following set up:
Without these pre-requisites installed first, this lab is not possible.
Checking out the PHP version of Shindig is essentially the same as checking out the Java version as explained in Lab 1.
However for easiest development, it's best to check out the Shindig code beneath your HTML root of your PHP enabled Apache HTML root. So for example if your Apache HTML root is '/var/www/html', you could checkout the Shindig code directly into a subdirectory of this.
Here's how you would checkout Shindig into a subdirectory named 'shindig' beneath the Apache HTML root :
cd /var/www/htmlsvn co http://svn.apache.org/repos/asf/incubator/shindig/trunk/ shindig Now instead of building the Java sources located in /java, you can instead work with the PHP sources in /php.
Setting up PHP Shindig
With PHP There is no need to build anything - the source code is already built.
To run the code, you have several options:
Edit your httpd.conf (or on some systems this is the vhost.conf). Point your apache to the php dir with a virtual host like:
<VirtualHost your_ip:your_port> ServerName your.host DocumentRoot /var/www/html/shindig/php ... other normal settings in vhosts... </VirtualHost>
Restart apache, and point your browser to:
http://your.host/gadgets/ifr?url=http://www.labpixies.com/campaigns/todo/todo.xml
you should see something like this.
If you cannot/don't want to create a virtual host, you can edit the file php/config.php and change the web_prefix setting to '/shindig/php'.
Then you can run the gadget by pointing your browser to:
http://your.host/shindig/php/gadgets/ifr?url=http://www.labpixies.com/campaigns/todo/todo.xml
Read php/README for original instructions on how to start up the php shindig server.
Read javascript/README for instructions for using the Shindig Gadget Container JavaScript to enable your page to render Gadgets using gmodules.com or a server started up as described above.
This lab explains how to install and run Partuza, which is a PHP based social networking site that uses the PHP version of Shindig.
Please see the instructions at:
http://code.google.com/p/partuza/wiki/GettingStarted