Don’t Sleep on the Simple Web Server – The New Stack

When Oracle released Java 18 last month, one of its slightly overlooked but interesting new features was the Simple Web Server.

Oracle introduced the Simple Web Server through Java Enhancement Protocol (JEP) 408. The JEP 408 proposal describes the Simple Web Server as providing a command-line tool and API to start a minimal web server that only serves static files. There is no CGI or servlet-like functionality available.

For prototyping, testing, etc.

The tool is intended for use in prototyping, ad hoc coding and testing, especially in educational settings, Oracle said.

The Simple Web Server is a minimal HTTP static file server that was added in JEP 408 to the jdk.httpserve module, said Julia Boes, OpenJDK developer at Oracle’s Java Platform Group, in a blog post. It serves a single directory hierarchy and only serves static files over HTTP/1.1; dynamic content and other HTTP versions are not supported, she wrote.

“The web server specification is informed by the overarching goal of making the JDK [Java Development Kit] more accessible,” Boes said. “The server is an out-of-the-box tool with easy setup and minimal functionality that lets you get started and focus on the task at hand. The simplistic design also avoids confusion with feature-rich or quality servers. commercial – after all, much better alternatives exist for production environments, and simple web server is not the right choice in such cases.

Indeed, another goal is to reduce developers’ activation energy and make the JDK more accessible. A third goal is to provide a default implementation via the command line with a small API for programmatic creation and customization.

Command line and API

The simplified server can be used via the dedicated command line tool jwebserver or programmatically via its API. From the command line, use the command $ jwebserver to start the simple web server. Oracle is also defining new APIs for creating servers and custom handling requests with the new functionality.

“The Simple Web Server was designed to make prototyping, debugging, and testing easier, and I hope the combination of a minimal command-line tool and a flexible set of API points will achieve that goal,” Boes said. “The jwebserver tool brings basic server functionality to the command line, while the Simple Web Server API points offer fully customizable server components that can help solve less common scenarios and special cases.”

Aimed at new developers

The new tool is especially useful for developers new to Java and for educators, as it makes it easy for students to get started, start a web server, and have all the infrastructure they need to write a Java application. simply, Georges Saab, vice president of software development for the Java Platform Group at Oracle, told The New Stack.

“The Simple Web Server represents our ongoing investments to make Java more accessible to the next generation of developers. And to make it easier for students and teachers to learn Java. And to do something cool without having to introduce a lot of new concepts,” Chad Arimura, vice president of developer relations at Oracle, told The New Stack.

For example, spinning up a web server, downloading NGINX and running it, and then writing Java code on top of that and deploying it, involves several steps that students don’t want to learn, he said, noting that the server is probably his favorite feature in Java 18.

“With a simple web server, you download the JDK, type jwebserver, it triggers a loopback to your interface for the localhost, and it automatically generates an index.html file with some java code, and you’re off to the races with almost without thinking. And then you can start inserting your own code,” Arimura said. “So I thought that was pretty cool in conjunction with Java. With the JShell tool, you can now do a lot of really cool things from the command line that you couldn’t do before.

However, seasoned Java pros like Simon Ritter, deputy technical director of Azul Systems, said they were a bit confused by what appears to be a change of direction with the new simple server.

“I get it, it’s for testing,” Ritter said. “But I know when we got to JDK 9, one of the big things the OpenJDK developers said was that we really wanted to try and remove all the superfluous stuff that we put in the JDK and kind of the basics you need to develop Java. And, you know, that’s great, except now we’re kind of going the other way. Let’s include a web server. Why? I mean , do we really need a web server?”

Still, the JEP 408 description spells out Oracle’s thinking on the matter.

“It is not an objective to provide a feature-rich or commercial-grade server,” the description reads. “Much better alternatives exist in the form of server frameworks (eg Jetty, Netty and Grizzly) and production servers (eg Apache Tomcat, Apache httpd and NGINX). These comprehensive, performance-optimized technologies require effort to set up, which we want to avoid. »

However, with a small out-of-the-box server, developers, especially beginners, can perform:

  • Web development testing, where a local test server is used to simulate a client-server setup.
  • Web service or application testing, where static files are used as API stubs in a directory structure that mirrors RESTful URLs and contains dummy data.
  • Informal browsing and file sharing between systems to, for example, find a directory on a remote server from your local machine.

“Python, Ruby, PHP, Erlang, and many other platforms offer out-of-the-box servers run from the command line,” the JEP 408 description reads. “This variety of existing alternatives demonstrates a recognized need for this type of tool.”

Overall, this represents Oracle’s good and steady progress with Java, which developers and CxOs expect from a programming language platform vendor, said Constellation Research analyst Holger Mueller.

“Adding a simple web server is critical for developer speed because developers can test and validate code earlier, easier, and faster,” he noted.

Packed with features

In addition to Simple Web Server, Java 18 contains thousands of performance, stability, and security enhancements, including nine enhancements to improve developer productivity.

These include the ability to add code snippets to the Java API documentation (JEP 413), which makes it easy to add source code examples to the API documentation, and Simple Web Server ( JEP 408) for prototyping and testing. Developers can also try out two incubation modules: Vector API (JEP 417) and Foreign Function and Memory API (JEP 419), as well as a preview feature: Pattern Matching for Switch (JEP 420) .

However, “it’s not necessarily about features,” said Sharat Chander, senior director of native Java and container product management and developer relations at Oracle, “because with every release, c is also a question of performance”. Chander said, “Just having the ability to use a new runtime to get out-of-the-box improvements over a previous version on a new one is, for me, a reason to follow because the performance is so essential to modern application development.”

Pattern Match for Switch

JEP 420 is in its second preview. It provides pattern matching for expressions and switch statements, as well as pattern language extensions. Extending pattern matching to switch allows an expression to be tested against a number of patterns, each with a specific action, so that complex data-driven queries can be expressed in a concise and safe way.

Saab called pattern matching for the switch one of its favorite features. “It’s in the arc of supporting immutable data and reasoning about it,” he said. “The style of coding it enables is really convenient and intuitive.” Saab said, “While this is kind of a small piece of a larger set of improvements to Java in terms of programming, I think in a few years we’ll look back and say, ‘Oh , my God, how can we live without it”, right?”

Overall, with its six-month release cadence for Java, Oracle provides a smooth continuation of work started with previous releases, such as pattern matching for the switch.

“With JEP 420, including extended pattern matching that will help Java developers do much more with data-driven queries – a capability and mindset that will serve Java well in an increasingly oriented application market data,” said Omdia analyst Brad Shimmin. . “Either way, this ‘slow burn’ approach to rolling updates is crucial, as it allows developers to start using fully integrated, newly introduced features faster and without risk or complexity.”

Featured image via Pixabay.