Skip to content

Commit

Permalink
[#1802] Switch pax-web-runtime from javax to jakarta
Browse files Browse the repository at this point in the history
  • Loading branch information
grgrzybek committed Jun 13, 2023
1 parent 392c018 commit 9cfa53d
Show file tree
Hide file tree
Showing 17 changed files with 139 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -302,4 +302,9 @@ public interface PaxWebConstants {
*/
String HTTP_SERVICE_CONTEXT_PROPERTY = "osgi.http.whiteboard.context.httpservice";

/**
* For compatibility purpose (OSGi CMPN 8: {@code org.osgi.service.http.runtime.HttpServiceRuntimeConstants#HTTP_SERVICE_ID})
*/
String HTTP_SERVICE_ID = "osgi.http.service.id";

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@
import org.springframework.mock.web.MockServletConfig;
import org.springframework.mock.web.MockServletContext;

import static org.junit.jupiter.api.Assertions.*;
import static org.assertj.core.api.Assertions.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class JasperJspNoScriptingTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@
import org.springframework.mock.web.MockServletConfig;
import org.springframework.mock.web.MockServletContext;

import static org.junit.jupiter.api.Assertions.*;
import static org.assertj.core.api.Assertions.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand Down
81 changes: 53 additions & 28 deletions pax-web-runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 +43,28 @@
<instructions>
<Bundle-Activator>org.ops4j.pax.web.service.internal.Activator</Bundle-Activator>
<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.descriptor;version="[3.1,5)",
javax.servlet.http;version="[3.1,5)",

<!-- ranges indicate we can work with OSGi Core R6+ -->
org.osgi.framework;version="[1.8,2)",
org.osgi.framework.dto;version="[1.0,2)",
<!-- ranges indicate Servlet API 6.0+ (JakartaEE 10+) -->
jakarta.servlet;version="[6,7)",
jakarta.servlet.annotation;version="[6,7)",
jakarta.servlet.descriptor;version="[6,7)",
jakarta.servlet.http;version="[6,7)",

<!-- OSGi Core R8+ -->
org.osgi.framework;version="[1.10,2)",
org.osgi.framework.dto;version="[1.8,2)",
org.osgi.framework.wiring;version="[1.2,2)",
org.osgi.util.tracker;version="[1.5,2)",

<!-- OSGi cmpn -->
org.osgi.service.cm;version="[1.0,2.0)";resolution:=optional,
org.osgi.service.event;resolution:=optional,
org.osgi.service.http;version="[1.2,2)",
org.osgi.service.http.context;version="[1.1,2)",
org.osgi.service.http.runtime;version="[1.1,2)",
org.osgi.service.http.runtime.dto;version="[1.1,2)",
org.osgi.service.cm;version="[1.6,2.0)";resolution:=optional,
org.osgi.service.event;version="[1.4,2.0)";resolution:=optional,
org.osgi.service.servlet.context;version="[2,3)",
org.osgi.service.servlet.runtime;version="[2,3)",
org.osgi.service.servlet.runtime.dto;version="[2,3)",

<!-- from pax-web-api -->
org.ops4j.pax.web.service;version="${pax-web.osgi.version}",
org.ops4j.pax.web.service.http;version="${pax-web.osgi.version}",
org.ops4j.pax.web.service.views;version="${pax-web.osgi.version}",
org.ops4j.pax.web.service.whiteboard;version="${pax-web.osgi.version}",
org.ops4j.pax.web.utils;version="${pax-web.osgi.version}",
Expand Down Expand Up @@ -98,8 +98,8 @@
org.apache.tomcat.util.digester;version="${dependency.org.apache.tomcat}",

<!-- from pax-logging-api -->
org.slf4j;version="[1.7,2)",
org.osgi.service.log;version="[1.3,2)",
org.slf4j;version="[2,3)",
org.osgi.service.log;version="[1.5,2)",

<!-- other required packages -->
javax.xml.parsers,
Expand All @@ -117,21 +117,23 @@
</Import-Package>
<!-- Nothing is exported from pax-web-runtime -->
<Provide-Capability>
<!-- TODO: JakartaEE 10 -->
<!-- 140.12.1 osgi.implementation Capability -->
osgi.implementation;osgi.implementation="osgi.http";version:Version="1.1";uses:="javax.servlet,javax.servlet.http,org.osgi.service.http.context,org.osgi.service.http.whiteboard",
osgi.implementation;osgi.implementation="osgi.http";version:Version="1.1";uses:="jakarta.servlet,jakarta.servlet.http,org.osgi.service.http.context,org.osgi.service.http.whiteboard",
<!--
140.12.2 osgi.contract Capability - pax-web-runtime does NOT export javax.servlet.* packages...
140.12.2 osgi.contract Capability - pax-web-runtime does NOT export jakarta.servlet.* packages...
https://docs.osgi.org/reference/portable-java-contracts.html
TODO: JakartaEE 10
-->
<!-- osgi.contract;osgi.contract=JavaServlet;version:Version="${dependency.jakarta.servlet-api}";uses:="javax.servlet,javax.servlet.http,javax.servlet.descriptor,javax.servlet.annotation",-->
<!-- osgi.contract;osgi.contract=JavaServlet;version:Version="${dependency.jakarta.servlet-api}";uses:="jakarta.servlet,jakarta.servlet.http,jakarta.servlet.descriptor,jakarta.servlet.annotation",-->
<!-- osgi.contract;osgi.contract=JavaWebSockets;version:Version="1";uses:="javax.websocket,javax.websocket.server"-->
<!-- 140.12.3 osgi.service Capability (135.4 osgi.service Namespace) -->
osgi.service;objectClass:List&lt;String&gt;="org.osgi.service.http.runtime.HttpServiceRuntime";uses:="org.osgi.service.http.runtime,org.osgi.service.http.runtime.dto",
osgi.service;objectClass:List&lt;String&gt;="org.osgi.service.servlet.runtime.HttpServiceRuntime";uses:="org.osgi.service.servlet.runtime,org.osgi.service.servlet.runtime.dto",
<!--
Not specified in 102 Http Service, but declared by pax-web-runtime.
OSGi Core R7, 10.3.3.5 public static final String EFFECTIVE_ACTIVE = "active"
-->
osgi.service;effective:=active;objectClass:List&lt;String&gt;="org.osgi.service.http.HttpService,org.ops4j.pax.web.service.WebContainer"
osgi.service;effective:=active;objectClass:List&lt;String&gt;="org.ops4j.pax.web.service.http.HttpService,org.ops4j.pax.web.service.WebContainer"
</Provide-Capability>
<Require-Capability>
<!-- ServerControllerFactory services are registered by pax-web-jetty, pax-web-tomcat and pax-web-undertow -->
Expand All @@ -144,8 +146,6 @@
ops4j-base-util-xml;inline=true,
pax-swissbox-property;inline=true,
</Embed-Dependency>
<!-- <_dsannotations>*</_dsannotations>-->
<!-- <_dsannotations-options>norequirements,nocapabilities,version;minimum=0.1</_dsannotations-options>-->
</instructions>
</configuration>
</plugin>
Expand Down Expand Up @@ -207,8 +207,23 @@
<artifactId>osgi.core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.cm</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.event</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 @@ -225,7 +240,7 @@
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<artifactId>log4j-slf4j2-impl</artifactId>
<scope>test</scope>
</dependency>

Expand All @@ -252,8 +267,18 @@
<!-- Testing -->

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
import org.osgi.framework.dto.ServiceReferenceDTO;
import org.osgi.service.http.HttpService;
import org.osgi.service.http.runtime.HttpServiceRuntime;
import org.osgi.service.http.runtime.HttpServiceRuntimeConstants;
import org.ops4j.pax.web.service.http.HttpService;
import org.osgi.service.servlet.runtime.HttpServiceRuntime;
import org.osgi.service.servlet.runtime.HttpServiceRuntimeConstants;
import org.osgi.service.log.LogService;
import org.osgi.util.tracker.ServiceTracker;
import org.osgi.util.tracker.ServiceTrackerCustomizer;
Expand Down Expand Up @@ -278,7 +278,7 @@ private void registerManagedService(final BundleContext context) {
}

/**
* Registers a managed service factory to create {@link org.osgi.service.http.HttpContext} <em>processors</em>
* Registers a managed service factory to create {@link org.ops4j.pax.web.service.http.HttpContext} <em>processors</em>
* - these will possibly register additional web items (like login configurations or filters) for shared or
* per-bundle http services.
*
Expand Down Expand Up @@ -554,7 +554,7 @@ private void performConfiguration() {
LOG.info("Starting server controller {}", serverController.getClass().getName());
serverController.start();

// this is where org.osgi.service.http.HttpService bundle-scoped service is registered in OSGi
// this is where org.ops4j.pax.web.service.http.HttpService bundle-scoped service is registered in OSGi
// this is the most fundamental operation related to Http Service specification
Dictionary<String, Object> props = determineServiceProperties(configuration);
ServiceFactory<StoppableHttpService> factory = new StoppableHttpServiceFactory(serverController, serverModel,
Expand Down Expand Up @@ -584,7 +584,7 @@ StoppableHttpService createService(Bundle bundle, ServerController serverControl
// we'll set this propery later through ServerListener
props.put(HttpServiceRuntimeConstants.HTTP_SERVICE_ENDPOINT, "/");
Long httpServiceId = (Long) httpServiceFactoryReg.getReference().getProperty(Constants.SERVICE_ID);
props.put(HttpServiceRuntimeConstants.HTTP_SERVICE_ID, Collections.singletonList(httpServiceId));
props.put(PaxWebConstants.HTTP_SERVICE_ID, Collections.singletonList(httpServiceId));
// SERVICE_CHANGECOUNT is 1.9 OSGi Core addition, so use literal please
// props.put(Constants.SERVICE_CHANGECOUNT, 0L);
props.put("service.changecount", 0L);
Expand All @@ -599,7 +599,7 @@ StoppableHttpService createService(Bundle bundle, ServerController serverControl
httpServiceRuntimeDTO.bundle = bundleContext.getBundle().getBundleId();
httpServiceRuntimeDTO.properties = new HashMap<>();
httpServiceRuntimeDTO.properties.put(HttpServiceRuntimeConstants.HTTP_SERVICE_ENDPOINT, "/");
httpServiceRuntimeDTO.properties.put(HttpServiceRuntimeConstants.HTTP_SERVICE_ID, Collections.singletonList(httpServiceId));
httpServiceRuntimeDTO.properties.put(PaxWebConstants.HTTP_SERVICE_ID, Collections.singletonList(httpServiceId));
httpServiceRuntimeDTO.properties.put("service.changecount", 0L);
// initially "usingBundles" is empty and we'll be setting it on every
httpServiceRuntimeDTO.usingBundles = new long[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import java.util.Collections;
import java.util.Map;
import java.util.UUID;
import javax.servlet.SessionCookieConfig;
import jakarta.servlet.SessionCookieConfig;

import org.ops4j.pax.web.service.PaxWebConfig;
import org.ops4j.pax.web.service.spi.config.Configuration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import javax.servlet.annotation.ServletSecurity;
import jakarta.servlet.annotation.ServletSecurity;

import org.apache.tomcat.util.descriptor.web.LoginConfig;
import org.apache.tomcat.util.descriptor.web.SecurityCollection;
Expand Down Expand Up @@ -68,7 +68,7 @@

/**
* <p>Tracks CM factory configurations which, in declarative way, are used to provide additional configuration
* for given bundle's instance of {@link org.osgi.service.http.HttpService}/{@link WebContainer}.</p>
* for given bundle's instance of {@link org.ops4j.pax.web.service.http.HttpService}/{@link WebContainer}.</p>
*/
public class HttpContextProcessing implements ManagedServiceFactory {

Expand Down Expand Up @@ -145,7 +145,7 @@ public void run() {
}

/**
* <p>A class that operates on {@link org.osgi.service.http.HttpService}/{@link WebContainer} scoped
* <p>A class that operates on {@link org.ops4j.pax.web.service.http.HttpService}/{@link WebContainer} scoped
* for given, configured {@link Bundle}.</p>
* <p>We don't have to operate on wirings/revisions - that's not required for
* {@link org.osgi.framework.Constants#SCOPE_BUNDLE}.</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,26 @@
import java.util.Dictionary;
import java.util.EventListener;
import java.util.List;
import javax.servlet.Filter;
import javax.servlet.MultipartConfigElement;
import javax.servlet.Servlet;
import javax.servlet.ServletContainerInitializer;
import javax.servlet.ServletException;
import javax.servlet.SessionCookieConfig;
import javax.servlet.descriptor.JspPropertyGroupDescriptor;
import javax.servlet.descriptor.TaglibDescriptor;
import jakarta.servlet.Filter;
import jakarta.servlet.MultipartConfigElement;
import jakarta.servlet.Servlet;
import jakarta.servlet.ServletContainerInitializer;
import jakarta.servlet.ServletException;
import jakarta.servlet.SessionCookieConfig;
import jakarta.servlet.descriptor.JspPropertyGroupDescriptor;
import jakarta.servlet.descriptor.TaglibDescriptor;

import org.ops4j.pax.web.service.MultiBundleWebContainerContext;
import org.ops4j.pax.web.service.WebContainer;
import org.ops4j.pax.web.service.views.PaxWebContainerView;
import org.osgi.framework.Bundle;
import org.osgi.service.http.HttpContext;
import org.osgi.service.http.NamespaceException;
import org.ops4j.pax.web.service.http.HttpContext;
import org.ops4j.pax.web.service.http.NamespaceException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* <em>Disabled</em> {@link org.osgi.service.http.HttpService} is set into actually registered, bundle-scoped
* <em>Disabled</em> {@link org.ops4j.pax.web.service.http.HttpService} is set into actually registered, bundle-scoped
* Http Service when the bundle stops.
*/
class HttpServiceDisabled implements WebContainer {
Expand Down
Loading

0 comments on commit 9cfa53d

Please sign in to comment.