pagetop
Javablog
by Java coders, for Java codersRSS

HTTP Server API, backport to Java 5

October 27th, 2007 by Sam

We’ve recently been forced to go back to Java 5. After a massive refactoring task to remove all @Override annotations on method implementations, we were only left with one thing missing… SUN’s HTTP Server API (a.k.a. com.sun.net.httpserver) which is not a part of J2SE and was only introduced in Java 6. We use it in one of our packages as a lightweight server… I’d considered porting our code to use an open source tool like BareHTTP, but to be honest I’ve been itching to look at the OpenJDK code for a while and this was all the excuse I needed. Read on to get the jar of the backported libraries, which are distributed under the GPL.

The OpenJDK release regular builds (with source) to the latest implementation of JDK7. I used the b22-12oct2007 snapshot. It was then a simple case of finding the package com.sun.net.httpserver, its implementation sun.net.httpserver, a new Java 6 parameter class javax.net.ssl.SSLParameter and writing a utility class to be able to pass the parameters around in their new form.

OpenJDK has a set of test cases for the new API, however I wouldn’t go so far as to call them automated or unit tests. They are more like 20 or 30 classes with main methods, no documentation and no standard way to say whether the test passed or failed. Some of them hang indefinitely… but a debugging run found that they were expecting input on an open port! I guess they were used internally for debugging. Still, it’s better than nothing as I didn’t think any tests were available given how closely SUN guards its TCKs!

I’ve bundled everything, including the source and tests into a single jar, openjdk_071012-httpserver.jar.

If you distribute this as part of your application, you must release your application under the GPL. I don’t recommend using this on a production system… my intention was just to have something that would allow our code to compile under Java 5.


This entry was posted by by Sam on Saturday, October 27th, 2007 at 9:14 pm, and is filed under GPL, HTTP, Java, Java 5, Java 6, OSS, Open Source, OpenJDK, SSL, Server. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.



4 comments on “HTTP Server API, backport to Java 5”

Why not use lighttpd? It’s tiny enough

KesheR, lighttpd is an HTTP Server like Apache… it’s not a Java library for quickly deploying lightweight apps that don’t need the Servlet API (i.e. Tomcat).

hello sam,

the http://thinktankmaths.co.uk/downloads/openjdk_071012-httpserver.jar

gives me a 404 ? did you decide to remove it ?

thanks, tom

Leave a comment

Markdown is supported.

To include code snippets in your comment, use

<pre><code># lang java
... code here ...
</code></pre>

or use 4 spaces at the start of the line instead of using code and pre tags.

Comment feed: RSS