Java HTTP Server

I want to implement Java HTTP server locally, I mean that the server computer will be under my control. I expect no more than 20 clients will send requests to him. I was wondering how to do this:

  • Should I use a J2EE servlet container like Apache Tomcat?
  • Can I use J2SE classes and just create it using them?
  • Are there existing alternatives?

What does your experience offer?

+4
source share
10 answers

There is a simple HTTP server built into the Sun 1.6 JRE. It is not JavaEE or servlet compatible, it is very lightweight, but it can be good enough for your requirements. No need to download any third-party content if that’s all you need.

javadocs, rather strange, come out on their own, here .

+7
source

Embed Jetty in your application. In addition to good execution, it is very easy to use and customizable.

+7
source

You have many options, not least Jetty , Grizzly and TTiny .

I would urge you to write your own web server if you did not have time to kill and you want to spend it on what you can already download for free.

+4
source

Seriously reuse the existing solution. Why the hell do you even think about rolling on your own?

Now, 1. I do not understand your question as about embedding a container. 2. You mentioned a lengthy survey several times. Therefore, I suggest using GlassFish v3 / Grizzly (because there are many examples, for example, look at the Dead Simple Comet Example on Glassfish v3 / Grizzly ).

If you do not want to rely on how the container implemented Comet support, use atmosphere , and any of the specified containers on the website:

The atmosphere is a POJO-based framework, using Inversion of Control (IoC) to bring push / Comet to the masses! Finally, a framework that can run on any Java-based web server, including Google App Engine , Tomcat , Jetty , GlassFish , Weblogic , Grizzly , JBossWeb and JBoss , Resin , etc., without waiting for Async servlet 3.0 support or without the need to find out how Comet support was implemented differently by all of these containers.

If this is not a problem, just stick to the proposed option (GlassFish v3 / Grizzly).

For a specific and recent comparison between the Comet server implementation, check out this amazing View of the Matrix comet matching grid (source: Comet Gazing: maturity ). It can help you make your final choice ... or not :)

+3
source

I think the biggest question is: why are you building this?

If this is for personal development, I will stick to any standard libraries that come with your JDK and build them on top of that.

If, on the other hand, you have a specific application that needs a dedicated HTTP server, I would try to take one of the open source servlet containers, such as Jetty or Tomcat, and rely on them.

+2
source

Perhaps view a list of 26 open source web servers at http://java-source.net/open-source/web-servers .

http://java.sun.com/developer/technicalArticles/Networking/Webserver/WebServercode.html is the actual code in a single file that implements a multi-threaded web server. For your requirements, such as these, this should be enough.

http://java.sun.com/developer/technicalArticles/Networking/Webserver/ - this is code analysis.

+2
source

If you write your own HttpServer, you will have to implement all the HTTP protocol methods. Tomcat can be easily used locally.

+1
source

Is it a practice, fun, to fulfill special requirements or why not just add an existing solution ?

+1
source

Are you sure you want to create an HTTP server that is directly connected to the protocol, or just want to write web applications? If all you care about is writing web applications, just use Tomcat or Jetty, or Glassfish, or another server - this will save a ton of effort.

If you are really interested in writing your own server from scratch, the best way would be to simply use Java SE and not use existing server technologies.

+1
source

All Articles