Java Reference
In-Depth Information
emps.put(1, e1);
emps.put(2, e2);
emps.put(3, e3);
return emps;
}
}
In this class, you use the /emps path, which will follow the context, and then map the dynamic
id parameter to select the employee whose data you're interested in.
Now if you deploy this in a WAR with the servlet mapped to /resources as with all of the
other examples in this chapter, you'll get an XML representation of a given employee. Let's
try http://localhost:8080/restexamples/resources/emps/2 , which shows the follow-
ing in a browser:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<employee>
<id>2</id>
<name>Larry Ellison</name>
</employee>
That's it. Here you're using the JAXB entity provider, but JAX-RS actually requires several
of them. They are discussed in section 4.2 of the specification. Here's a complete list:
byte[]
java.lang.String
java.io.InputStream
java.io.Reader
java.io.File
javax.activation.DataSource
javax.xml.transform.Source
javax.xml.bind.JAXBElement and application-supplied JAXB classes (used for XML
media types only)
MultivaluedMap<String, String> for form content only ( application/x-www-form-
urlencoded )
StreamingOutput
JAX-RS vendors are required to offer MessageBodyReader and MessageBodyWriter imple-
mentations for each of these means of providing entities. Each must support the */* media
type unless otherwise specified.
Search WWH ::




Custom Search