This example demonstrates how to use JAX-RS with Glassfish and the Java Persistence API to expose the contents of a Derby database table as a RESTful resource.
The example consists of two Java classes:
com.example.resources.WidgetsResource
com.example.Persistence.Widget
The example uses sun-appserv-samples
database, which comes along with Java EE 5 Samples
GlassFish update center module. In order to install the module you need to run update center client:
And then install$AS_HOME/updatecenter/bin/updatetool
Java EE 5 Samples
module from Available Software
list.
Then run the example as follows. First start Glassfish:
$AS_HOME/bin/asadmin start-domain $AS_HOME/bin/asadmin start-database
Build the example via ant, it will create dist/GlassfishDB.war
archive.
Deploy GlassfishDB.war using the admin console or via
and then using a web browser, visit:$AS_HOME/bin/asadmin deploy dist/GlassfishDB.war
http://localhost:8080/GlassfishDB/resources/widgets
If this is the first time running this example you will likely see an empty window. In order to get some content you have to add some rows to the database as follows:
Refresh the web page to see the newly added data:
A WADL description may be accessed at the URL:
http://localhost:8080/GlassfishDB/resources/application.wadl