users@jersey.java.net

Re: [Jersey] not-working custom provider in Jersey 1.1 (?)

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Fri, 26 Jun 2009 15:35:29 +0200

On Jun 26, 2009, at 3:22 PM, Bruno De Nys wrote:

> Thanks for clearing things out. During my searches across the
> internet I didn't find much information pointing to this particular
> aspect (the appropriate settings in web.xml when defining a customer
> resolver). I actualy had been looking for a while how to correctly
> "register" those custom providers. I found how to do it for the
> Apache implementation and for Spring implementations, but I never
> obtained a hit via Google which told me how to do it correctly for
> my setup.
>

The Jersey samples are a good place to look.

We have the following:

   https://jersey.dev.java.net/documentation/1.1.0-ea/user-
guide.html#d4e115

But the deployment section does not make it clear that there is
actually no distinction between root resource classes and providers in
terms of registration. So i have updated to state:

   "JAX-RS provides the deployment agnostic abstract class for
declaring root resource and provider
    classes, and root resource and provider singleton instances."

and:

     "Alternatively it is possible to reuse one of Jersey's
     implementations that scans for root resource and provider classes
given a classpath or
     a set of package names. Such classes are automatically added to
the set of
     classes that are returned by <literal>getClasses</literal>. For
example,
     the following scans for root resource and provider classes in
packages "org.foo.rest",
     "org.bar.rest" and in any sub-packages of those two:"

Paul.

> Thanks for your time!
>
> On Fri, Jun 26, 2009 at 3:13 PM, Paul Sandoz (via Nabble) <ml-user
> %2B51078-16148994@...> wrote:
> Hi,
>
> Glad things are working.
>
> Given your set up there should be no scanning for resources because
> you are referring explicitly to an implementation of Application that
> does not do scanning.
>
> I am presuming given your set up the following servlet declaration in
> your web.xml should work:
>
> <servlet>
> <display-name>Jersey Web Application</display-name>
> <servlet-name>JSONThesauriServlet</servlet-name>
> <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</
> servlet-class>
> <init-param>
> <param-name>com.sun.jersey.config.property.packages</
> param-name>
> <param-value>be.kvvcr.thesauri.rest</param-value>
> </init-param>
> </servlet>
>
> Paul.
>
> On Jun 26, 2009, at 3:00 PM, Bruno De Nys wrote:
>
> >
> > Thanks for your swift reply. I immediately noticed that your
> > example worked.
> > Hence the cause of the problem was probably in the setup/
> > configuration of my
> > project.
> >
> > The messages in the log-file of my tomcat 6.0.14 server made me
> > conclude
> > that my resolver was properly registered. This was a wrong
> > conclusion. The
> > solution was to explicitly include the resolver in the application
> > that I
> > had to register in the web.xml file.
> >
> > This is the excerpt of the web.xml file:
> > <servlet>
> > <display-name>Jersey Web Application</display-name>
> > <servlet-name>JSONThesauriServlet</servlet-name>
> >
> > <servlet-
> > class>com.sun.jersey.spi.container.servlet.ServletContainer</
> servlet-
> > class>
> > <init-param>
> > <param-name>javax.ws.rs.Application</param-name>
> > <param-value> be.kvvcr.thesauri.rest.ThesauriRestApp</param-
> > value>
> > </init-param>
> > </servlet>
> > and here is my new ThesauriRestApp (the line that was added is
> > "s.add(JAXBXSLResolver.class);"):
> > package be.kvvcr.thesauri.rest;
> >
> > import java.util.HashSet;
> > import java.util.Set;
> >
> > import javax.ws.rs.core.Application;
> >
> > public class ThesauriRestApp extends Application {
> >
> > @Override
> > public Set<Class<?>> getClasses() {
> > Set<Class<?>> s = new HashSet<Class<?>>();
> > s.add(DescriptorResource.class);
> > s.add(JAXBXSLResolver.class);
> > return s;
> > }
> >
> > }
> > There was one more hickup: the vendor specific JAXB extension for
> the
> > xmlHeaders property is not available when using the JAXB-support of
> > Java
> > 6.0. As a consequence I had to copy a more recent JAXB
> > implementation (I
> > took the JAXB reference implementation 20081030) to the tomcat
> > directory
> > containing the bootstrap classes (and make sure it was loaded before
> > loading
> > rt.jar).
> >
> > The strange thing is that I now no longer see a message in my tomcat
> > log-file saying that my resolver is loaded. It is as if the
> automatic
> > scanning no longer works. I have no idea why at first the JAX-RS
> > runtime
> > scanned for my resource and now no longer scans for my resources.
> >
> > Anyway, things now seem to work as expected.
> > --
> > View this message in context: http://n2.nabble.com/not-working-custom-provider-in-Jersey-1.1-%28-%29-tp3149611p3161381.html
> > Sent from the Jersey mailing list archive at Nabble.com.
> >
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@...
> > For additional commands, e-mail: users-help@...
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@...
> For additional commands, e-mail: users-help@...
>
>
>
> View this message in context: Re: [Jersey] not-working custom
> provider in Jersey 1.1 (?)
> Sent from the Jersey mailing list archive at Nabble.com.