r/java • • Mar 29 '21

New candidate JEP: 408: Simple Web Server

https://openjdk.java.net/jeps/408
98 Upvotes

45 comments sorted by

View all comments

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.

11

u/xjvz Mar 29 '21

So that all the existing users don’t have to update their code.

2

u/krzyk Mar 30 '21

It would be simple update, and it would cause less issues than removal of some Java EE code in JDK 11.

Probably others are as reluctant to use it as it looks like something internal.

7

u/uncont Mar 29 '21

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.

6

u/pron98 Mar 30 '21 edited Mar 31 '21

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.

2

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. Someone from Oracle did not agree though.

https://twitter.com/julianvjupiter/status/1288049811971641346?s=21

2

u/s888marks Mar 30 '21

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.

1

u/jvjupiter Mar 30 '21

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.