users@jersey.java.net

Re: [Jersey] Using Response with non 200 responses

From: Jakub Podlesak <Jakub.Podlesak_at_Sun.COM>
Date: Tue, 15 Sep 2009 10:31:01 +0200

On Mon, Sep 14, 2009 at 04:59:26PM -0700, dloy wrote:
> I currently use Response with the ok method.
>
> Is it possible with Response to return a non-OK (e.g. 501) response with
> a body and mime type for that response?
> e.g. Response.ok(file, mimeType()).status(501).build(); I'm not sure if
> http allows this.

[1] reads:

Response status codes beginning with the digit "5" indicate cases in which the server is aware that it has erred or is incapable of performing the request. Except when responding to a HEAD request, the server SHOULD include an entity containing an explanation of the error situation, and whether it is a temporary or permanent condition. User agents SHOULD display any included entity to the user. These response codes are applicable to any request method.

So it is not only possible, but you should do that:

Response.status(501).type("text/xml").entity(...).build();

>
> Basically, I want to return an text/xml response containing information
> about an exception with a bad status.
>
> Also, could you tell me what is a good link for info on
> javax.ws.rs.core.Response.Builder.

see [2]

HTH,

~Jakub

>
> Thank you so much
> David


[1]http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
[2]https://jsr311.dev.java.net/nonav/releases/1.1/javax/ws/rs/core/Response.ResponseBuilder.html
>
>
> *
>
> *
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>

-- 
Jakub Podlešák, Software Engineer                                                             
Web Services and Technologies, SUN Microsystems                                               
http://blogs.sun.com/japod