HttpdBase4J 0.2

HttpdBase4J is an embeddable Java web server framework that supports HTTP, HTTPS, templated content.

  Add it to your Download Basket!

 Add it to your Watch List!


Rate it!
send us
an update
LGPL (GNU Lesser General Public License) 
Donald Munro
ROOT \ Internet \ HTTP (WWW)
HttpdBase4J is an embeddable Java web server framework that supports HTTP, HTTPS, templated content and serving content from inside an archive.

The classes are easy to extend as they utilize the Hollywood 'don't call us, we'll call you' principle to allow the user to overide the framework behaviour during all the different phases of the HTTP transaction.

Note:HttpdBase4J uses the Java 6 classes so it won't currently work under earlier versions of Java.

Usage Examples:

The simplest use case is to create an embedded web server on port 8088 with its home directory at htdocs in the local filesystem and a root url at / ie / maps onto htdocs:

homeDir = new"./htdocs");
httpd = new FileHttpd(homeDir, 10); // Creates a server with a threadpool of 10
httpd.setLogger(System.err); // Log to console
httpd.start(8088, "/");

Creating a HTTPS server equivalent the the HTTP server above requires passing a keystore and password to start. Passing null will generate a certificate free keystore if you only need the encryption capabilities of HTTPS and not the certificate capability:

httpd = new FileHttpd(homeDir, 10);
m_httpd.start(8089, "/", keystore, password);

Serving content from inside an archive or from a jar or zip in the Java classpath requires creating an ArchiveHttpd instance instead of a FileHttpd. To serve content located in a jar or zip in the class path you need only specify the resource directory in the classpath where the content islocated, for example:

httpd = new ArchiveHttpd("/resources/htdocs", 10);
httpd.start(8088, "/");

To serve content from within a specific archive specify the archive as a Java File when constructing the ArchiveHttpd:

httpd = new ArchiveHttpd(new File(""), "/resources/htdocs", 10);
httpd.start(8088, "/");

Creating web content using templates is also supported. Currently only the StringTemplate library ( is is supported but it should be relatively easy to create user derived classes for other template implementations. To create an HTTP embedded web server on serving templated content from resources/htdocs in the classpath and having a template file handler (A Java class implenting the Templatable interface that is used to fill the templates) in net.homeip.donaldm.test.templates.

httpd = new ArchiveHttpd("resources/htdocs", 10);

StringTemplateHandler stHandler = new ArchiveStringTemplateHandler(httpd,

httpd.addHandler(".st", stHandler); // .st extension = template files
httpd.start(m_port, "/");

The HTTP transaction handling can be customized at any point by overiding any of the methods in the HttpHandleable interface or by overiding onCreateRequestHandler in Httpd in order to provide your own request handler. A simple example of overiding HttpHandleable methods:

httpd = new TestOverideHttpd(m_homeDir, 10);
httpd.start(m_port, "/");

class TestOverideHttpd extends FileHttpd
public HttpResponse onServeHeaders(long id, HttpExchange ex, Request request)
//Create or amend content
public InputStream onServeBody(long id, HttpExchange ex, Request request)
//Return amended or created content

Last updated on July 16th, 2007


#Java framework #web framework #HTTP content #HttpdBase4J #Java #web #server

Add your review!