users@jersey.java.net

Re: [Jersey] Entity provider not getting picked up

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Mon, 20 Apr 2009 17:24:27 +0200

On Apr 20, 2009, at 1:33 PM, Jaka Jančar wrote:

> Ahh, right... I'm not using auto-discovery, so I just added it to
> getClasses() of MyAppplication and it works now.
>
> Do you mind me asking, what is the purpose of the @Provider annotation
> then? Aren't MessageBody(Reader|Writer) interfaces enough?

It is possible to implement the interface but not be a provider that
is of interest to the JAX-RS runtime. Explicit registration using an
annotation is useful when using package scanning techniques, but i
agree it is not so useful if utilizing explicit registration.

Paul.


> On Mon, Apr 20, 2009 at 1:16 PM, Paul Sandoz <Paul.Sandoz_at_sun.com>
> wrote:
>> Hi,
>>
>> You need to register the provider in the same way as you register a
>> root
>> resource class, for example, declare the package where the
>> MyEntityProvider.class resides.
>>
>> When you deploy the application there should be a log of what root
>> resource
>> and provider classes have been discovered if you are using the
>> package
>> registration configuration.
>>
>> Paul.
>>
>> On Apr 20, 2009, at 12:07 PM, Jaka Jančar wrote:
>>
>>> I have a resource method:
>>> --
>>> @GET
>>> @Produces(MediaType.APPLICATION_JSON)
>>> public Object get() {...}
>>> --
>>>
>>> And a custom entity provider:
>>>
>>> --
>>> @Provider
>>> @Produces(MediaType.APPLICATION_JSON)
>>> @Consumes(MediaType.APPLICATION_JSON)
>>> public class MyEntityProvider implements MessageBodyReader<Object>,
>>> MessageBodyWriter<Object>
>>> --
>>>
>>> But when invoking the method, the entity provider isn't getting
>>> called
>>> at all, and I get the exception:
>>>
>>> --
>>> Apr 20, 2009 12:06:19 PM
>>> com.sun.jersey.spi.container.ContainerResponse
>>> write
>>> SEVERE: A message body writer for Java type, class java.lang.Object,
>>> and MIME media type, application/json, was not found
>>> Apr 20, 2009 12:06:19 PM
>>> com.sun.jersey.server.impl.application.WebApplicationImpl
>>> onException
>>> SEVERE: Internal server error
>>> javax.ws.rs.WebApplicationException
>>> at
>>> com
>>> .sun
>>> .jersey
>>> .spi.container.ContainerResponse.write(ContainerResponse.java:241)
>>> at
>>> com
>>> .sun
>>> .jersey
>>> .server
>>> .impl
>>> .application
>>> .WebApplicationImpl._handleRequest(WebApplicationImpl.java:689)
>>> --
>>>
>>> Is there anything else I need to do to register it?
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>