users@jersey.java.net

Re: [Jersey] granular control over Http Response status

From: Andrew Cole <andrew_at_9summer.com>
Date: Wed, 28 May 2008 14:00:22 -0700

Response.status(Status.NOT_FOUND)
where Status is javax.ws.rs.core.Response.Status

On Wed, May 28, 2008 at 1:53 PM, g f <gforty_at_gmail.com> wrote:

> Hello all,
> I am new to REST, I have a GET method see below:
>
>
> @GET
> @Path("/get/{arg1}")
> @ProduceMime("application/xml")
> public String getXml(@PathParam("id")
> String id) {
> if(context.equals(null)) {
> throw new UnsupportedOperationException();
> }
> MultivaluedMap<String, String> params =
> context.getTemplateParameters();
> String arg1 = params.getFirst("arg1");
> return fpkifd.getFPKIfd(arg1).toString();
> }
>
> Currently fpkifd.getFPKIfd() method returns a single record from a
> database.
> If there are no records with the arg1 value, I return a xml error body:
> <?xml version="1.0" ?>
> <error>
> <message>No IFD with the name dufusss</message>
> <code>404</code>
> </error>
>
> I am trying to return a Http status code of 404 but I cannot seem to get
> anything other than a 200.
> I tried to insert the following:
> Response.status(404).build();
> but this has no effect.
> How can I gain more control over the status code?
> This would be easier for the end user to receive an int status code in lieu
> of an xml string error code in the body.
>
> TIA!
>
>
>