Quarkus extension providing servlet support through Undertow web server for cloud-native Java applications
npx @tessl/cli install tessl/maven-io-quarkus--quarkus-undertow@3.23.0A Quarkus extension providing servlet support through the Undertow web server. This extension enables traditional Java web applications using servlet APIs (Jakarta Servlet) while maintaining Quarkus' cloud-native features including fast startup times, low memory usage, and native compilation support.
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-undertow</artifactId>
</dependency>import io.quarkus.undertow.runtime.ServletRuntimeConfig;
import io.quarkus.undertow.runtime.UndertowDeploymentRecorder;For CDI integration:
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import jakarta.inject.Inject;For build-time configuration:
import io.quarkus.undertow.spi.ServletBuildItem;
import io.quarkus.undertow.spi.FilterBuildItem;
import io.quarkus.undertow.spi.ListenerBuildItem;@WebServlet(urlPatterns = "/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 Quarkus Undertow!");
}
}@ApplicationScoped
public class ServletService {
@Inject
HttpServletRequest request;
@Inject
HttpServletResponse response;
public void handleRequest() {
// Use injected servlet objects
String method = request.getMethod();
response.setHeader("X-Processed-By", "Quarkus");
}
}@BuildStep
ServletBuildItem createServlet() {
return ServletBuildItem.builder("my-servlet", MyServlet.class.getName())
.addMapping("/api/custom")
.setAsyncSupported(true)
.build();
}The Quarkus Undertow extension is structured as a multi-module Maven project with three main components:
Core runtime functionality including servlet container management, CDI integration, and session handling.
// Runtime configuration interface
@ConfigMapping(prefix = "quarkus.servlet")
public interface ServletRuntimeConfig {
Optional<MemorySize> bufferSize();
Optional<Boolean> directBuffers();
int maxParameters();
}
// CDI producers for servlet objects
@Singleton
public class ServletProducer {
@Produces @RequestScoped
public HttpServletRequest request();
@Produces @RequestScoped
public HttpServletResponse response();
@Produces @RequestScoped
public HttpSession session();
}Extension points for registering servlets, filters, and listeners during application build.
// Register servlets at build time
public class ServletBuildItem extends MultiBuildItem {
public static Builder builder(String name, String servletClass);
public String getName();
public String getServletClass();
public List<String> getMappings();
}
// Register filters at build time
public class FilterBuildItem extends MultiBuildItem {
public static Builder builder(String name, String filterClass);
public String getName();
public String getFilterClass();
public List<FilterMappingInfo> getMappings();
}Runtime and build-time configuration options for servlet behavior, security, and performance tuning.
// Runtime configuration properties (quarkus.servlet.*)
public interface ServletRuntimeConfig {
@WithDefault("1000")
int maxParameters();
Optional<MemorySize> bufferSize();
Optional<Boolean> directBuffers();
}