JAX-RS Building Responses - Quiz
Total: 4 questions
1. Helpful classes to return additional information in response to a HTTP request?
Helpful classes to return additional information in response to a HTTP request?
Response and Response.ResponseBuilder.
2. Write example where an entity body is added to a custom response.
Write example where an entity body is added to a custom response.
@POST
@Consumes("application/xml")
public Response post(String str) {
URI uri = ...
String newContent = create(str);
return Response.created(uri).entity(Entity.text(newContent)).build();
}
3. How does JAX-RS support conditional GETs?
How does JAX-RS support conditional GETs?
Using the contextual interface Request and its method evaluatePreconditions.
4. What will Request. evaluatePreconditions return?
What will Request. evaluatePreconditions return?
If a client request has an If-None-Match header with a value that contains the same entity tag that was calculated then the evaluatePreconditions returns a pre-filled out response, with the 304 status code and entity tag set, which can be built and returned. Otherwise, evaluatePreconditions returns null and the normal response can be returned.
Page 1 of 1