HTTP server API in Sun's Java SE 6
You are probably wondering already about the package names, and why they are com.sun.httpserver rather than something like java.net.httpserver. What this distinction means, is that the API and implementation are a fully supported, publicly accessible component of Sun's implementation of Java SE 6. It does mean however, that the packages are not formally part of the Java SE platform, and are therefore not guaranteed to be available on all other (non Sun) implementations of Java SE 6.
So, what can you do with the HTTP server ?
First, the package allows programmers to create simple embedded http and https applications. The API is similar in some respects to the servlet API in Java EE, but this API is more light-weight and does not provide the facilities/services that the servlet container environment provides.
It does have some innovations like a pluggable thread model. What this means is that the server does not create threads for handling incoming Http requests. Instead, the management of threads is delegated to an Executor object provided by the application. A number of off the shelf Executor implementations are provided in Java SE 6, and the programmer can choose one (or roll your own).
The following table shows the main classes and interfaces that a programmer needs to know about for programming a HTTP server.
| Class/interface | What does it do? |
|---|---|
| HttpServer | Listens on a particular port number and address for incoming Http requests |
| HttpsServer | Same as for HttpServer except for Https requests |
| HttpHandler | Programmer implements this. Handler is called to handle each incoming Http request |
| HttpExchange | Encapsulates all of the information about a Http request and the corresponding response |
| HttpContext | Represents one Http application on a HttpServer instance. It is identified by the URI path to the application, and has a HttpHandler associated |
There are a number of other auxiliary classes in addition to the ones mentioned above. They provide services like basic http authentication and a filtering mechanism, that can be applied to all incoming requests.
So that is a very brief overview of the Http server API. I plan to augment this with some code samples of how to use the API, how to configure the use of SSL etc.
Posted by Kaiwen on December 26, 2006 at 11:03 AM PST #
- com.sun.net.httpserver
- com.sun.net.httpserver.spi
The package description contains an example of a HTTPS server.Posted by Jari Mustonen on January 02, 2007 at 09:15 AM PST #
Posted by Ravi Luthra on January 05, 2007 at 11:29 AM PST #
Posted by Pavan Kumar on February 21, 2007 at 03:36 AM PST #
Posted by Evgeny Goldin on March 01, 2007 at 03:14 PM PST #
Posted by Alastair Rae on March 06, 2007 at 02:06 AM PST #
Posted by 194.65.5.228 on May 21, 2007 at 06:35 AM PDT #
Posted by Jerry on July 03, 2007 at 10:17 PM PDT #
Posted by Javablog on October 30, 2007 at 11:00 AM PDT #
Posted by Javablog on October 30, 2007 at 11:00 AM PDT #
we are using standalone jax-ws, we have a serious connections leak with lightweight http server
see dragonjoke.blogspot.com
Posted by Ken on June 28, 2008 at 09:33 AM PDT #
http://dragonjoke.blogspot.com/2008/06/jax-ws-loopback-connections-leak.html
Posted by Ken on June 28, 2008 at 09:34 AM PDT #