users@jersey.java.net

granular control over Http Response status

From: g f <gforty_at_gmail.com>
Date: Wed, 28 May 2008 15:53:46 -0500

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!