users@jersey.java.net

Re: [Jersey] Take 2: Using MessageBodyWriters as Providers for an AccountList and an Account object

From: John O'Conner <john_at_joconner.com>
Date: Fri, 31 Oct 2008 10:02:38 -0700

On Fri, Oct 31, 2008 at 1:26 AM, Paul Sandoz <Paul.Sandoz_at_sun.com> wrote:

> You need to do this:
>
> public class AccountsProvider ...
>
> ...
>
> public boolean isWriteable(Class<?> arg0, Type arg1, Annotation[] arg2, MediaType arg3) {
> return AccountSummaryList.class == arg0;
> }
> }
>


Thank you for the tip. That solved the problem.

Since the annotation clearly suggests the mime types for this class, I
previously though I wouldn't have to also check the MediaType...but
your tip suggests that I might need to do that as well. I'm not yet,
but I wonder if I should.

One other question: let's assume that the resource I requested does
not exist. In that case, I'm returning this from AccountResource for
example:
Response.status(Response.Status.NOT_FOUND)
        .type(MediaType.APPLICATION_XML)
        .build();

However, the response actually contains HTML, and my browser displays
an html message. I assumed that mime type would be "application/xml",
the entity body would be empty, and only a response header would say
not found (404?). That's not the case...the response is HTML with the
404 text message. How can I create that response for an XML entity
type?

Thank you again!

Regards,
John