Undertow
Undertow is a lightweight, high-performance web server written in Java, providing both blocking and non-blocking APIs built on NIO.
Designed around a modular, composition-based architecture, Undertow lets you build anything from a minimal non-blocking handler chain to a full Jakarta Servlet container—or mix both in the same deployment. It is fully embeddable with a fluent builder API, giving your application complete lifecycle control.
Undertow is a Commonhaus Foundation project and powers the web layer of WildFly and thousands of cloud-native Java microservices.
Why Undertow
- Lightweight & High Performance
-
Built on XNIO with a minimal memory footprint and low-overhead handler chains, delivering high throughput without paying for features you don’t use.
- Jakarta Servlet Support
-
Full support for modern Jakarta Servlet specifications (including embedded Servlet), with the unique ability to mix Servlets and native non-blocking handlers side by side.
- Composable Handler Architecture
-
Configure servers by chaining small, single-purpose HttpHandler components together—giving you complete control over routing, security, compression, and lifecycle.
- Embeddable by Design
-
Embed Undertow in any JVM application or run it standalone in just a few lines of code using clean, fluent builder APIs.
- HTTP/2 & WebSockets
-
Native, out-of-the-box support for HTTP/2, HTTP Upgrade multiplexing, and full Jakarta WebSocket standards.
- Built-in Reverse Proxy
-
Production-ready reverse proxy and load-balancing handlers with connection pooling, health checks, and protocol bridging right out of the box.
Show me the code
Build and start a non-blocking HTTP server in a few lines of Java:
public class HelloWorldServer {
public static void main(String[] args) {
Undertow server = Undertow.builder()
.addHttpListener(8080, "localhost")
.setHandler(exchange -> {
exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/plain");
exchange.getResponseSender().send("Hello World");
})
.build();
server.start();
}
}
@WebServlet("/hello")
public class HelloServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
resp.setContentType("text/plain");
resp.getWriter().write("Hello from Jakarta Servlet");
}
}
// Deploy with embedded Servlet container
DeploymentInfo deployment = Servlets.deployment()
.setClassLoader(HelloServlet.class.getClassLoader())
.setContextPath("/")
.setDeploymentName("hello.war")
.addServlets(Servlets.servlet("HelloServlet", HelloServlet.class)
.addMapping("/hello"));
DeploymentManager manager = Servlets.defaultContainer().addDeployment(deployment);
manager.deploy();
Undertow server = Undertow.builder()
.addHttpListener(8080, "localhost")
.setHandler(manager.start())
.build();
server.start();
public class ReverseProxyServer {
public static void main(String[] args) throws Exception {
LoadBalancingProxyClient proxyClient = new LoadBalancingProxyClient()
.addHost(new URI("http://backend1:8080"))
.addHost(new URI("http://backend2:8080"));
Undertow server = Undertow.builder()
.addHttpListener(8080, "localhost")
.setHandler(ProxyHandler.builder()
.setProxyClient(proxyClient)
.build())
.build();
server.start();
}
}