Assume a hypothetical scenario where you are a bird lover and you want to keep track of birds that you have sighted. This app provides a RESTful API to do the following
- Add Bird - add a new bird
- View Bird - list of birds
- Delete Bird - delete a bird
- Add Sighting - add a new sighting
- View Sighting - query sighting
- Quit - shutdown the app
- Jersey
- Guice
- Jetty
- JAXB
- Sqlite
gradlew.bat fatJar
./gradlew fatJar
-data <folder path> folder path containing data xml files (required)
-port <number> listening port (if not provided then set to 3000)
-proc_count <number> number of worker process (if not provided set to 2).
This defines the number of worker process in Jetty to process request
java -jar build\libs\app.jar --data <path to data folder>
A sample data folder is available in the root folder
/add/bird
Attributes
- name
- color
- height
- weight
Example
add/bird?name=dove&color=white&height=1.0&weight=1.0
/view/bird
Sample Output
[{"name":"test1","color":"red","weight":10.0,"height":1.0,"sightings":[{"location":"jurong","date":1309492800000},{"location":"bedok","date":1312171200000}]},{"name":"test2","color":"orange","weight":9.0,"height":2.0,"sightings":[{"location":"pasir ris","date":1309496400000},{"location":"tampines","date":1309579200000},{"location":"jurong","date":1322665200000}]},{"name":"dove","color":"white","weight":1.0,"height":1.0,"sightings":[]}]
/delete/bird?name=<?>
Example
/delete/bird?name=dove
/add/sighting?name=<?>&location=<?>&date=<?>
Attributes
- name
- location
- date (dd/MM/yyyy HH:mm)
Example
/add/sighting?name=dove&location=house&date=10/01/2013 21:00
/view/sighting
Attributes
- name (regular expression)
- fromDate (dd/MM/yyyy)
- toDate (dd/MM/yyyy)
Example
/view/sighting?name=t.*&&fromDate=01/07/2010&toDate=01/07/2012
Sample Output
[{"name":"test2","color":"orange","weight":9.0,"height":2.0,"sightings":[{"location":"pasir ris","date":"01/07/2011 15:00"},{"location":"tampines","date":"02/07/2011 14:00"},{"location":"jurong","date":"01/12/2011 01:00"}]},{"name":"test1","color":"red","weight":10.0,"height":1.0,"sightings":[{"location":"jurong","date":"01/07/2011 14:00"},{"location":"bedok","date":"01/08/2011 14:00"}]}]
This API must be called using the HTTP Delete
/quit
This shutdowns the Application
<birds>
<bird>
<name>test1</name>
<color>red</color>
<height>1.0</height>
<weight>10.0</weight>
</bird
<bird>
<name>test2</name>
<color>orange</color>
<height>2.0</height>
<weight>9.0</weight>
</bird>
</birds>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<sightings>
<sighting birdname="test1">
<location>jurong</location>
<date>01/07/2011 14:00</date><
/sighting>
<sighting birdname="test1">
<location>bedok</location>
<date>01/08/2011 14:00</date>
</sighting>
</sightings>
A background thread runs prediocally to backup the Sqlite database into the xml files that was passed in as parameter
- Terrible error handling. Need to improve
- Add logging framework so as to make it easy to debug