Java Reference
In-Depth Information
public
public enum
enum Family {
INFORMATIONAL , SUCCESSFUL , REDIRECTION ,
CLIENT_ERROR , SERVER_ERROR , OTHER
}
public
public Family getFamily ()
public
public int
int getStatusCode ()
public
public static
static Status fromStatusCode ( final
final int
int statusCode )
}
Each Status enum value is associated with a specific family of HTTP response codes. These
families are identified by the Status.Family Java enum. Codes in the 100 range are con-
sidered informational . Codes in the 200 range are considered successful . Codes in the 300
range are success codes, but fall under the redirection category. Error codes are in the 400 to
500 ranges. The 400s are client errors and 500s are server errors .
Both the Response.status() and ResponseBuilder.status() methods can accept a
Status enum value. For example:
@DELETE
Response delete () {
...
return
return Response . status ( Status . GONE ). build ();
}
Here, we're telling the client that the thing we want to delete is already gone (410).
javax.ws.rs.core.GenericEntity
When we're dealing with returning Response objects, we do have a problem with Mes-
sageBodyWriter s that are sensitive to generic types. For example, what if our built-in JAXB
MessageBodyWriter can handle lists of JAXB objects? The isWriteable() method of our
JAXB handler needs to extract parameterized type information of the generic type of the re-
sponse entity. Unfortunately, there is no easy way in Java to obtain generic type information
at runtime. To solve this problem, JAX-RS provides a helper class called
javax.ws.rs.core.GenericEntity . This is best explained with an example:
@GET
@Produces ( "application/xml" )
public
public Response getCustomerList () {
List < Customer > list = new
new ArrayList < Customer >();
Search WWH ::




Custom Search