Skip to content

Add karaf-web, a web container based on Apache Tomcat - #3009

Open
jbonofre wants to merge 2 commits into
apache:mainfrom
jbonofre:karaf-web-tomcat
Open

jbonofre wants to merge 2 commits into
apache:mainfrom
jbonofre:karaf-web-tomcat

Conversation

@jbonofre

Copy link
Copy Markdown
Member

This PR adds karaf-web, a web container simpler than Pax Web, based on an embedded Apache Tomcat 11 (Servlet 6.1, Java 17).

The services/web module

The org.apache.karaf.services.web bundle embeds Tomcat privately (Tomcat logs to the Karaf log via the org.apache.juli.logging package of Pax Logging) and supports:

  • OSGi Servlet Whiteboard (org.osgi.service.servlet, the Jakarta version of the HTTP Whiteboard): servlets, filters (patterns, servlet names, regex, dispatchers), listeners, resources and servlet context helpers (custom contexts, handleSecurity, resources, MIME types). Shadowing by name/pattern and ranking, with the services not deployed reported with the reason. Services registered together are deployed together (100 ms debounce); the unregistration of a service waits for its undeployment.
  • Web Application Bundles (Web-ContextPath): resources read from the bundle entries, classes loaded by the bundle class loader, web.xml, web fragments, @WebServlet/@WebFilter/@WebListener, ServletContainerInitializer, default servlet and welcome files, authentication with the Karaf JAAS realm, and the ServletContext service with the osgi.web.* properties.
  • Configuration with the org.apache.karaf.services.web PID: host, HTTP/HTTPS ports, keystore, max threads, session timeout, JAAS realm, undeploy timeout. A configuration change restarts Tomcat.
  • Commands: web:context-list, web:servlet-list and web:filter-list.

Not supported: JSP, WAR deployment (war:/webbundle:), whiteboard error pages and preprocessors, osgi.http.whiteboard.target, HttpServiceRuntime, and the javax OSGi HTTP Service.

Distribution

  • New karaf-web feature in the standard features (the Servlet API and the org.apache.karaf.services.web bundle).
  • karaf-web is an installed feature of the karaf-light distribution (feature:install karaf-web), not a boot feature.
  • The manual gets a new "Karaf Web Container (Apache Tomcat)" chapter, and the karaf-light README mentions the feature.

karaf-web is an alternative to the Pax Web features: they use the same default port and the same web:* command names, so they should not be installed together.

Tests

  • Unit tests for the configuration, the context paths, the bundle resource set and the resource servlet (on a real Tomcat).
  • New KarafWebTest itest (context list, whiteboard servlet deployment and synchronous undeployment) and StandardFeaturesTest#installKarafWebFeature.
  • Tested manually in karaf-light: whiteboard servlets/filters/resources/helpers, WABs with web.xml, annotations and BASIC authentication, HTTPS with a PKCS12 keystore, configuration changes, Karaf restart and feature uninstall.

MavenTest fails on main already (no version for jakarta.servlet/jakarta.servlet-api); with the Servlet API dependency added to the itests it gets further, but it then fails to load KarafTestSupport in its probe, a separate issue.

@github-actions

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Test Results

  744 files  +15    744 suites  +15   1h 6m 35s ⏱️ + 1m 3s
1 094 tests +17    960 ✅ +17  134 💤 ±0  0 ❌ ±0 
3 282 runs  +51  2 880 ✅ +51  402 💤 ±0  0 ❌ ±0 

Results for commit 25d844b. ± Comparison against base commit 2aabe51.

♻️ This comment has been updated with latest results.

The new services/web module provides a web container simpler than
Pax Web, embedding Apache Tomcat 11 (Servlet 6.1). It supports the OSGi
Servlet Whiteboard (servlets, filters, listeners, resources and servlet
context helpers) and the Web Application Bundles (web.xml, web
fragments, annotations, ServletContainerInitializer, Karaf JAAS
authentication). It is configured with the org.apache.karaf.services.web
PID and provides the web:context-list, web:servlet-list and
web:filter-list commands.

The karaf-web feature is added to the standard features and installed in
the karaf-light distribution. The manual gets a new chapter, and itests
cover the feature installation and a whiteboard servlet.
The content length of the test resource depends on the line ending of
the checkout, \r\n on Windows with core.autocrlf.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant