This example demonstrates how to use JPA in the backend with EntityManager instance injected from J2EE6 container. The example is based on bookmark example from the RESTful Web Services book, which was inspired by the http://del.icio.us/ web service.
A bookmark web application is presented that is capable of maintaining users and their bookmarks.
The example consists of four web resources implemented by the following:
com.sun.jersey.samples.bookmark_em.resources.UsersResource
com.sun.jersey.samples.bookmark_em.resources.UserResource
com.sun.jersey.samples.bookmark_em.resources.BookmarksResource
com.sun.jersey.samples.bookmark_em.resources.BookmarkResource
The mapping of the URI path space is presented in the following table:
URI path | Resource class | HTTP methods |
---|---|---|
/users/ | UsersResource | GET |
/users/{userid} | UserResource | GET, PUT (used also for creating new users), DELETE |
/users/{userid}/bookmarks | BookmarksResource | GET, POST |
/users/{userid}/bookmarks/{bmid} | BookmarkResource | GET, PUT, DELETE |
Bookmark example runs on Glassfish V3 application server (http://glassfish.dev.java.net) and needs a running JavaDB (http://developers.sun.com/javadb/) instance for underlying data (it comes along with GlassFish V2).
Presuming, you have installed Glassfish V3. AS_HOME
variable should point to
your glassfish installation directory.
You then build and run the example by
mvn package $AS_HOME/bin/asadmin start-domain $AS_HOME/bin/asadmin start-database $AS_HOME/bin/asadmin deploy target/bookmark-em.war
mvn test -Dtest.containerFactory=com.sun.jersey.test.framework.spi.container.external.ExternalTestContainerFactory -DenableLogging -DJERSEY_HTTP_PORT=8080 -Ptest