users@jersey.java.net

[Jersey] 204 status returned instead of 500 when throwing WebApplicationException

From: <sdoca_at_shaw.ca>
Date: Wed, 1 Feb 2012 18:04:12 +0000 (GMT)

I have a Jersey web service with the following a resource class:

    @Stateless
    @Path("/provision")
    public class ProvisionResource
    {
        private final Logger logger =
LoggerFactory.getLogger(ProvisionResource.class);
    
        @EJB
        private ProvisionService provisionService;
    
        @GET
        @Produces(MediaType.APPLICATION_XML)
        @Path("/subscriber")
        public SubscriberAccount querySubscriberAccount(
                @QueryParam("accountNum") String accountNum)
        {
            logger.debug("Entering querySubscriberAccount()");
            
            final SubscriberAccount account;
            
            try
            {
                account = provisionService.querySubscriber(accountNum);
    
                if (account != null)
                {
                    logger.debug("Retreived account = " + account);
                }
                else
                {
                    logger.debug("No account was found for " +
accountNum);
                }
            }
            catch (IllegalArgumentException ex)
            {
                logger.error("Illegal argument while executing query
for subscriber account",
                        ex);
                
                throw new
WebApplicationException(Response.Status.BAD_REQUEST);
            }
            catch (Exception ex)
            {
                logger.error("Unexpected exception while executing
query for subscriber account",
                        ex);
                
                throw new
WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
            }
    
            logger.debug("Exiting querySubscriberAccount()");
    
            return account;
        }

    .... snip ....
    
    }

The `provisionService.querySubscriber` throws an exception which is
caught by the second catch statement in the `querySubscriberAccount`
method (we see the log statement in the file). However, the client is
receiving a `204` status instead of the expected `500` error.

I did find this issue which is similar to mine:
http://java.net/jira/browse/JERSEY-41 but is quite old and for Jersey
1.3.1. We are using version 1.9.1.

Has anyone else seen this issue and hopefully figured out what the
problem is?