This example demonstrates how to add support for custom Java types as resource class method parameters.
The example consists of seven Java classes:
com.sun.jersey.samples.entityprovider.Maincom.sun.jersey.samples.entityprovider.resources.MapResourceHashtable.com.sun.jersey.samples.entityprovider.resources.PropertiesResourcecom.sun.jersey.samples.entityprovider.resources.NameValuePairMapResource. The input HTML form
data is converted into an instance of this class by FormReader.com.sun.jersey.samples.entityprovider.FormReaderNameValuePair. This class is used to instantiate the
NameValuePair parameter of MapResource.updateDataItem().com.sun.jersey.samples.entityprovider.FormWriterHashtable along with a HTML form
for modifying the contents. This class is used to render the
output of MapResource.getData() and MapResource.updateDataItem().com.sun.jersey.samples.entityprovider.PropertiesProviderProperties instance. This class is used to render the
output of PropertiesResource.getSystemProperties().Jersey uses the following files to find the message body readers and writers
(FormReader, FormWriter and PropertiesProvider):
META-INF/services/javax.ws.rs.ext.MessageBodyReaderMessageBodyReader
(FormReader).META-INF/services/javax.ws.rs.ext.MessageBodyWriterMessageBodyWriter
(FormWriter and PropertiesProvider).Annotations on each message body reader and writer indicate the supported media types.
The mapping of the URI path space is presented in the following table:
| URI path | Resource class | HTTP methods |
|---|---|---|
| /data | MapResource | GET, POST |
| /properties | PropertiesResource | GET |
Run the example as follows:
mvn compile exec:java
From a web browser, visit:
http://127.0.0.1:9998/properties
From a web browser, visit:
http://127.0.0.1:9998/data
Fill in the form and submit it. Note that the list below the form is updated each time the form is submitted.
A WADL description may be accessed at the URL:
http://127.0.0.1:9998/application.wadl