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.

Reply via email to