On Oct 31, 2008, at 1:02 PM, John O'Conner wrote:
> 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.
>
The writer will only be used if the response media type matches the
value of @Produces. There are cases where you might need to check the
media type, e.g. if your writer supports two different media types but
only under certain circumstances like if it relies on the presence of
annotations on the class being written.
> 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 what I would expect too. BTW, if the body is empty there's no
need to specify a content type.
> 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?
>
It sounds to me like you are running into either a servlet error page
or an intermediate proxy or cache is translating the error for you.
The latter sounds the most likely since you are returning a response
from your method so servlet error pages shouldn't be used. Do you have
a web proxy configured and is it possible to test without ?
Marc.
---
Marc Hadley <marc.hadley at sun.com>
CTO Office, Sun Microsystems.