Java Reference
In-Depth Information
Example8-20.A mock database for saving users
package com.soacookbook.rest.forms;
import java.util.HashMap;
import java.util.Map;
/**
* Mocks a database. When users are created by the form, they
* are stored here for later retrieval.
*/
public class Database {
static Map<String, User> users = new HashMap<String, User>();
}
The class that runs the show is the FormsService ; this is shown in Example 8-21 .
Example8-21.The FormsService class represents the user in a form, in a list, and in detail
package com.soacookbook.rest.forms;
import java.net.URI;
import java.util.Date;
import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriInfo;
/**
* REST service produces a form for users to provide input,
* reads the data from the form, creates a user, and returns
* navigation control. Allows viewing all users.
*
* Shows using @FormParam, Response variations, URI building,
* and putting together a complete application.
*
* 'Forms' shouldn't be part of the path probably; I only use
* it here for the topic example to keep demos clear.
*/
@Path("/forms/user")
Search WWH ::




Custom Search