-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

RESTful Java Web Services
By :

We discussed a few examples in the previous section for retrieving resources via the HTTP GET
request. The resource class implementations that we used in these examples were simply returning plain Java constructs in response to the method call. What if you want to return extra metadata, such as the Cache-Control
header or the status code, along with the result (resource representation)?
JAX-RS allows you to return additional metadata via the javax.ws.rs.core.Response
class, which wraps the entity and any additional metadata, such as the HTTP headers, HTTP cookie, and status code. You can create a Response
instance by using javax.ws.rs.core.Response.ResponseBuilder
as a factory. The following example demonstrates the use of the Response
class to return the response content along with the additional HTTP header fields:
//Other imports removed for brevity import javax.ws.rs.core.CacheControl; import javax.ws.rs.core.Response; import javax.ws.rs...
Change the font size
Change margin width
Change background colour