users@jersey.java.net

Re: [Jersey] Web applications using XMLHttpRequest and JAX-RS REST/JSON Web Services

From: Craig McClanahan <Craig.McClanahan_at_Sun.COM>
Date: Mon, 10 Nov 2008 13:47:44 -0800

Eduardo Pérez Ureta wrote:
> Like Josh:
> http://joshdevins.blogspot.com/2008/10/jax-rs-woes-continue.html
> I would like to send a text/plain response with a message when I
> output a 401 Unauthorized response. Is there a way to do that with
> JAX-RS ?
>
Set up your resource method to return Response, and then something like
this should work:

    @GET
    @Path("{id}")
    public Response findCustomer(@PathParam("{id}") String id) {
        if (!userIsAuthorized(...)) {
            return Response.status(401).type("text/plain").entity("This
is my error message").build();
        }
        Customer customer = ...
        return Response.ok(customer).build();
    }

> Craig McClanahan wrote:
>
>> Are there particular aspects of CSRF that you are concerned about?
>>
> No, I just wanted to know if there is a defacto standard way to do
> that using JAX-RS
>
>
I don't know of anything that specifically relates to JAX-RS in this regard.

Craig
> Eduardo
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>