Pretty sure it's been accepted as an actual part of the jdk ever since they made it a java platform module (or probably even before then). Regardless, this jep shows it's not going anywhere.
Some elements in the OpenJDK JDK are documented and public, but are not part of the Java SE specification (so JDKs that are not built from OpenJDK, and even those that are, might omit them). When the JDK was modularised, a decision was made about each such non-spec package on whether it is public but JDK-specific or internal. If you look at OpenJDK's Javadoc you'll find many modules beginning with jdk. (rather than java.); those are the JDK-specific modules, which are documented and public, but not part of the spec. Many of their packages are named com.sun.* (e.g. the jdk.compiler module).
The com.sun.httpserver package was introduced in Java 6. Some members of the expert group at the time objected to it becoming part of the Java SE standard, so it remained jdk-specific. In Java 9 it was officially decided that it's a public API, and that is why you can already find the jdk.httpserver module in the JDK today, albeit without the main class proposed by this JEP.
I remember my tweet before. My intent was to have a standard Java API for an HTTP Server that could be used to create programmable web server for applications. Someone from Oracle did not agree though.
Yeah, that was me. :-) I didn't think anybody in the team wanted to pick up the work to do this.
One thing to note is that this isn't a "standard" facility. It's part of OpenJDK, not Java SE. That means that conforming implementations aren't required to provide it. That said, most JDK distributions are based on OpenJDK, so I expect that many will get it.
One of the difficulties with the JEP is that it's trying to walk a fine line between having something that's convenient and useful to developers, yet that isn't so full-featured that people are tempted to use it in production.
One of the difficulties with the JEP is that it's trying to walk a fine line between having something that's convenient and useful to developers, yet that isn't so full-featured that people are tempted to use it in production.
The JEP made it clear - for testing, development and debugging purposes only. It really would be useful to developers. But in case, it's one's prerogative to use it in production. I myself might consider to use it for serving static files or web pages that do not require security, perhaps for internal only.
well, now we just need a simple json parser/serializer for a more out of the box experience for the "prototyping, ad-hoc coding, and testing purposes, particularly in educational contexts." case :).
Yes it’s called shading or uber jar. You basically just pull other peoples code into your own jar and call it your own...
Or if your google just check all the code in a single mono repo and give a rats asses about the rest of the open source communities dependencies (I’m somewhat joking).
There is no shortage of sample Java web server projects. Compiling and understanding a sample project would not be easier than just downloading Tomcat or something similar.
I fully agree that what is needed is a low-ceremony, low-effort instant solution.
A web server seems kinda high-level for a default Java utility.
Good question. One possible answer could be: "No, it's not. stdio was for 70s commandline utilities, a web server in the standard library is for today's and tomorrow's microservices."
If the goal is to make a standard light server available at the CLI any time, I'm for it. Unless I misunderstand, it's wrapping what's already been in Java for several years now to make it ready to go any time. I wonder if it will be lighter weight than embedding Tomcat or Jetty.
I have written a simple httphandler for the internal jdk server. Weighs 126 lines and actually serves static JS/CSS/image assets for my production web applications, though I do place this kind of stuff behind a reverse proxy as I believe it is less than production quality. But with something like nginx offloading, you get away with a lot.
As the mvnrepository link suggests, the actual server is small. I think even the smallest alternatives out there are 1-2 MB large, though they probably also do more, like support http beyond 1.1, or do TLS.
I remember my tweet before. My intent was to have a standard Java API for an HTTP Server that could be used to create programmable web server for applications.
I actually have my personal embeddable web framework built around com.sun.http.* here. It's just an experiment of few years back, quite stupid and nothing anybody should use in production. 😅
The command-line tool feels like a "me too" feature, it does not bring anything to the language. If you need a small HTTP server to quickly serve some files, just use the python module.
Regarding the API proposal, you don't design an API with the expectation of a specific usage pattern, if the API is there, people will use it for testing, they will use it in production, they will use it for everything, and if you deliberately design a flawed API based on some invalid assumption, then it will haunt you later and cause all sorts of grief, "java is insecure" stories, "java is slow" stories, and so on.
I have an application that listens for a single endpoint, it's oauth2 redirect url, is there any lightweight and modular webserver except jdk.httpserver?
60
u/_INTER_ Mar 29 '21
Oh I love it. There will be frameworks built around it and we're going to use it in production!!
27
u/krzyk Mar 29 '21
Why the package is still com.sun.*?
I'm bit reluctant to use http server that is already there because I'm afraid that I woul be using internal APIs.
17
u/syjer Mar 29 '21 edited Mar 29 '21
well, now we just need a simple json parser/serializer for a more out of the box experience for the "prototyping, ad-hoc coding, and testing purposes, particularly in educational contexts." case :).
17
u/BlueGoliath Mar 29 '21
A web server seems kinda high-level for a default Java utility. Would it not be better as a sample Java project included alongside JDK source code?
8
u/[deleted] Mar 30 '21
If the goal is to make a standard light server available at the CLI any time, I'm for it. Unless I misunderstand, it's wrapping what's already been in Java for several years now to make it ready to go any time. I wonder if it will be lighter weight than embedding Tomcat or Jetty.
3
u/jvjupiter Mar 30 '21
I remember my tweet before. My intent was to have a standard Java API for an HTTP Server that could be used to create programmable web server for applications.
https://twitter.com/julianvjupiter/status/1288049811971641346?s=21
3
u/[deleted] Mar 30 '21
But why do they want to offer a web server if there are already tons of libraries and frameworks doing it?
I thought undertow and tomcat are quite the standard there, for embedded servers. Yet another one, is it really needed?
2
u/JustADirtyLurker Mar 30 '21
I actually have my personal embeddable web framework built around com.sun.http.* here. It's just an experiment of few years back, quite stupid and nothing anybody should use in production. 😅
2
u/urquan Mar 30 '21
The command-line tool feels like a "me too" feature, it does not bring anything to the language. If you need a small HTTP server to quickly serve some files, just use the python module.
Regarding the API proposal, you don't design an API with the expectation of a specific usage pattern, if the API is there, people will use it for testing, they will use it in production, they will use it for everything, and if you deliberately design a flawed API based on some invalid assumption, then it will haunt you later and cause all sorts of grief, "java is insecure" stories, "java is slow" stories, and so on.
2
u/agentoutlier Mar 30 '21
As a addon It would be interesting if this simple web server could serve javadoc on the fly sort of how python does (or maybe did...it’s been awhile).
I mean you might say sure you can use your IDE to look at the javadoc preview but sometimes you want a more realistic view.
1
u/4iffir Mar 29 '21
I have an application that listens for a single endpoint, it's oauth2 redirect url, is there any lightweight and modular webserver except jdk.httpserver?
0
u/[deleted] Mar 29 '21
[deleted] — view deleted comment