Thanks guys. I got the problem solved. What I was doing was "Testing using Mozilla Firefox and it was not showing in any way the response status code." My resolution steps are as follows: 1. First tested using telnet and sending HTTP Get invocation, I was getting the expected resonse status code. 2. Then I used Internet Explorer and I got the response code as expected,
Regards, Sunil Kumar Dhage. -----Original Message----- From: Sunil Dhage [mailto:[email protected]] Sent: Wednesday, June 09, 2010 1:11 PM To: [email protected] Subject: Problem with Exception handling in Jaxrs web services. Hi, All the members of the users list, I am a newbie to the users list and my issue is regarding exception handling in Rest web services. I am trying to handle exceptions in my Resource methods as mentioned in http://cxf.apache.org/docs/jax-rs.html#E My code is @Path("allEmployees/{noOfEmps}") @GET @Produces("application/xml") public Employees getAllEmployees(int noOfEmps) { if (noOfEmps == 0){ throw new WebApplicationException(403); } return null; } @Path("addEmployees/{empId}") @PUT public Response addEmployees(int empId){ if (empId == 0){ return Response.status(403).build(); } return Response.ok().build(); } When I test using my browsers neither of the service methods come with the response code 403. And when I generate my wadl by http://<host>/app/....?_wadl<http://%3chost%3e/app/....?_wadl>, ....... <method name="GET"> <request></request> <response> <representation mediaType="application/xml"/> </response> </method> ..... But it should show different response entries like <response status ="403"> ... </response> <response status = "200"> .. </response> Then I tried mapping the exceptions as below @Provider public class ExceptionMapperProvider implements ExceptionMapper<WebApplicationException> { public Response toResponse(WebApplicationException ex) { return Response.status(ex.getResponse().getStatus()). entity(ex.getMessage()). type("text/plain"). build(); } } And registered this provider with the <jaxrs:providers> in my cxf.xml. Still I am neither getting the response with status code 403 nor WADL containing different response status codes. Please help me in finding what am I missing out here. Regards, Sunil Kumar Dhage.
