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.
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
If you think ServletContainer
being an additional dependency use the second one.which is,
jersey + Simple Http server
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With