HTTP Server API, backport to Java 5
October 27th, 2007 by SamWe’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.
KesheR wrote:
October 27th, 2007 at 9:36 pm