6

I am creating RESTful web services using Jersey and an embedded Grizzly web server.

I see that there are two ways to create an embedded Grizzly web server. Can anyone tell me the difference between the two?

public static void main(String[] args) throws IOException,  ConfigurationException,    DBException, DaxException {
    GrizzlyWebServer gws = new GrizzlyWebServer(8085, "/var/www");
    ServletAdapter jerseyAdapter = new ServletAdapter();

    jerseyAdapter.addInitParameter(
        PackagesResourceConfig.PROPERTY_PACKAGES,"com.merchant.services");
    jerseyAdapter.setServletInstance(new ServletContainer());

    gws.addGrizzlyAdapter(jerseyAdapter, new String[]{"/"});

    // let Grizzly run
    gws.start();
}  

And second way is:

ResourceConfig rc = new PackagesResourceConfig("com.merchant.services");
HttpServer httpServer = GrizzlyServerFactory.createHttpServer(BASE_URI, rc);
httpServer.start();

With the first way its easy to configure the web server.

Perception
  • 79,279
  • 19
  • 185
  • 195
Sagar Bhosale
  • 71
  • 1
  • 3

1 Answers1

3

1

Grizzly Web Serve with ServletAdapter approach is to support JAX-RS along with Servlet and Filters.which gives you,

jersey + ServletContainer

This will give you ample flexibility to provide more complex configuration

2

If you think ServletContainer being an additional dependency use the second one.which is,

jersey + Simple Http server

Community
  • 1
  • 1
TheWhiteRabbit
  • 15,480
  • 4
  • 33
  • 57
  • Thank you for the answer. So do I imply that the underlying WebServer implementation is the same? Is GrizzlyWeb Server a production quality web server ? Why should one consider grizzly over tomcat or netty? – Sagar Bhosale Feb 07 '13 at 18:52
  • 1
    One major difference that I've found is that with jersey + Simple Http Server is you have a lack of access to commonly needed data (e.g., remote client IP address) via the HttpRequestContext that is accessible with a HttpServletRequest (which is only available if configured with the ServletContainer). There's a bug on Jersey's JIRA indicating an interest in getting that information in HttpRequestContext, but it's currently "open/unresolved" after 2 years (https://java.net/jira/browse/JERSEY-473). – Jason Mock May 07 '13 at 15:45