Glassfish vs Tomcat for RESTful Services

2020-05-23 04:03发布

问题:

I have a .net development background but relatively new to Java world. We have started development of RESTful services (public web APIs) with JAX-RS to be consumed mostly by mobile platforms (Android, iPhone, windows phone etc.)

  1. We need some guidance on selection of appropriate server such as Tomcat or Glassfish etc.? Please share reason as well.
  2. Also please guide whether our decision of JAX-RS is appropriate for build RESTful services.

回答1:

Tomcat is a servlet container only, which simply means that it will not provide support for Java EE features.

More than looking at RESTful services, see what you intend to use to implement your tier functionality. If you are sticking with Servlet/JSP only, then Tomcat would definitely be a very reasonable choice. If you need to use JavaEE features, then look at GlassFish.

Purely in terms of functionality, GlassFish can do everything Tomcat can, and a lot more, because it is a fully JavaEE compliant application server. But, take note, that Tomcat is used to great effect for a lot of complex applications (that don't use Java EE features).

In terms of performance, Tomcat is lightweight, starts really fast, and is well supported in the Eclipse environment. GlassFish startup is a bit slower (around 11 seconds on my horrible laptop), but deploys are blazing fast.

Tomcat has a manager application for basic app deployment, but JNDI and similar resource configurations (like user configs) have to be done by editing XML files manually. Glassfish has a nice administration console which allows you to do all this from a central UI without manual configuration editing.

Anyways, what I'm getting at is that your choice should be based solely on what you intend to use from the Java/Java EE APIs, and the server that minimally fits that bill. Don't go by any popularity consensus, as your requirements are your best guide.

As far as implementing with JAX-RS is concerned, I don't see any concerns there. I've worked with Jersey, and here's a sneak peek looking at the two: http://www.slideshare.net/pelegri/jersey-and-jaxrs-presentation

Lastly, as far as SSL is concerned: Both Tomcat and Glassfish will happily do SSL, no issues in either whatsoever.

GlassFish SSL tut: http://javadude.wordpress.com/2010/04/06/getting-started-with-glassfish-v3-and-ssl/

Good luck.



回答2:

You may take a look at Play Framework. It is scalable, stateless, restful Web-framework. Normally it don't need an application server like Tomcat. It has it's own built-in high performance webserver based on Netty. But an application can be packed as .war if you'll need it.

Building RESTful web-service won't be a problem using Play.

We use it on production environment and pretty happy with it. Development is very fast and easy. It is like Ruby on Rails in Java World.

EDIT

For an example, you may see this post.