Child pages
  • Connect mysql database to shindig
Skip to end of metadata
Go to start of metadata

This tutorial shows how one can add a database to Java Shindig,
so that social requests to shindig will be taking data from this database.
For this tutorial MySQL database is used.

1) Download shindig trunk as follows:

$mkdir shindig
$cd shindig
$svn checkout .
# This also was working for a branch 2.0.x

2) To use database in Shindig one could take advantage of existing in shindig "samples" project that uses JPA and EclipseLink to connect to the database from Java. This how Shindig should be compiled in this tutorial (in future it should be cleaned up to have only one command for compilation)

# Compilation: in shindig root folder
# To build samples jar
$mvn -Dmaven.test.skip -P samples
# To build server jar
$mvn -Dmaven.test.skip
# Running server
$cd java/server
$mvn jetty:run

3) First of all we need to add into Shindig's Guice modules. This module will provide real database implementations for PersonService, AppDataService, etc. One should add this module in java/server/src/main/webapp/WEB-INF/web.xml. Some default Guice modules should be removed from this file in order to avoid compilation problems. This is how the <context-params> section should look.


We also need to change the to add a sample OAuthDataStore.


  protected void configure() {



4) Here we will adjust Shindig settings to compile with database support. We have to move external dependencies from samples/pom.xml to social-api/pom.xml. We also add dependency on shinig-samples and (since we use mysql database) we add dependency on the database driver too. Now to compile the project we have to compile first "samples" and then the whole project (as explained in 2)

    <!-- dependency on shindig-samples -->

    <!-- add a driver for mysql -->
    <!-- add here all external dependencies from samples/pom.xml -->

5) Generate signing keys for oAuth with the following commands. (In production use the proper keys)

$mkdir ssl_keys
$cd ssl_keys
$openssl req -newkey rsa:1024 -days 365 -nodes -x509 -keyout testkey.pem      -out testkey.pem -subj '/CN=mytestkey'
$openssl pkcs8 -in testkey.pem -out oauthkey.pem -topk8 -nocrypt -outform PEM

Add the keys information into java/common/conf/ Don't forget the full path to your oauthkey.pem!!


6) Add your database information to java/samples/src/main/resources/ Here we use mysql database, so the settings are mysql specific.



7) Create database "shindig" and give access to it for user "shindig" with password "shindig".

8) Compile now the project and run jetty server according to 2)
The tables will be created in the database based on shindig's default database structure.

9) When database is created, add manually a row to the Person table with
oid = 1, person_id = 1 and display_name = Shindig User

10) Run the jetty server as explained in 2) (Ignore errors that tables already exist). Now execute a social request in your browser.


You should get back a json response (I had to reload page 3 times to get it)

"displayValue":"Extended Away"},"id":"1",
"photos":[],"displayName":"Shindig User"}}

This is a proof-of-concept tutorial on how to connect Shindig to a real MySQL database. Next tutorial will explain how to change shindig classes to connect to your own database structure and not the one provided by shindig samples!

There is a patch as attachment to this document that makes all the discussed changes (please use it with care because shindig trunk might have changed when you read this and do not forget to change the absolute path to your own shindig signing keys)

  • No labels