Java Reference
In-Depth Information
package com.soacoobook.rest.order;
import javax.ws.rs.Produces;
import javax.ws.rs.ext.MessageBodyWriter;
import javax.ws.rs.ext.Provider;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.List;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
/**
* Creates an HTML form representing an order for a
* supply chain. Users can submit the form back to this resource
* to add items. The page shows all items from ordering analysts.
*/
@Produces("text/html")
@Provider
public class ProductHtmlFormWriter
implements MessageBodyWriter<List<Product>> {
public boolean isWriteable(Class<?> type, Type genericType,
Annotation[] annotations, MediaType mediaType) {
System.out.println("isWriteable");
return List.class.isAssignableFrom(type);
}
public long getSize(List<Product> data,
Class<?> type, Type genericType,
Annotation annotations[], MediaType mediaType) {
System.out.println("Writer.getSize");
return -1;
}
/**
* Here we create the representation of the order as an
* HTML form. Note that we are dealing with a custom Java
* type (List<Product>) directly.
* The headers param shows Content-Type=[text/html].
*/
public void writeTo(List<Product> products,
Class<?> type, Type genericType,
Search WWH ::




Custom Search