users@glassfish.java.net

Re: Jersey or Servlet ?

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Tue, 31 Mar 2009 16:00:37 +0200

On Mar 31, 2009, at 3:43 PM, Felipe Gaścho wrote:

> so, I will create a new Restfull service.. than I have this doubt: to
> adopt Jersey or to go with pure Servlet ????
>
> from Jersey I got JSON and XML formats handling and a lot of cool
> features, but I loose EJB dependency injection and other Java EE
> features...
>


It will be supported when EE 6 is ready. However, there are ways to
get you boot strapped for what you require in the interim using a
plugable injection mechanism in Jersey.

See here for an example:

http://markmail.org/search/?q=list%3Anet.java.dev.jersey.users
+EJB#query:list%3Anet.java.dev.jersey.users%20EJB%20order%3Adate-
backward+page:1+mid:catyvvrocdk2h4gx+state:results


We have recently got "prototype" support working for JAX-RS resource
classes that are no-interface view session beans deployed in the war
with the latest Glasssfisg v3 nightly builds. I will send another
email to this list when it is fully integrated and working with
Jersey. This is interesting because it can reduce the layers you need
e.g. the business objects are resources.

Another approach is to extend the Jersey servlet and inject what you
require on that, and make those injected instances available to the
resource classes e.g. via ServletContext or via some custom injectable
provider.


> from servlet I have a fully Java EE compliant technology, but I miss
> the cool annotations of Jersey..
>
> so, what is the best option ?
>

Jersey :-), ,but i am biased,

It really depends on what you require. As you said Jersey can provide
the ease of use w.r.t. to JAXB XML/JSON support, and also matching
request URIs to methods.

Paul.