users@glassfish.java.net

Re: JAX-RS in GF 2.1 and EJB injection?

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Wed, 21 Apr 2010 10:20:32 +0200

On Apr 20, 2010, at 4:55 PM, glassfish_at_javadesktop.org wrote:

> Hi,
> I am nobody how gives up very easily but I feel a little bit unsure
> about the solution.
> After all I did have the situation you described. I have one jar
> containing my EJB Interfaces, one jar containing my EJB
> implementations. These jars are bundled in my EAR. And I have
> defined an additional WAR containing my JAX-RS Class. This works in
> JEE6. But on JEE5 GF2.1 die @EJB annotation will be ignored. I
> added the EJBProvider. But the EJBProvider did not work. I always
> got the NameNotFound JNDI Exceptions or NameNotBound Exceptions.
> Maybe my problem is that I did not know how to add the ejb-ref
> declaration to my web.xml form my JAX-RS Implementation.
> And I can't find a complete solution or example. There are
> guidelines how to integrate jersey-server into Glassfish V2.1 but it
> seems that these guys did not work with EJBs...? :-/
>

JAX-RS 1.0 does not specify integration with EJB 3.0 nor does it
specify that root resource classes will get injected with EE-related
artifacts. Unfortunately only JAX-RS 1.1 with EE 6 does all the things
out of the box you require. JAX-RS 1.1 is not specified to work with
EE 5 in the same way.

In summary on EE 5/GF v2.1 Jersey can support:

- root resource classes that are remote interfaces of an EJB
(annotated such interfaces with JAX-RS annotations and register them).

- EE resource injection but you have to implement it yourself like the
EJBProvider does.

I have attached a simple NetBeans 6.8 enterprise application that runs
of GF v2.1. Note that it does require NB 6.8 because it makes
reference to Jersey 1.1.4 that ships with NB 6.8.

The URLs are:

   http://localhost:8080/EnterpriseApplication1-war/webresources/ear
   Accesses the SSB

   http://localhost:8080/EnterpriseApplication1-war/webresources/war
   Accesses the root resource in the war which reference the SSB.

The same app should also work on GF v3 but i have not tried it.

Hth,
Paul.