At the moment I solved throwing a WebApplicationException: feed.addCategory(ERROR_SCHEME, String.valueOf(Status.UNAUTHORIZED.getStatusCode()), "Username or password not valid."); throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).entity(feed).build());
were the feed is an Abdera feed. For me it's important to always return a proper feed (serialized by the correct provider) independently from the status code. Throwing the exception seems to work fine. Pro: at least in this service I can avoid including the servlet class in the interface and implementation. Contra: it doesn't sound correct to me throwing exceptions for setting the status code. Cheers, V. P.s.: in the previous email @PathParam --> @FormParam (not yet Atom style for posting) On Wed, Oct 14, 2009 at 3:01 AM, Vincenzo Vitale <[email protected]>wrote: > Hi, > > in my service implementation I'm injecting the HttpServletResponse with the > @Context annotation: > > @POST > @Path("/login") > public Feed login(@PathParam("username") String username, > @PathParam("password") String password, > @Context HttpServletResponse httpServletResponse) > > and than I set the 401 status code when the user is not authorized. The > problem is that the status code is than overwritten in the > AbstractHTTPDestination class during the headers flushing: > > Integer i = (Integer)outMessage.get(Message.RESPONSE_CODE); > if (i != null) { > int status = i.intValue(); > ... ... ... > response.setStatus(status); > > is this the expected behaviour or is this a bug? > > > > Thanks in advance, > Vincenzo. >
