Skip to content

Commit

Permalink
[#1802] Switch pax-web-api from javax to jakarta
Browse files Browse the repository at this point in the history
  • Loading branch information
grgrzybek committed Jun 12, 2023
1 parent fea4948 commit a6e033c
Show file tree
Hide file tree
Showing 25 changed files with 762 additions and 261 deletions.
115 changes: 69 additions & 46 deletions pax-web-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@
<executions>
<execution>
<!--
copy javax/servlet/resources and javax/servlet/jsp/resources which will be
copy jakarta/servlet/resources and jakarta/servlet/jsp/resources which will be
available to slightly modified org.apache.tomcat.util.descriptor.DigesterFactory
Originally Tomcat load these resources through java.lang.Class.getResource() method
of javax.servlet.ServletContext and javax.servlet.jsp.JspContext classes
of jakarta.servlet.ServletContext and jakarta.servlet.jsp.JspContext classes
-->
<id>copy-selected-resources</id>
<phase>process-resources</phase>
Expand All @@ -101,14 +101,14 @@
<outputDirectory>${project.build.outputDirectory}/META-INF/resources</outputDirectory>
<resources>
<resource>
<directory>${project.build.directory}/unpack-deps/tomcat-servlet-api/javax/servlet/resources</directory>
<directory>${project.build.directory}/unpack-deps/tomcat-servlet-api/jakarta/servlet/resources</directory>
<includes>
<include>*.xsd</include>
<include>*.dtd</include>
</includes>
</resource>
<resource>
<directory>${project.build.directory}/unpack-deps/tomcat-jsp-api/javax/servlet/jsp/resources</directory>
<directory>${project.build.directory}/unpack-deps/tomcat-jsp-api/jakarta/servlet/jsp/resources</directory>
<includes>
<include>*.xsd</include>
<include>*.dtd</include>
Expand All @@ -126,18 +126,26 @@
<configuration>
<instructions>
<Import-Package>
<!-- ranges indicate Servlet API 3.1+ (JavaEE 7+) -->
javax.servlet;version="[3.1,5)",
javax.servlet.annotation;version="[3.1,5)",
javax.servlet.http;version="[3.1,5)",
<!-- ranges indicate Servlet API 6.0+ (JakartaEE 10+) -->
jakarta.servlet;version="[6,7)",
jakarta.servlet.annotation;version="[6,7)",
jakarta.servlet.http;version="[6,7)",

<!-- ranges indicate we can work with OSGi Core R6+ -->
org.osgi.dto;version="[1.0,2)",
org.osgi.framework;version="[1.8,2)",
<!-- OSGi Core R8+ -->
org.osgi.dto;version="[1.1,2)",
org.osgi.framework;version="[1.10,2)",
org.osgi.framework.wiring;version="[1.2,2)",

<!-- OSGi CMPN R8.1 140 Jakarta Servlet packages (formerly known as Whiteboard) -->
org.osgi.service.servlet.context;version="2.0.0",
org.osgi.service.servlet.runtime;version="2.0.0",
org.osgi.service.servlet.runtime.dto;version="2.0.0",
org.osgi.service.servlet.whiteboard;version="2.0.0",
org.osgi.service.servlet.whiteboard.annotations;version="2.0.0",
org.osgi.service.servlet.whiteboard.propertytypes;version="2.0.0",

<!-- from pax-logging-api -->
org.slf4j;version="[1.7,2)"
org.slf4j;version="[2,3)"
</Import-Package>
<Export-Package>
<!-- pax-web-api -->
Expand All @@ -146,18 +154,7 @@
org.ops4j.pax.web.service.whiteboard;version="${pax-web.osgi.version}",
org.ops4j.pax.web.utils;version="${pax-web.osgi.version}",
<!-- Special export for org.keycloak:keycloak-osgi-adapter:18.0.x -->
org.ops4j.pax.web.service;version="7.4",

<!-- re-export OSGi CMPN R7 102 HTTP Service packages -->
org.osgi.service.http;version="1.2.1",

<!-- re-export OSGi CMPN R7 140 HTTP Whiteboard packages -->
org.osgi.service.http.context;version="1.1",
org.osgi.service.http.runtime;version="1.1",
org.osgi.service.http.runtime.dto;version="1.1",
org.osgi.service.http.whiteboard;version="1.1",
org.osgi.service.http.whiteboard.annotations;version="1.1",
org.osgi.service.http.whiteboard.propertytypes;version="1.1"
<!-- org.ops4j.pax.web.service;version="7.4",-->
</Export-Package>
<Include-Resource>
{maven-resources},
Expand Down Expand Up @@ -216,8 +213,23 @@
<artifactId>osgi.core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.namespace.extender</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.http</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.servlet</artifactId>
<scope>provided</scope>
</dependency>

<!-- JavaEE -->
<!-- JakartaEE -->

<dependency>
<groupId>jakarta.servlet</groupId>
Expand All @@ -234,38 +246,49 @@
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<artifactId>log4j-slf4j2-impl</artifactId>
<scope>test</scope>
</dependency>

<!-- Tomcat -->

<!-- <dependency>-->
<!-- &lt;!&ndash;-->
<!-- This dependency is used to take javax.servlet.resources package with XSDs/DTDs into pax-web-tomcat-common-->
<!-- to satisfy the DigesterFactory-->
<!-- &ndash;&gt;-->
<!-- <groupId>org.apache.tomcat</groupId>-->
<!-- <artifactId>tomcat-servlet-api</artifactId>-->
<!-- <scope>provided</scope>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- &lt;!&ndash;-->
<!-- This dependency is used to take javax.servlet.jsp.resources package with XSDs/DTDs into pax-web-tomcat-common-->
<!-- to satisfy the DigesterFactory-->
<!-- &ndash;&gt;-->
<!-- <groupId>org.apache.tomcat</groupId>-->
<!-- <artifactId>tomcat-jsp-api</artifactId>-->
<!-- <scope>provided</scope>-->
<!-- </dependency>-->
<dependency>
<!--
This dependency is used to take jakarta.servlet.resources package with XSDs/DTDs into pax-web-api
to satisfy the DigesterFactory
-->
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<!--
This dependency is used to take jakarta.servlet.jsp.resources package with XSDs/DTDs into pax-web-api
to satisfy the DigesterFactory
-->
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jsp-api</artifactId>
<scope>provided</scope>
</dependency>

<!-- Testing -->


<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${dependency.org.assertj}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
Expand Down
42 changes: 21 additions & 21 deletions pax-web-api/readme.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
This bundle has these purposes:

* re-export packages specified in OSGi CMPN R7 102 "Http Service Specification"
** `org.osgi.service.http` 1.2
** `org.osgi.service.servlet` 1.2
* re-export packages specified in OSGi CMPN R7 140 "Http Whiteboard Specification"
** `org.osgi.service.http.context` 1.1
** `org.osgi.service.http.runtime` 1.1
** `org.osgi.service.http.runtime.dto` 1.1
** `org.osgi.service.http.whiteboard` 1.1
** `org.osgi.service.http.whiteboard.annotations` 1.1
** `org.osgi.service.http.whiteboard.propertytypes` 1.1
** `org.osgi.service.servlet.context` 1.1
** `org.osgi.service.servlet.runtime` 1.1
** `org.osgi.service.servlet.runtime.dto` 1.1
** `org.osgi.service.servlet.whiteboard` 1.1
** `org.osgi.service.servlet.whiteboard.annotations` 1.1
** `org.osgi.service.servlet.whiteboard.propertytypes` 1.1
* provide additional interfaces (like `org.ops4j.pax.web.service.WebContainer`) extending standard specification
* provide some utilities used throughout PAX WEB (`org.ops4j.pax.web.utils` package)
Expand Down Expand Up @@ -295,19 +295,19 @@ Since OSGi CMPN R6, Http Whiteboard is an official specification and Pax Web (wh

CMPN R7 Http Whiteboard Specification allows registration (as OSGi services) of the following services:

* 140.4 Registering Servlets: `javax.servlet.Servlet` services
* 140.4 Registering Servlets: `jakarta.servlet.Servlet` services
* 140.5 Registering Servlet Filters:
** `javax.servlet.Filter` services
** `org.osgi.service.http.whiteboard.Preprocessor` services handled before security processing
** `jakarta.servlet.Filter` services
** `org.osgi.service.servlet.whiteboard.Preprocessor` services handled before security processing
* 140.6 Registering Resources: any objects with `osgi.http.whiteboard.resource.pattern` and `osgi.http.whiteboard.resource.prefix` service properties. Actual service is irrelevant
* 140.7 Registering Listeners: services with these subinterfaces of `java.util.EventListener`:
** `javax.servlet.ServletContextListener`
** `javax.servlet.ServletContextAttributeListener`
** `javax.servlet.ServletRequestListener`
** `javax.servlet.ServletRequestAttributeListener`
** `javax.servlet.http.HttpSessionListener`
** `javax.servlet.http.HttpSessionAttributeListener`
** `javax.servlet.http.HttpSessionIdListener`
** `jakarta.servlet.ServletContextListener`
** `jakarta.servlet.ServletContextAttributeListener`
** `jakarta.servlet.ServletRequestListener`
** `jakarta.servlet.ServletRequestAttributeListener`
** `jakarta.servlet.http.HttpSessionListener`
** `jakarta.servlet.http.HttpSessionAttributeListener`
** `jakarta.servlet.http.HttpSessionIdListener`

When registering the above servives, all additional and required information should be specified as OSGi service properties and/or Java annotations on the services. Annotations where specified only in R7 Whiteboard specification. Version R6 specified only service registration properties.

Expand All @@ -319,11 +319,11 @@ This may be called _explicit whiteboard approach_ (where registration parameters

=== Context

Java Servlet API specification defines `javax.servlet.ServletContext` interface which roughly means a distinguished namespace (with _context path_) where servlets, filters and other _web elements_ may be specified.
Java Servlet API specification defines `jakarta.servlet.ServletContext` interface which roughly means a distinguished namespace (with _context path_) where servlets, filters and other _web elements_ may be specified.

OSGi CMPN Http Service specification defines `org.osgi.service.http.HttpContext` interface that should _influence_ the `javax.servlet.ServletContext` associated with the servlets (and resources) being registered.
OSGi CMPN Http Service specification defines `org.ops4j.pax.web.service.http.HttpContext` interface that should _influence_ the `jakarta.servlet.ServletContext` associated with the servlets (and resources) being registered.

OSGi CMPN Whiteboard specification defines `org.osgi.service.http.context.ServletContextHelper` interface that plays the same role as the above `HttpContext`, but which is dedicated for Whiteboard specification.
OSGi CMPN Whiteboard specification defines `org.osgi.service.servlet.context.ServletContextHelper` interface that plays the same role as the above `HttpContext`, but which is dedicated for Whiteboard specification.
This `ServletContextHelper` is explicitly associated with _context path_ (using `osgi.http.whiteboard.context.path` service registration property) - unlike `HttpContext` which doesn't have a _context path_.

OSGi CMPN HTTP Service specification (102.2 Registering servlets) mentions:
Expand All @@ -333,7 +333,7 @@ OSGi CMPN HTTP Service specification (102.2 Registering servlets) mentions:
[...]. Thus, Servlet objects registered with the same HttpContext object must also share the same ServletContext object.
----

Without actually specifying what _the same_ means. `felix.http` implements `org.osgi.service.http.HttpService.createDefaultHttpContext()` by returning _new_ instance of `org.apache.felix.http.base.internal.service.DefaultHttpContext` on each call...
Without actually specifying what _the same_ means. `felix.http` implements `org.ops4j.pax.web.service.http.HttpService.createDefaultHttpContext()` by returning _new_ instance of `org.apache.felix.http.base.internal.service.DefaultHttpContext` on each call...

OSGi CMPN Whiteboard specification (140.10 Integration with Http Service contexts) says:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import java.security.cert.CertStoreParameters;
import javax.net.ssl.SSLContext;
import javax.servlet.ServletContext;
import jakarta.servlet.ServletContext;

/**
* <p>Dedicated interface with constants related to configuration. Other constants reside
Expand Down Expand Up @@ -65,28 +65,28 @@ public interface PaxWebConfig {
* This property specifies the port used for servlets and resources accessible via HTTP.
* The default value for this property is {@code 80} according to specification, but we'll use {@code 8080}.
*/
String PID_CFG_HTTP_PORT = "org.osgi.service.http.port";
String PID_CFG_HTTP_PORT = "org.osgi.service.servlet.port";

/**
* This property specifies the port used for servlets and resources accessible via HTTPS.
* The default value for this property is {@code 443} according to specificaton, but we'll use {@code 8443}.
*/
String PID_CFG_HTTP_PORT_SECURE = "org.osgi.service.http.port.secure";
String PID_CFG_HTTP_PORT_SECURE = "org.osgi.service.servlet.port.secure";

/** Should the default non-secure port be enabled? */
String PID_CFG_HTTP_ENABLED = "org.osgi.service.http.enabled";
String PID_CFG_HTTP_ENABLED = "org.osgi.service.servlet.enabled";

/** Should the default secure port be enabled? */
String PID_CFG_HTTP_SECURE_ENABLED = "org.osgi.service.http.secure.enabled";
String PID_CFG_HTTP_SECURE_ENABLED = "org.osgi.service.servlet.secure.enabled";

/** Comma-separated list of addresses to bind listeners/connectors to. Defaults to {@code 0.0.0.0} */
String PID_CFG_LISTENING_ADDRESSES = "org.ops4j.pax.web.listening.addresses";

/** Name to use as <em>default</em> (non-secure) connector, defaults to {@code default}. */
String PID_CFG_HTTP_CONNECTOR_NAME = "org.osgi.service.http.connector.name";
String PID_CFG_HTTP_CONNECTOR_NAME = "org.osgi.service.servlet.connector.name";

/** Name to use as <em>secure</em> connector, defaults to {@code secureDefault}. */
String PID_CFG_HTTP_SECURE_CONNECTOR_NAME = "org.osgi.service.http.secure.connector.name";
String PID_CFG_HTTP_SECURE_CONNECTOR_NAME = "org.osgi.service.servlet.secure.connector.name";

/**
* Jetty: {@code org.eclipse.jetty.server.AbstractConnector#setIdleTimeout(long)}
Expand Down Expand Up @@ -119,7 +119,7 @@ public interface PaxWebConfig {
/**
* Jetty: adds {@code org.eclipse.jetty.server.ForwardedRequestCustomizer} to {@code HttpConfiguration}
*/
String PID_CFG_HTTP_CHECK_FORWARDED_HEADERS = "org.osgi.service.http.checkForwardedHeaders";
String PID_CFG_HTTP_CHECK_FORWARDED_HEADERS = "org.osgi.service.servlet.checkForwardedHeaders";

/**
* Comma-separated list of virtual hosts to set on <em>every deployed context</em> if the context itself
Expand Down Expand Up @@ -162,7 +162,7 @@ public interface PaxWebConfig {
String BUNDLE_CONTEXT_PROPERTY_WAR_EXTENDER_JARS_TO_SCAN = "org.ops4j.pax.web.extender.war.jarsToScan";

/**
* <p>Defines the type of TCCL that should be set for service methods (like {@link javax.servlet.Servlet#service}).
* <p>Defines the type of TCCL that should be set for service methods (like {@link jakarta.servlet.Servlet#service}).
* It can take two values:<ul>
* <li>{@code servlet} (the default, assumed value) - {@link ServletContext#getClassLoader()} returns
* only the bundle's class loader for given servlet/filter, but TCCL is set to servlet context's classloader</li>
Expand Down
Loading

0 comments on commit a6e033c

Please sign in to comment.