users@jersey.java.net

[Jersey] Re: Explicitly declare the root resource and provider classes - not working for provider class

From: Farrukh Najmi <farrukh_at_wellfleetsoftware.com>
Date: Tue, 28 Feb 2012 13:04:37 -0500

Hi Glen,

Thank you for your help. Please see inline below...

On 02/28/2012 12:21 PM, Glen Mazza wrote:
> As a temporary step, instead of reading in your HubSubscriberResource
> via a Spring application context file, can you try directly
> hardcoding/instantiating it and see what happens? That will let us
> know whether the problem is with the Spring config or getSingletons().

But the HubSubscriberResource (my only root resource) is working just fine.
What is not being regsitered is my only Provider class SyndFeedReader.

Removing spring is quite complex in my app so dop you still think it
would help given what I said above about what works and does not work?

>
> There are actually not two entries for hubSubscriberResource, just one
> (the other is "H"ubSubscriber...) Perhaps it's your Spring config
> file causing those classes to be registered.

I searches my entire source tree and there is no instance of
/*h*/ubSubscriberResource. That string must have been generated by
jersey code is all I can guess.

As to why two instances of class
org.freebxml.omar.pubsub.subscriber.HubSubscriberResource are being
registered I cannot say. Note that I am not setting the
"com.sun.jersey.config.property.packages" initParam on the SpringServlet
so package scanning is not occuring (otherwise we got into
http://jersey.576304.n2.nabble.com/jersey-and-java-web-start-td4506576.html
issue).

>
> Finally, if nothing else works, you might be able to register your
> @Provider (providing it has that annotation) by adding it to
> getClasses(). CXF at least allows that, and it still treats it as a
> singleton (AFAIK):
> https://github.com/gmazza/jersey-samples-on-cxf/blob/master/simple-servlet/src/main/java/com/sun/jersey/samples/servlet/resources/MyApplication.java
>

I am already doing above AFAIK. See my SyndFeedReader class has
@Provider annotation and is being added in getClass() as shown below.

BTW, when I set breakpoints inside my getClasses() and getSingletons()
methods of my "class HubSubscriber extends javax.ws.rs.core.Application"
I find they are never called!

So I am really confused whats going on or what to try next.

I can debug this further in the debugger if any one has specific
suggestions on where to set breakpoints and what to look for.

Please note that I have spent 4 days on the series of issues discovered
when trying to get my jersey server endpoint app that was working
standalone just fine to work under java webstart and really appreciate
all the help I have been getting.

> HTH,
> Glen
>
>
>
> On 02/28/2012 12:00 PM, Farrukh Najmi wrote:
>>
>> With help from Alexey Stashok on the Grizzly list I have overcome
>> earlier problems with an issue in Grizzly with webstart.
>> Now I am close and would really appreciate if someone from jersey
>> team / community can get me over the hump on the following simple
>> issue...
>>
>> Recall that when running a jersey endpoint within javawebstart could
>> not use automatic package scanning:
>>
>> http://jersey.576304.n2.nabble.com/jersey-and-java-web-start-td4506576.html
>>
>> So I modified my code to use explcit declaration of root resource and
>> provider classes. This seems to work for my root resource singleton
>> but is not working for my provider class.
>>
>> Here is what my Provider class looks like:
>>
>> @Produces("application/atom+xml")
>> @Provider
>> public class SyndFeedReader implements MessageBodyReader<SyndFeed> {
>> ...
>> }
>>
>> Here is how I explicitly declare the root resource singleton and my
>> provider class...
>>
>> public class HubSubscriber extends javax.ws.rs.core.Application {
>>
>> ....
>>
>> @Override
>> public Set<Class<?>> getClasses() {
>> Set<Class<?>> s = new HashSet<Class<?>>();
>> s.add(SyndFeedReader.class); //My Provider
>> class that does not seem to be detected
>> return s;
>> }
>>
>> @Override
>> public Set<java.lang.Object> getSingletons() {
>> Set<Object> s = new HashSet<Object>();
>>
>> HubSubscriberResource hsr = (HubSubscriberResource)
>> subApplicationContext.getBean("HubSubscriberResource");
>> s.add(hsr);
>> return s;
>> }
>>
>>
>> ....
>>
>> }
>>
>> Here is what the LoggingFilter and other logs are logging on my app
>> that implements the jersey server endpoint above.
>>
>> Some odd things I notice are:
>>
>> * Why are there two entries for INFO: Registering Spring bean,
>> hubSubscriberResource?
>> * Why is my SyndFeedReader provider class not being registered as
>> a provider class?
>>
>>
>> Feb 28, 2012 11:42:13 AM
>> com.sun.jersey.spi.spring.container.servlet.SpringServlet getContext
>> INFO: Using default applicationContext
>> Feb 28, 2012 11:42:13 AM
>> com.sun.jersey.spi.spring.container.SpringComponentProviderFactory
>> registerSpringBeans
>> INFO: Registering Spring bean, hubSubscriberResource, of type
>> org.freebxml.omar.pubsub.subscriber.HubSubscriberResource as a root
>> resource class
>> Feb 28, 2012 11:42:13 AM
>> com.sun.jersey.spi.spring.container.SpringComponentProviderFactory
>> registerSpringBeans
>> INFO: Registering Spring bean, HubSubscriberResource, of type
>> org.freebxml.omar.pubsub.subscriber.HubSubscriberResource as a root
>> resource class
>> Feb 28, 2012 11:42:13 AM
>> com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
>> INFO: Initiating Jersey application, version 'Jersey: 1.10 11/02/2011
>> 03:53 PM'
>> Feb 28, 2012 11:42:15 AM
>> com.sun.jersey.api.container.filter.LoggingFilter filter
>> INFO: 1 * Server in-bound request
>> 1 > GET
>> http://localhost:9075/wellgeo/adminui/rest/pubsub/subscriber/15e347cf-9f0b-4afb-9427-e6c1982c9f7e?hub.mode=subscribe&hub.topic=http%3A%2F%2Flocalhost%3A8080%2Fomar-server%2Frest%2Fevents%2Fall&hub.challenge=60fdc38c-b224-449c-b4aa-f3a0b760c4b5&hub.lease_seconds=3610&hub.verify_token=79fc36ef-ea52-46bf-98b4-ac14b122234c
>> 1 > user-agent: ROME-Certiorem
>> 1 > host: localhost:9075
>> 1 > accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
>> 1 > connection: keep-alive
>> 1 >
>>
>> Feb 28, 2012 11:42:15 AM org.rometools.certiorem.sub.Subscriptions
>> validate
>> FINE: Handling validation request for id
>> 15e347cf-9f0b-4afb-9427-e6c1982c9f7e
>> Feb 28, 2012 11:42:15 AM org.rometools.certiorem.sub.Subscriptions
>> validate
>> FINE: Validated. Returning 60fdc38c-b224-449c-b4aa-f3a0b760c4b5
>> Feb 28, 2012 11:42:15 AM
>> com.sun.jersey.api.container.filter.LoggingFilter$Adapter finish
>> INFO: 1 * Server out-bound response
>> 1 < 200
>> 1 < Content-Type: text/html
>> 1 <
>> 60fdc38c-b224-449c-b4aa-f3a0b760c4b5
>>
>> .... Above request is processed fine indicating that my singleton
>> root resource HubSubscriberResource is working fine
>>
>> Feb 28, 2012 11:42:48 AM
>> com.sun.jersey.api.container.filter.LoggingFilter filter
>> INFO: 2 * Server in-bound request
>> 2 > POST
>> http://localhost:9075/wellgeo/adminui/rest/pubsub/subscriber/65e6c143-5f8e-4488-ac96-4cb97e52ad24
>> 2 > content-type: application/atom+xml
>> 2 > user-agent: Java/1.6.0_20
>> 2 > host: localhost:9075
>> 2 > accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
>> 2 > connection: keep-alive
>> 2 > content-length: 2211
>> 2 >
>> <?xml version="1.0" encoding="UTF-8"?>
>> <feed xmlns="http://www.w3.org/2005/Atom"
>> xmlns:dc="http://purl.org/dc/elements/1.1/">
>> <title>ebXML RegRep All Events Feed</title>
>> <link rel="alternate"
>> href="http://localhost:8080/omar-server/rest/events/all" />
>> <subtitle>A feed of all AuditableEvents generated by ebXML RegRep
>> server</subtitle>
>> <id>http://localhost:8080/omar-server/rest/events/all</id>
>> <dc:creator>ebXML RegRep Server</dc:creator>
>> <entry>
>> <link rel="alternate"
>> href="http://localhost:8080/omar-server/rest/registryObjects/urn:uuid:9ee59029-a855-45ca-9290-af1f45309d5a"
>> />
>> <author>
>> <name>rod</name>
>> </author>
>> <id>urn:uuid:9ee59029-a855-45ca-9290-af1f45309d5a</id>
>> <updated>2012-02-28T16:42:33Z</updated>
>> <published>2012-02-28T16:42:33Z</published>
>> <content type="text/xml">
>> ...
>> </content>
>> <dc:creator>rod</dc:creator>
>> <dc:date>2012-02-28T16:42:33Z</dc:date>
>> </entry>
>> </feed>
>>
>>
>>
>> Feb 28, 2012 11:42:48 AM
>> com.sun.jersey.spi.container.ContainerRequest getEntity
>> *SEVERE: A message body reader for Java class
>> com.sun.syndication.feed.synd.SyndFeed, and Java type interface
>> com.sun.syndication.feed.synd.SyndFeed, and MIME media type
>> application/atom+xml was not found.*
>> The registered message body readers compatible with the MIME media
>> type are:
>> */* ->
>> com.sun.jersey.core.impl.provider.entity.FormProvider
>> com.sun.jersey.core.impl.provider.entity.MimeMultipartProvider
>> com.sun.jersey.core.impl.provider.entity.StringProvider
>> com.sun.jersey.core.impl.provider.entity.ByteArrayProvider
>> com.sun.jersey.core.impl.provider.entity.FileProvider
>> com.sun.jersey.core.impl.provider.entity.InputStreamProvider
>> com.sun.jersey.core.impl.provider.entity.DataSourceProvider
>> com.sun.jersey.core.impl.provider.entity.XMLJAXBElementProvider$General
>> com.sun.jersey.core.impl.provider.entity.ReaderProvider
>> com.sun.jersey.core.impl.provider.entity.DocumentProvider
>>
>> com.sun.jersey.core.impl.provider.entity.SourceProvider$StreamSourceReader
>> com.sun.jersey.core.impl.provider.entity.SourceProvider$SAXSourceReader
>> com.sun.jersey.core.impl.provider.entity.SourceProvider$DOMSourceReader
>> com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$General
>> com.sun.jersey.core.impl.provider.entity.XMLListElementProvider$General
>> com.sun.jersey.core.impl.provider.entity.XMLRootObjectProvider$General
>> com.sun.jersey.core.impl.provider.entity.EntityHolderReader
>>
>> Feb 28, 2012 11:42:48 AM
>> com.sun.jersey.api.container.filter.LoggingFilter$Adapter finish
>> INFO: 2 * Server out-bound response
>> 2 < 415
>> 2 <
>>
>>
>> ............. Above POST request fails because it seems that my
>> SyndFeedReader provider class is not getting used.

-- 
Regards,
Farrukh Najmi
Web: http://www.wellfleetsoftware.com