users@jersey.java.net

[Jersey] Re: Annotations in interfaces, how to use with jersey?

From: Graham Leggett <minfrin_at_sharp.fm>
Date: Sat, 15 Mar 2014 02:42:23 +0200

On 15 Mar 2014, at 1:44 AM, Graham Leggett <minfrin_at_sharp.fm> wrote:

> I am not seeing jersey work with interfaces at all.
>
> I have annotations in interfaces autogenerated by wadl2java, and a concrete implementation class that implements the interface. By default, eclipse autgenerates concrete classes with the @Override annotation. The concrete implementation class is completely ignored by jersey.
>
> I tried removing all the @Override annotations, as I believe the bug you have listed above requires. Makes no difference, jersey completely ignores the concrete classes.
>
> I tried moving the concrete implementation class into a dedicated package and pointing jersey at that new package, keeping the interface outside in another package. No joy, jersey utterly ignores the concrete class.
>
> I feel like I am in the twilight zone. wadl2java generates interface code. People on various mailing lists tell me that yes, interface code does work. But I find no concrete examples of it working, no clues as to what to do differently to make it work, and nobody can explain what to do differently to make it work.
>
> Has anyone got an actual working, running example of jersey in an interface?

More things tried, I tried implementing an Application class as follows:

package xx.users.jaxrs.service;

import java.util.HashSet;
import java.util.Set;

public class Application extends javax.ws.rs.core.Application {

        @Override
        public Set<Class<?>> getClasses() {
                Set<Class<?>> implementations = new HashSet<Class<?>>();

                /* explicitly add implementation class */
                implementations.add(UserResourceImpl.class);

                return implementations;
        }

}

In a debugger I can confirm we pass through this code on application startup, but jersey is completely silent on startup, the class UserResourceImpl is silently ignored.

I am running out of ideas at this point, does interface support work at all?

I am desperately trying to define an explicit definition of a rest interface that I can hand over to some developers and say "implement this", keeping the definition of the API in the interface where it belongs, and keeping the concrete implementation in the concrete class where it belongs (you know, standard java), but for some reason jersey seems to try and make this as hard as possible.

Am I the first to ever try this?

Regards,
Graham
--