Skip to main content

Starting a WebServer serving Jersey RS Requests

No replies
alex-f
Offline
Joined: 2012-09-09

Hi.

We are building webservices using Grizzly and Jersey and learning along the way by doing web searches. We noticed two distinct way of launching a grizzly webserver, but do not see whether one way is better than the other. Can anyone help, please?

#1 - using GrizzlyWebContainerFactory:
==========================
public static void main(String[] args) throws IOException {
Map initParams = new HashMap();
initParams.put( "com.sun.jersey.config.property.packages", "net.gilstraps.server" );
SelectorThread selector = GrizzlyWebContainerFactory
.create( "http://localhost:9998/", initParams ); //noinspection ResultOfMethodCallIgnored
System.in.read();
threadSelector.stopEndpoint();
System.exit(0);
}}
==========================

#2 - using GrizzlyWebServer
====================
GrizzlyWebServer gws = new GrizzlyWebServer(8080, "/var/www");

// Jersey web resources
ServletAdapter jerseyAdapter = new ServletAdapter();
jerseyAdapter.addInitParameter("com.sun.jersey.config.property.packages",
"com.example");
jerseyAdapter.setContextPath("/jersey");
jerseyAdapter.setServletInstance(new ServletContainer());

// Another non-Jersey servlet
ServletAdapter simpleServletAdapter = new ServletAdapter();
simpleServletAdapter.setContextPath("/simple");
simpleServletAdapter.setServletInstance(new SimpleServlet());

// register all above defined adapters
gws.addGrizzlyAdapter(jerseyAdapter, new String[] {"/jersey"});
gws.addGrizzlyAdapter(simpleServletAdapter, new String[] {"/simple"});

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

So which way is better?

Thanks
--Alex