users@jersey.java.net

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

From: Petr Jurák <petr.jurak_at_gmail.com>
Date: Wed, 1 Feb 2012 21:04:22 +0100

Hi,

I have similar resource and Jersey 1.9.1 and exception handling is
behaving well (I mean that the client gets 500 as expected). Could you
please double check your stack trace?
And what jee server are you using?

Br, Petr

On 1 February 2012 19:04, <sdoca_at_shaw.ca> wrote:
> 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?