Skip to content

Commit

Permalink
[#1802] Switch pax-web-itest-container-common from javax to jakarta
Browse files Browse the repository at this point in the history
  • Loading branch information
grgrzybek committed Jun 21, 2023
1 parent b69a627 commit de2df6d
Show file tree
Hide file tree
Showing 48 changed files with 236 additions and 264 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,11 @@ public interface PaxWebConstants {
*/
String HTTP_SERVICE_CONTEXT_PROPERTY = "osgi.http.whiteboard.context.httpservice";

/**
* For compatibility purpose (OSGi CMPN 8: {@code org.osgi.service.http.whiteboard.HttpWhiteboardConstants#HTTP_SERVICE_CONTEXT_FILTER})
*/
String HTTP_SERVICE_CONTEXT_FILTER = "(" + HTTP_SERVICE_CONTEXT_PROPERTY + "=*)";

/**
* For compatibility purpose (OSGi CMPN 8: {@code org.osgi.service.http.runtime.HttpServiceRuntimeConstants#HTTP_SERVICE_ID})
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@
<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)",
javax.websocket;resolution:=optional,
javax.websocket.server;resolution:=optional,
<!-- ranges indicate Servlet API 3.1+ (JakartaEE 7+) -->
jakarta.servlet;version="[3.1,5)",
jakarta.servlet.annotation;version="[3.1,5)",
jakarta.servlet.http;version="[3.1,5)",
jakarta.websocket;resolution:=optional,
jakarta.websocket.server;resolution:=optional,

<!-- ranges indicate we can work with OSGi Core R6+ -->
org.osgi.framework;version="[1.8,2)",
Expand All @@ -70,9 +70,9 @@
org.osgi.service.event;resolution:=optional,
org.osgi.service.cm;resolution:=optional,
org.osgi.service.http;version="[1.2,2)",
org.osgi.service.http.context;version="[1.1,2)",
org.osgi.service.http.runtime.dto;version="[1.1,2)",
org.osgi.service.http.runtime;version="[1.1,2)",
org.osgi.service.servlet.context;version="[1.1,2)",
org.osgi.service.servlet.runtime.dto;version="[1.1,2)",
org.osgi.service.servlet.runtime;version="[1.1,2)",

<!-- from pax-web-api -->
org.ops4j.pax.web.service;version="${pax-web.osgi.version}",
Expand Down Expand Up @@ -602,9 +602,17 @@
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.cdi</artifactId>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.osgi</groupId>-->
<!-- <artifactId>org.osgi.service.jaxrs</artifactId>-->
<!-- </dependency>-->
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.jaxrs</artifactId>
<artifactId>org.osgi.service.component.annotations</artifactId>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.servlet</artifactId>
</dependency>

<dependency>
Expand Down Expand Up @@ -663,7 +671,7 @@
<artifactId>xbean-finder-shaded</artifactId>
</dependency>

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

<dependency>
<groupId>com.sun.activation</groupId>
Expand Down Expand Up @@ -722,6 +730,10 @@
<groupId>jakarta.websocket</groupId>
<artifactId>jakarta.websocket-api</artifactId>
</dependency>
<dependency>
<groupId>jakarta.websocket</groupId>
<artifactId>jakarta.websocket-client-api</artifactId>
</dependency>

<dependency>
<groupId>jakarta.persistence</groupId>
Expand Down Expand Up @@ -769,7 +781,7 @@
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<artifactId>log4j-slf4j2-impl</artifactId>
</dependency>

<!-- Testing -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected Option[] baseConfigure() {
protected Option[] baseConfigureWithoutRuntime() {
Option[] options = super.baseConfigure();
Option[] containerOptions = new Option[] {
frameworkProperty("org.osgi.service.http.port").value("8181")
frameworkProperty("org.osgi.service.servlet.port").value("8181")
};
options = combine(options, containerOptions);
options = combine(options, defaultLoggingConfig());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void tearDown() throws BundleException {
public void testStatus() throws Exception {
HttpTestClientFactory.createDefaultTestClient()
.withResponseAssertion("Status must be available!",
resp -> resp.contains("org.osgi.service.http.authentication.type : null"))
resp -> resp.contains("org.osgi.service.servlet.authentication.type : null"))
.doGET("http://127.0.0.1:8181/status")
.executeTest();
}
Expand All @@ -67,7 +67,7 @@ public void testStatusAuth() throws Exception {
HttpTestClientFactory.createDefaultTestClient()
.authenticate("admin", "admin", "Test Realm")
.withResponseAssertion("Authorized Access must be allowed!",
resp -> resp.contains("org.osgi.service.http.authentication.type : BASIC"))
resp -> resp.contains("org.osgi.service.servlet.authentication.type : BASIC"))
.doGET("http://127.0.0.1:8181/status-with-auth")
.executeTest();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.util.Dictionary;
import java.util.Hashtable;
import javax.inject.Inject;
import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpServletResponse;

import org.junit.After;
import org.junit.Before;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.reflect.Proxy;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.Filter;
import jakarta.servlet.FilterChain;
import jakarta.servlet.FilterConfig;
import jakarta.servlet.ServletException;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletResponse;
import jakarta.servlet.http.HttpServletResponse;

import org.junit.After;
import org.junit.Before;
Expand Down Expand Up @@ -140,7 +140,7 @@ public void testRootFilterRegistration() throws Exception {
// the same context
WebContainer service = getWebContainer(hsBundle.getBundleContext());

final String fullContent = "This content is Filtered by a javax.servlet.Filter";
final String fullContent = "This content is Filtered by a jakarta.servlet.Filter";

Filter filter = new Filter() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import javax.servlet.Filter;
import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.Filter;
import jakarta.servlet.http.HttpServletResponse;

import org.junit.Test;
import org.ops4j.pax.web.itest.container.AbstractContainerTestBase;
Expand All @@ -31,8 +31,8 @@
import org.ops4j.pax.web.service.spi.model.events.ServletEventData;
import org.ops4j.pax.web.service.spi.model.events.WebElementEventListener;
import org.ops4j.pax.web.service.spi.servlet.OsgiScopedServletContext;
import org.osgi.service.http.HttpContext;
import org.osgi.service.http.HttpService;
import org.ops4j.pax.web.service.http.HttpContext;
import org.ops4j.pax.web.service.http.HttpService;
import org.osgi.util.tracker.ServiceTracker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package org.ops4j.pax.web.itest.container.httpservice;

import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpServletResponse;

import org.junit.After;
import org.junit.Before;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package org.ops4j.pax.web.itest.container.httpservice;

import javax.servlet.ServletContext;
import jakarta.servlet.ServletContext;

import org.junit.After;
import org.junit.Before;
Expand Down Expand Up @@ -86,7 +86,7 @@ public void testWebContextPathWithServlet() throws Exception {
*/
@Test
public void testServletContextRegistration() throws Exception {
// according to javax.servlet.ServletContext.getContextPath() javadoc, root context has
// according to jakarta.servlet.ServletContext.getContextPath() javadoc, root context has
// "" context path, not "/", but we'll unify it
String filter = String.format("(%s=%s)",
PaxWebConstants.SERVICE_PROPERTY_WEB_SERVLETCONTEXT_PATH, "/");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

/**
* Tests related to {@link org.osgi.service.http.HttpService} and chapter 102 of OSGi CMPN R7 Specification
* Tests related to {@link org.ops4j.pax.web.service.http.HttpService} and chapter 102 of OSGi CMPN R7 Specification
* (including {@link org.ops4j.pax.web.service.WebContainer} extension from Pax Web).
* No Whiteboard, no JSP, no WAR tests here.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ public void testTldJsp() throws Exception {

@Test
public void testPrecompiled() throws Exception {
String elFactory = System.getProperty("javax.el.ExpressionFactory");
String elFactory = System.getProperty("jakarta.el.ExpressionFactory");
try {
// The "context" in which JSPs are served is related to "helloworld-jsp" bundle and unlike in the
// case where JSPs are compiled (and TCCL is the loader from pax-web-jsp), here, JSP servlet
// (actually directly compiled JSP page) calls ExpressionFactory.newInstance() within the scope of
// TCCL of helloworld-jsp bundle.
// So we need this property ("helloworld-jsp" can't see the /META-INF/services/javax.el.ExpressionFactory
// So we need this property ("helloworld-jsp" can't see the /META-INF/services/jakarta.el.ExpressionFactory
// inside pax-web-jsp) AND we need org.apache.el Import-Package.
System.setProperty("javax.el.ExpressionFactory", "org.apache.el.ExpressionFactoryImpl");
System.setProperty("jakarta.el.ExpressionFactory", "org.apache.el.ExpressionFactoryImpl");
HttpTestClientFactory.createDefaultTestClient()
.withResponseAssertion("Response must contain '<h1>Hello World</h1>'",
resp -> resp.contains("<h1>Hello World</h1>"))
Expand All @@ -85,7 +85,7 @@ public void testPrecompiled() throws Exception {
.doGETandExecuteTest("http://localhost:8181/helloworld/jspc/using-tld.jsp");
} finally {
if (elFactory != null) {
System.setProperty("javax.el.ExpressionFactory", elFactory);
System.setProperty("jakarta.el.ExpressionFactory", elFactory);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@
import java.io.PrintWriter;
import java.util.Dictionary;
import java.util.Hashtable;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import jakarta.servlet.Filter;
import jakarta.servlet.FilterChain;
import jakarta.servlet.FilterConfig;
import jakarta.servlet.ServletException;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletResponse;

import org.junit.Test;
import org.ops4j.pax.web.itest.container.AbstractContainerTestBase;
import org.ops4j.pax.web.itest.utils.client.HttpTestClientFactory;
import org.ops4j.pax.web.service.WebContainer;
import org.osgi.framework.Bundle;
import org.osgi.service.http.HttpContext;
import org.ops4j.pax.web.service.http.HttpContext;

/**
* @author Achim Nierbeck
Expand All @@ -42,7 +42,7 @@ public abstract class AbstractFilterIntegrationTest extends AbstractContainerTes
public void testSimpleFilter() throws Exception {
WebContainer service = getWebContainer(context);

final String fullContent = "This content is Filtered by a javax.servlet.Filter";
final String fullContent = "This content is Filtered by a jakarta.servlet.Filter";
Filter filter = new Filter() {
@Override
public void init(FilterConfig filterConfig) throws ServletException {
Expand Down Expand Up @@ -71,8 +71,8 @@ public void destroy() {
});

HttpTestClientFactory.createDefaultTestClient()
.withResponseAssertion("Response must contain 'This content is Filtered by a javax.servlet.Filter'",
resp -> resp.contains("This content is Filtered by a javax.servlet.Filter"))
.withResponseAssertion("Response must contain 'This content is Filtered by a jakarta.servlet.Filter'",
resp -> resp.contains("This content is Filtered by a jakarta.servlet.Filter"))
.doGETandExecuteTest("http://127.0.0.1:8181/testFilter/filter.me");

service.unregisterFilter(filter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected UrlProvisionOption theWab() {
.add(AnnotatedMultipartTestServlet.class)
.set(Constants.BUNDLE_SYMBOLICNAME, "AnnotatedServletTest")
.set(PaxWebConstants.HEADER_CONTEXT_PATH, "/annotatedTest")
.set(Constants.IMPORT_PACKAGE, "javax.servlet")
.set(Constants.IMPORT_PACKAGE, "jakarta.servlet")
.set(Constants.DYNAMICIMPORT_PACKAGE, "*")
.build()).noStart();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
import java.util.Hashtable;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.Filter;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletResponse;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import org.junit.Test;
import org.ops4j.pax.web.itest.container.AbstractContainerTestBase;
Expand All @@ -39,9 +39,9 @@
import org.ops4j.pax.web.service.spi.model.events.WebApplicationEventListener;
import org.osgi.framework.Bundle;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.http.HttpContext;
import org.osgi.service.http.context.ServletContextHelper;
import org.osgi.service.http.whiteboard.HttpWhiteboardConstants;
import org.ops4j.pax.web.service.http.HttpContext;
import org.osgi.service.servlet.context.ServletContextHelper;
import org.osgi.service.servlet.whiteboard.HttpWhiteboardConstants;

import static org.junit.Assert.assertTrue;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
package org.ops4j.pax.web.itest.container.war;

import java.io.IOException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
import java.util.Hashtable;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import jakarta.servlet.Filter;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletResponse;

import org.junit.Test;
import org.ops4j.pax.web.itest.container.AbstractContainerTestBase;
Expand All @@ -37,7 +37,7 @@
import org.ops4j.pax.web.service.spi.model.events.WebElementEventListener;
import org.osgi.framework.Bundle;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.http.whiteboard.HttpWhiteboardConstants;
import org.osgi.service.servlet.whiteboard.HttpWhiteboardConstants;

import static org.junit.Assert.assertTrue;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ protected UrlProvisionOption theWab() {
.add(TestServletContainerInitializer.class, InnerClassStrategy.NONE)
.set(Constants.BUNDLE_SYMBOLICNAME, "war-bundle")
.set(PaxWebConstants.HEADER_CONTEXT_PATH, "/contextroot")
.set(Constants.IMPORT_PACKAGE, "javax.servlet, javax.servlet.annotation, javax.servlet.http")
.set(Constants.IMPORT_PACKAGE, "jakarta.servlet, jakarta.servlet.annotation, jakarta.servlet.http")
.set(Constants.DYNAMICIMPORT_PACKAGE, "*")
.add("WEB-INF/web.xml",
AbstractWarContainerInitializerIntegrationTest.class.getClassLoader().getResourceAsStream("web-3.0.xml"))
.add("META-INF/services/javax.servlet.ServletContainerInitializer",
AbstractWarContainerInitializerIntegrationTest.class.getClassLoader().getResourceAsStream("META-INF/services/javax.servlet.ServletContainerInitializer"))
.add("META-INF/services/jakarta.servlet.ServletContainerInitializer",
AbstractWarContainerInitializerIntegrationTest.class.getClassLoader().getResourceAsStream("META-INF/services/jakarta.servlet.ServletContainerInitializer"))
.build()).noStart();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManagerFactory;
import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpServletResponse;

import org.apache.hc.client5.http.async.methods.SimpleHttpRequest;
import org.apache.hc.client5.http.async.methods.SimpleHttpResponse;
Expand Down
Loading

0 comments on commit de2df6d

Please sign in to comment.