Java Reference
In-Depth Information
@GET
@Path ( "{id}" )
@Produces ( "application/xml" )
public
public Customer getCustomer ( @PathParam ( "id" ) int
int id ) {
Customer cust = findCustomer ( id );
iif ( cust == null
null ) {
throw new NotFoundException ());
}
return
return cust ;
}
}
Like the other exceptions in the exception hierarchy, NotFoundException inherits from We-
bApplicationException . If you looked at the code, you'd see that in its constructor it is
initializing the status code to be 404. Table 7-1 lists some other exceptions you can use for
error conditions that are under the javax.ws.rs package.
Table 7-1. JAX-RS exception hierarchy
Exception Status code Description
BadRequestException 400
Malformed message
401
Authentication failure
NotAuthorizedException
403
Not permitted to access
ForbiddenException
404
Couldn't find resource
NotFoundException
405
HTTP method not supported
NotAllowedException
406
Client media type requested not supported
NotAcceptableException
415
Client posted media type not supported
NotSupportedException
InternalServerErrorException 500
General server error
ServiceUnavailableException 503
Server is temporarily unavailable or busy
BadRequestException is used when the client sends something to the server that the server
cannot interpret. The JAX-RS runtime will actually throw this exception in certain scenarios.
The most obvious is when a PUT or POST request has submitted malformed XML or JSON
Search WWH ::




Custom Search