dev@grizzly.java.net

Jersey + Grizzly + Weld with _at_RequestScoped

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Wed, 28 Apr 2010 11:05:01 +0200

Hi,

As per Evan's tweet:

   http://twitter.com/evanchooly/statuses/12951736142

anybody want to help me get Jersey + Grizzly + Weld (the CDI impl
distributed with GF) to work on SE for @RequestScoped support.

You can find a sample maven project here:

http://markmail.org/search/?q=list
%3Anet.java.dev.jersey.users#query:list%3Anet.java.dev.jersey.users
+page:1+mid:txgigj6adxjtohz4+state:results

What this means is modifying the sample such that the JAX-RS resource
class is:

@Path("hello")
@RequestScoped // per request
public class JerseyResource {

     @Inject BeanManager bm;

     @GET
     public String get() {
         return bm.toString();
     }
}


and then somehow we modify the following:

         GrizzlyWebServer g = new GrizzlyWebServer();

         ServletAdapter jerseyAdapter = new ServletAdapter();
         jerseyAdapter.addInitParameter("javax.ws.rs.Application",
                 "org.jersey.jweld.JerseyWebApp");
         jerseyAdapter.setContextPath("/jersey");
         jerseyAdapter.setServletInstance(new ServletContainer() {
             @Override
             protected void initiate(ResourceConfig rc, WebApplication
wa) {
                 wa.initiate(rc, new JCDIComponentProviderFactory(bm));
             }
         });

         g.addGrizzlyAdapter(jerseyAdapter, new String[] {"/jersey"});
         g.start();

to register a weld listener to manage the request scope. I am assuming
Weld has some sort of basic servlet support one can add as a request
context listener, but i have not checked.

Paul.
P.S. i am not a member of the dev list so please CC on replies.