users@jersey.java.net

Re: [Jersey] Deployment: provider recognized, but not instantiated?

From: Marc Hadley <marc.hadley_at_oracle.com>
Date: Fri, 23 Apr 2010 08:28:34 -0400

On Apr 22, 2010, at 4:06 PM, Paul Sandoz wrote:
>
> I think there might is a bug in the MBW sorting algorithm.
>
> https://jsr311.dev.java.net/nonav/releases/1.1/spec/spec3.html#x3-440004.2.2
>
> 4. Sort the selected MessageBodyWriter providers with a primary key of media type (see section 4.2.3) and a secondary key
> of generic type where providers whose generic type is the nearest superclass of the object class are sorted first.
>
> and i am doing this the opposite for the secondary key, doh! So MessageBodyWriter<String> is sorted before MessageBodyWriter<Object>, rather than the other way around.
>
I think the current behavior is correct. "object class" is a poor choice of phrase, it should be "entity object's class" or "the class of the entity object" instead. The intent is that writers whose generic type is closer to the actual type of the object being written are sorted ahead of those further away. This sorting allows more specific writers to override more generic ones.

Marc.

>
>
> On Apr 22, 2010, at 6:07 PM, Laird Nelson wrote:
>
>> Following Paul's advice, for testing anyway, I now have a war file
>> without a web.xml, and various provider classes in jars in the
>> WEB-INF/lib directory. I also have an empty subclass of
>> javax.ws.rs.core.Application that is annotated with @ApplicationPath.
>>
>> When I deploy this to Glassfish 3, I can see from the logs that my
>> provider classes are found, but logging output that I would expect to
>> see from them is never shown, and when it comes time to find a message
>> body writer, I get the following error:
>>
>> [#|2010-04-22T10:12:08.796-0400|SEVERE|glassfish3.0|com.sun.jersey.spi.container.ContainerResponse|_ThreadID=30;_ThreadName=Thread-1;|A
>> message body writer for Java type, class java.util.ArrayList, and MIME
>> media type, application/xml, was not found|#]
>>
>> My resource class does indeed return an ArrayList<PersonEntity>.
>>
>> The message body writer which I intend to have handle everything never
>> seems to be constructed, but is found:
>>
>> [#|2010-04-22T10:12:07.578-0400|INFO|glassfish3.0|com.sun.jersey.server.impl.application.DeferredResourceConfig|_ThreadID=30;_ThreadName=Thread-1;|Instantiating
>> the Application class, named com.jenzabar.ngp.war.test.Application.
>> The following root resource and provider classes are registered:
>> [class com.jenzabar.ngp.smartgwt.jaxrs.RestDataSourceAdapter, class
>> com.jenzabar.ngp.constituent.jaxrs.PersonResource]|#]
>>
>> My RestDataSourceAdapter is annotated like this:
>> @Provider
>> @Produces("application/xml")
>> public class RestDataSourceAdapter implements MessageBodyWriter<Object> {
>> //...
>> }
>>
>> I have logging messages on entry, exit of every method. No logging is
>> output. There is no indication that this message body writer is ever
>> constructed.
>>
>> What have I done wrong?
>>
>> Best,
>> Laird
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>
>