Java Reference
In-Depth Information
import java.util.Map;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.ext.MessageBodyReader;
import javax.ws.rs.ext.Provider;
/**
* Accepts the values from the HTML form to create our custom
* Java type, Product.
*/
@Consumes("application/x-www-form-urlencoded")
@Provider
public class ProductHtmlFormReader implements
MessageBodyReader<List<Product>> {
private static String ENC = "UTF-8";
//remembers all products
private List<Product> cartProducts = new ArrayList<Product>();
public boolean isReadable(Class<?> type, Type genericType,
Annotation[] annotations, MediaType mediaType) {
System.out.println("isReadable");
return type.equals(List.class);
}
/*
* Returns the list of products represented by this
* application. If this only returned a single product,
* you'd only see the last one added.
*/
public List<Product> readFrom(Class<List<Product>> type,
Type genericType,
Annotation[] annotations, MediaType mediaType,
MultivaluedMap<String, String> headers,
InputStream inputFormData)
throws IOException {
System.out.println("readFrom");
// get form data as a string
String formData = formToString(inputFormData);
// access elements from form data
Search WWH ::




Custom Search