Comparing Embed-able Java HTTP/REST Servers
I have a project where I want to create a REST service in Java, but embed the HTTP and REST server in the application itself. Why embedded? Because we can't install a servlet container on any of the machines we need to run on. I don't want to serve web pages, just REST services. Maybe in the future I would like to support web sockets, but that is just a "nice to have". This is not a public REST API, so we don't need to worry about firewalls.
There are a lot of embed-able java HTTP/REST servers out there. The good thing is that REST framework part of it seems like a no brainer; Use the reference implementation, Jersey. We already have a project using Jersey, so it's an easy choice.
But the embed-able HTTP server is not an easy choice. Here is a list with some features as of 2014-03-17. Options that support NIO and an async model would be nice.
There are a lot of embed-able java HTTP/REST servers out there. The good thing is that REST framework part of it seems like a no brainer; Use the reference implementation, Jersey. We already have a project using Jersey, so it's an easy choice.
But the embed-able HTTP server is not an easy choice. Here is a list with some features as of 2014-03-17. Options that support NIO and an async model would be nice.
- Simple - Seems to perform better than Jetty. Can use Jersey. Persuasive argument for Simple from 2008.
- Jetty - embed-able, async! (nice)
- nanohttpd - light, single .java file, seems to support REST, not sure about Jersey.
- Sun HttpServer - no REST framework?
- Grizzly, Uses NIO, part of glassfish
- Wildfly, formerly resteasy/JBOSS. It says embed-able for unit tests? sync.
- AysncWeb - dormant
I wish I could offer a conclusion, but you will probably need to research these to meet your own needs. As far as popularity I think it boils down to Jetty and Simple.
We chose Jetty. Here are the steps to get your hello world Jetty/Jersey embedded server up and running:
The hard way:
We chose Jetty. Here are the steps to get your hello world Jetty/Jersey embedded server up and running:
The hard way:
- Embed Jetty
- Using Jersey with embedded Jetty HTTP Server. Search for section 4.5.1.4. Jetty HTTP Server.
The easy way:
- Use a maven archetype: http://stackoverflow.com/a/22516307/1804678
Comments
Post a Comment