Bookmark Example

# Bookmark EM Example

This example demonstrates how to use JPA in the backend with EntityManager instance injected from Java EE 6 container. The example is based on bookmark example from the RESTful Web Services book, which was inspired by the http://delicious.com/ web service.

A bookmark web application is presented that is capable of maintaining users and their bookmarks.

## Contents

The example consists of four web resources implemented by the following:

`com.sun.jersey.samples.bookmark_em.resources.UsersResource`
  The users resource that returns a list of users.
`com.sun.jersey.samples.bookmark_em.resources.UserResource`
  The user resource that has userid, username, e-mail and password.
`com.sun.jersey.samples.bookmark_em.resources.BookmarksResource`
  The bookmarks resource that returns a list of bookmarks for actual user resource.
`com.sun.jersey.samples.bookmark_em.resources.BookmarkResource`
  The bookmark resource that has a bookmark uri and a long and short description.

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

## Running the Example

Bookmark example runs on Glassfish 3.1 application server (http://glassfish.java.net) and needs a running JavaDB (http://www.oracle.com/technetwork/java/javadb/overview/index.html) instance for underlying data (it comes along with GlassFish 3.1).

Presuming, you have installed Glassfish 3.1. `AS_HOME` variable should point to your glassfish installation directory.

#### Building And Starting The Bookmark Service

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

#### Test Client Running

    mvn test -DargLine="-Djersey.test.containerFactory=com.sun.jersey.test.framework.spi.container.external.ExternalTestContainerFactory -DenableLogging -Djersey.test.port=8080" -Ptest

## Links

http://java.net/projects/bpcatalog/sources/svn/content/trunk/ee5/docs/persistence/webonlyapp.html?raw=true