Search code examples
jax-rscxf

WebApplicationException is not showing the error message


I created my custom exception class by extending WebApplicationException class of jax-rs api. I am throwing this exception on wrong inputs.

public class RestException extends WebApplicationException {

    public RestException(String message, Response.Status status) {
        super(message, status);
    }


}

When I used above exception in my application, it is returning the status code correctly, but it is not returning the error message i set in the constructor.

If i use jersey instead of cxf, it is showing both error message and status code. Any help on this....


Solution

  • I get rid of the problem by changing the signature of RestException constructore like below.

    public class RestException extends WebApplicationException {
    
        public RestException(String message, Response.Status status) {
            super(Response.status(status).entity(message).type(MediaType.TEXT_PLAIN).build());
        }
    
    
    }