users@glassfish.java.net

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

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Tue, 20 Apr 2010 09:22:27 +0200

Hi,

GF 2.1 supports EE 5 so no-interface view EJBs (or EJB POJOs) will not
work.

If you want the EJB to be a resource class in EE 5 do the following,
which is not portable and is only guaranteed to work on GF v2.x.
Define an @Remote interface and annotate that interface with JAX-RS
annotations, @Path etc, and ensure that interface is registered as a
root resource class.

If you want to inject stuff like in the blog link you sent register
that provider (e.g. make sure it is picked up using package scanning)
or declared explicitly as a class in the Application/ResourceConfig.

   https://jersey.dev.java.net/nonav/documentation/latest/user-guide.html
#d4e194

Paul.

On Apr 19, 2010, at 11:20 PM, glassfish_at_javadesktop.org wrote:

> I just started to implement a JAX-RS REST service in GF 3.
> My implementation need to access EJBs which are deployed in the
> surrounding EAR of my WAR file.
> To use the dependency injection (@EJB) I read about the need to add
> a @stateless annotation to my RESTservice class :
>
> @Path("/workflow")
> @Produces( { "application/xml","application/json" })
> [b]@Stateless[/b]
> public class WorkflowServiceHandler {
> [b]@EJB
> org.imixs.workflow.jee.ejb.WorkflowService workflowService;[/b]
>
> @GET
> @Path("/worklist/")
> public EntityCollection getWorkList(@DefaultValue("0")
> @QueryParam("start") int start,_at_DefaultValue("10")
> @QueryParam("count") int count ) {
> Collection<ItemCollection> col = null;
> try {
> col = workflowService.getWorkList(null, start, count);
> return buildEntityCollection(col);
>
> } catch (Exception e) {
> e.printStackTrace();
> }
> return new EntityCollection();
> }
> ...
>
> This works as expected in Glassfish V3.
> But now I try to get this run on a GF V2.1 server. I have added the
> jersey-core-1.1.5.1 and jersey-server-1.1.5.1 jars. So basically I
> have the functionality of jersey up and runing.
>
> But the problem is the injected EJB in my code example. As I
> understand this will only work in GF 3 Server.
>
> Now I want to ask if anybody have a solution for such a problem? I
> found this blog about a possible solution in GF 2.1:
> http://blogs.sun.com/sandoz/entry/ejb_injection
>
> But my problem is that I did not finally understand what I should do
> to get things run in GF 2.1.
> Did anybody solved this situation yet?
> Is it necessary/recommended to implement a EJB Provider class
> subclassed from the com.sun.jersey.spi.inject.InjectableProvider ?
>
> I still did not found any working solution :(
> Thanks for any help
>
> Ralph
> [Message sent by forum member 'rsoika']
>
> http://forums.java.net/jive/thread.jspa?messageID=397904
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>