Convert Figma logo to code with AI

undertow-io logoundertow

High performance non-blocking webserver

3,576
986
3,576
72

Top Related Projects

3,040

WildFly Application Server

Spring Framework

Quick Overview

Undertow is a flexible, high-performance web server written in Java. It is designed to be embedded within applications, providing a lightweight and scalable HTTP server that can be easily integrated into a variety of Java-based projects.

Pros

  • Lightweight and Scalable: Undertow is designed to be highly efficient, with a small footprint and the ability to handle a large number of concurrent connections.
  • Flexible and Extensible: Undertow provides a modular architecture that allows developers to easily extend and customize its functionality to meet their specific needs.
  • High-Performance: Undertow is built on top of the Netty networking framework, which provides a high-performance, asynchronous I/O implementation.
  • Supports Modern Web Technologies: Undertow supports a wide range of web technologies, including HTTP/2, WebSockets, and HTTP/1.1.

Cons

  • Limited Documentation: While Undertow has a growing community, the documentation can be sparse in some areas, which may make it challenging for new users to get started.
  • Steep Learning Curve: Undertow's flexibility and extensibility can also make it more complex to set up and configure, especially for developers who are new to the project.
  • Lack of Widespread Adoption: Compared to other popular Java web servers like Tomcat or Jetty, Undertow has a smaller user base, which may limit the availability of third-party libraries and resources.
  • Potential Performance Overhead: While Undertow is designed to be highly performant, the use of its advanced features, such as HTTP/2 or WebSockets, may introduce some performance overhead in certain scenarios.

Code Examples

Here are a few examples of how to use Undertow in your Java projects:

Serving a Simple HTTP Response

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();

This code sets up a simple Undertow server that listens on localhost:8080 and responds with the message "Hello, World!" when a client connects.

Handling WebSocket Connections

Undertow server = Undertow.builder()
    .addHttpListener(8080, "localhost")
    .setHandler(path("websocket").addExactPath("/echo")
        .to(WebSocketProtocolHandlerFactory.builder()
            .addProvider(new EchoWebSocketProtocolProvider())
            .build()))
    .build();

server.start();

This example demonstrates how to set up a WebSocket endpoint that echoes back any messages sent to it.

Serving Static Files

Undertow server = Undertow.builder()
    .addHttpListener(8080, "localhost")
    .setHandler(resource(new ClassPathResourceManager(getClass().getClassLoader(), "static"))
        .setDirectoryListingEnabled(true))
    .build();

server.start();

This code sets up an Undertow server that serves static files from the static directory in the classpath.

Getting Started

To get started with Undertow, you can add the following dependency to your Maven or Gradle project:

<dependency>
    <groupId>io.undertow</groupId>
    <artifactId>undertow-core</artifactId>
    <version>2.3.0.Final</version>
</dependency>

Once you have the dependency set up, you can start building your Undertow-based application. The examples provided earlier should give you a good starting point for common use cases. For more advanced usage and configuration options, refer to the Undertow documentation.

Competitor Comparisons

3,040

WildFly Application Server

Pros of Wildfly

  • Wildfly is a full-featured application server that provides a comprehensive set of features, including support for various Java EE specifications, security, and management capabilities.
  • Wildfly has a large and active community, with extensive documentation and a wide range of third-party integrations.
  • Wildfly is designed to be highly scalable and reliable, making it suitable for enterprise-level applications.

Cons of Wildfly

  • Wildfly has a larger footprint and may require more resources (CPU, memory) compared to Undertow, which is a lightweight web server.
  • The configuration and deployment process for Wildfly may be more complex than Undertow, especially for simpler web applications.
  • Wildfly may have a steeper learning curve for developers who are new to Java EE and application server environments.

Code Comparison

Undertow (Servlet Initialization):

Undertow server = Undertow.builder()
    .addHttpListener(8080, "localhost")
    .setHandler(path()
        .addPrefixPath("/", resource(new ClassPathResourceManager(Undertow.class.getClassLoader(), "webapp")))
        .addPrefixPath("/servlets", servlet(new MyServlet(), "/myservlet")))
    .build();
server.start();

Wildfly (Servlet Deployment):

<deployment>
    <deployment-name>my-web-app.war</deployment-name>
    <content>
        <resource-root path="my-web-app.war"/>
    </content>
    <subsystem xmlns="urn:jboss:domain:undertow:10.0">
        <servlet-container name="default">
            <jsp-config/>
            <websockets/>
        </servlet-container>
        <handlers>
            <file name="welcome-content" path="${jboss.home.dir}/welcome-content"/>
        </handlers>
        <server name="default-server">
            <http-listener name="default" socket-binding="http"/>
            <host name="default-host" alias="localhost">
                <location name="/" handler="welcome-content"/>
                <location name="/myservlet" handler="servlet"/>
            </host>
        </server>
    </subsystem>
</deployment>

Spring Framework

Pros of Spring Framework

  • Comprehensive and feature-rich framework for building enterprise-level applications
  • Extensive ecosystem of libraries and tools for various aspects of application development
  • Robust support for dependency injection, transaction management, and other enterprise-level features

Cons of Spring Framework

  • Steep learning curve, especially for beginners
  • Can be overkill for smaller, simpler applications
  • Increased complexity and overhead compared to more lightweight frameworks

Code Comparison

Spring Framework:

@Configuration
public class MyConfig {
    @Bean
    public MyService myService() {
        return new MyServiceImpl();
    }
}

Undertow:

Undertow server = Undertow.builder()
    .addHttpListener(8080, "localhost")
    .setHandler(new HttpHandler() {
        @Override
        public void handleRequest(final HttpServerExchange exchange) throws Exception {
            exchange.getResponseSender().send("Hello World");
        }
    })
    .build();
server.start();

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Undertow

Undertow is a Java web server based on non-blocking IO. It consists of a few different parts:

  • A core HTTP server that supports both blocking and non-blocking IO
  • A Servlet 4.0/5.0/6.0 implementation
  • A JSR-356/Jakarta 2.0 compliant Web Socket implementation

Website: http://undertow.io

Issues: https://issues.redhat.com/projects/UNDERTOW

Project Lead: Flavia Rainone frainone@redhat.com

Undertow Dev Group: https://groups.google.com/g/undertow-dev/ (you can access archived discussions of old undertow-dev mail list here)

Zulip Chat: https://wildfly.zulipchat.com stream #undertow

Notifying Security Relevant Bugs

If you find a bug that has a security impact, please notify us sending an email to Red Hat SecAlert secalert@redhat.com with a copy to Flavia Rainone frainone@redhat.com. This will ensure the bug is properly handled without causing unnecessary negative impacts for the Undertow's user base.

You can find more information about the security procedures at this page.