users@jersey.java.net

Re: [Jersey] Jersey client accessing Jesery REST server message writer issue

From: Jimi Hullegård <jimi.hullegard_at_mogul.com>
Date: Tue, 10 Aug 2010 13:38:50 +0200

I must say that I don't quite follow you now, Paul.... You say "you definitely need to tell Jersey
what the JAXBContext should be, and that is what ContextResolver is for", but then why doesn't it work for me? I already have registered the resolver using "clientConfig.getClasses().add(JAXBContextResolver.class);" and that worked fine when jersey was fetching jaxb objects using GET, but sending objects (using POST) doesn't work.

Is there something else I have been missing?

In debug mode in Eclipse I managed to see all the message body writers registered in the init() method of MessageBodyFactory, and here they are, with their corresponding types:

com.sun.jersey.core.impl.provider.entity.SourceProvider$SourceWriter_at_16ade67 [application/xml, text/xml, */*]
com.sun.jersey.core.impl.provider.entity.StringProvider_at_10df1a3 [text/plain, */*]
com.sun.jersey.core.impl.provider.entity.ByteArrayProvider_at_16d392f [application/octet-stream, */*]
com.sun.jersey.core.impl.provider.entity.FileProvider_at_1ad09a1 [application/octet-stream, */*]
com.sun.jersey.core.impl.provider.entity.InputStreamProvider_at_115a135 [application/octet-stream, */*]
com.sun.jersey.core.impl.provider.entity.DataSourceProvider_at_1541633 [application/octet-stream, */*]
com.sun.jersey.core.impl.provider.entity.RenderedImageProvider_at_5c8344 [image/*]
com.sun.jersey.core.impl.provider.entity.MimeMultipartProvider_at_be19bd [*/*]
com.sun.jersey.core.impl.provider.entity.FormProvider_at_169cceb [application/x-www-form-urlencoded, */*]
com.sun.jersey.core.impl.provider.entity.FormMultivaluedMapProvider_at_149ad2f [application/x-www-form-urlencoded]
com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$App_at_42c7ff [application/xml]
com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$Text_at_133bce4 [text/xml]
com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$General_at_1402 [*/*]
com.sun.jersey.core.impl.provider.entity.XMLJAXBElementProvider$App_at_115bb4f [application/xml]
com.sun.jersey.core.impl.provider.entity.XMLJAXBElementProvider$Text_at_12f69d [text/xml]
com.sun.jersey.core.impl.provider.entity.XMLJAXBElementProvider$General_at_8e4f [*/*]
com.sun.jersey.core.impl.provider.entity.XMLListElementProvider$App_at_1f8d56 [application/xml]
com.sun.jersey.core.impl.provider.entity.XMLListElementProvider$Text_at_8e78a1 [text/xml]
com.sun.jersey.core.impl.provider.entity.XMLListElementProvider$General_at_191b [*/*]
com.sun.jersey.core.impl.provider.entity.ReaderProvider_at_1b00f9e [text/plain, */*]
com.sun.jersey.core.impl.provider.entity.DocumentProvider_at_1d15a38 [application/xml, text/xml, */*]
com.sun.jersey.core.impl.provider.entity.StreamingOutputProvider_at_155d3c5 [application/octet-stream, */*]
com.sun.jersey.atom.rome.impl.provider.entity.AtomFeedProvider_at_176acb1 [*/*]
com.sun.jersey.atom.rome.impl.provider.entity.AtomEntryProvider_at_17283b5 [*/*]
com.sun.jersey.json.impl.provider.entity.JSONRootElementProvider$App_at_124eb13 [application/json]
com.sun.jersey.json.impl.provider.entity.JSONRootElementProvider$General_at_c53 [*/*]
com.sun.jersey.json.impl.provider.entity.JSONJAXBElementProvider$App_at_1c55158 [application/json]
com.sun.jersey.json.impl.provider.entity.JSONJAXBElementProvider$General_at_1b8 [*/*]
com.sun.jersey.json.impl.provider.entity.JSONListElementProvider$App_at_87632e [application/json]
com.sun.jersey.json.impl.provider.entity.JSONListElementProvider$General_at_806 [*/*]
com.sun.jersey.json.impl.provider.entity.JSONWithPaddingProvider_at_1fbffde [*/*]
com.sun.jersey.fastinfoset.impl.provider.entity.FastInfosetRootElementProvider_ [application/fastinfoset]
com.sun.jersey.fastinfoset.impl.provider.entity.FastInfosetJAXBElementProvider_ [application/fastinfoset]

Does this look OK in your eyes? Is there something else I can debug in order to get closer to solving this mystery?

/Jimi


________________________________________
Från: Paul Sandoz [Paul.Sandoz_at_oracle.com]
Skickat: den 10 augusti 2010 12:45
Till: users_at_jersey.dev.java.net
Ämne: Re: SV: [Jersey] Jersey client accessing Jesery REST server message writer issue

By default Jersey creates a JAXBContext using:

   JAXBCOntext.newInstance(type)

   http://download.oracle.com/javase/6/docs/api/javax/xml/bind/JAXBContext.html#newInstance%28java.lang.Class...%29

     protected JAXBContext getStoredJAXBContext(Class type) throws
JAXBException {
         synchronized (jaxbContexts) {
             JAXBContext c = jaxbContexts.get(type);
             if (c == null) {
                 c = JAXBContext.newInstance(type);
                 jaxbContexts.put(type, c);
             }
             return c;
         }
     }

There is no class loader to specify as the type (the type of the JAXB
bean to parse or serialize) is already loaded. You only need to
specify the class loader when creating a JAXBContext and declaring a
location for the context path.

By default Jersey only has the type to go on. I suspect in your case
the type was not sufficient and you definitely need to tell Jersey
what the JAXBContext should be, and that is what ContextResolver is
for (which can also declare the Marshaller or Unmarshaller too).

Hth,
Paul.