I am developing a simple RESTFul service using JBoss-7.1 and RESTEasy. I have a REST Service, called CustomerService as follows:
@Path(value="/customers")
@ValidateRequest
class CustomerService
{
@Path(value="/{id}")
@GET
@Produces(MediaType.APPLICATION_XML)
public Customer getCustomer(@PathParam("id") @Min(value=1) Integer id)
{
Customer customer = null;
try {
customer = dao.getCustomer(id);
} catch (Exception e) {
e.printStackTrace();
}
return customer;
}
}
Here when I hit the url http://localhost:8080/SomeApp/customers/-1 then @Min constraint will fail and showing the stacktrace on the screen.
Is there a way to catch these validation errors so that I can prepare an xml response with proper error message and show to user?
See Question&Answers more detail:os