Dropwizard/Jersey Resources and interfaces

334 views
Skip to first unread message

Brent Ryan

unread,
Jul 6, 2014, 10:37:34 PM7/6/14
to dropwiz...@googlegroups.com
Is it possible with Dropwizard to define a resource like this using interfaces?

@Path("/myResource")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public interface MyResource {

   @POST
   @Timed
   Response createSomething();
}

public class MyResourceImpl implements MyResource {

   @Override
   public Response createSomething() {
         ...//do some stuff
   }
}

When I tried several different patterns of adding this resource I couldn't get it to register with jersey properly.

environment.jersey().register(new MyResourceImpl());


The primary reason for even having this interface is so that we can dynamically generate a client from this interface by doing something like:

        DropwizardClientProxy<MyResource> clientProxy = new DropwizardClientProxy(config, e, MyResource.class);
        MyResource myResource = clientProxy.getResourceInterface();
        Response r = myResource.createSomething();

We got everything working to support this, but the only way we can get this working currently is to duplicate the annotations on the interface and the implementation.  I've read that a bunch of things like this seem to be supported in Jersey 2 (haven't tried it yet), but it seems like this should work with Jersey 1...

Anyone ever get this to work?


Thanks,
Brent

Brent Ryan

unread,
Jul 6, 2014, 11:27:17 PM7/6/14
to dropwiz...@googlegroups.com
So I found this post "http://jersey.576304.n2.nabble.com/Annotations-in-interfaces-how-to-use-with-jersey-td7582032.html" and it looks like JAX-RS just has some crappy specifications for how to handle annotation inheritance and Jersey is just implementing that crappy spec related to this.

If I remove all method, class, and parameter annotations from my concrete MyResourceImpl class then it works as expected.  This kinda sucks because you can't use things like @Override and I'm not sure this will really work anyways for other parameter level annotations that are required....

Let me know if someone finds other solutions to this problem.

Thanks!
Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
0 new messages