Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between GrizzlyServerFactory.createHttpServer and new GrizzlyWebServer WebServer

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.

like image 534
Sagar Bhosale Avatar asked Oct 22 '22 18:10

Sagar Bhosale


1 Answers

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

like image 141
TheWhiteRabbit Avatar answered Oct 27 '22 10:10

TheWhiteRabbit