This is an automated email from the ASF dual-hosted git repository.
cziegeler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/felix-dev.git
The following commit(s) were added to refs/heads/master by this push:
new d3994ac7c8 FELIX-6745 : HttpService: Cannot unregister
javaxwrappers.ServletWrapper
d3994ac7c8 is described below
commit d3994ac7c8bc5c6d30b3019b2402ab8b2eadc168
Author: Carsten Ziegeler <[email protected]>
AuthorDate: Sun Dec 22 12:01:00 2024 +0100
FELIX-6745 : HttpService: Cannot unregister javaxwrappers.ServletWrapper
---
.../handler/HttpServiceServletHandler.java | 2 +-
http/itest/pom.xml | 2 +-
.../http/itest/servletapi3/HttpServiceTest.java | 82 ++++++++++++++++++----
.../http/itest/servletapi3/ServletContentTest.java | 77 ++++++++++++++++++--
http/jetty/pom.xml | 2 +-
http/jetty12/pom.xml | 2 +-
6 files changed, 146 insertions(+), 21 deletions(-)
diff --git
a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/HttpServiceServletHandler.java
b/http/base/src/main/java/org/apache/felix/http/base/internal/handler/HttpServiceServletHandler.java
index 600cb534f0..255ad55551 100644
---
a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/HttpServiceServletHandler.java
+++
b/http/base/src/main/java/org/apache/felix/http/base/internal/handler/HttpServiceServletHandler.java
@@ -38,7 +38,7 @@ public final class HttpServiceServletHandler extends
ServletHandler
final ServletInfo servletInfo,
final javax.servlet.Servlet servlet)
{
- this(HttpServiceFactory.HTTP_SERVICE_CONTEXT_SERVICE_ID, context,
servletInfo, ServletWrapper.getRegisteredServlet(servlet));
+ this(HttpServiceFactory.HTTP_SERVICE_CONTEXT_SERVICE_ID, context,
servletInfo, new ServletWrapper(servlet));
}
/**
diff --git a/http/itest/pom.xml b/http/itest/pom.xml
index 1d1f16864f..670c86a0b9 100644
--- a/http/itest/pom.xml
+++ b/http/itest/pom.xml
@@ -45,7 +45,7 @@
<properties>
<felix.java.version>17</felix.java.version>
<http.servlet.api.version>3.0.0</http.servlet.api.version>
- <http.jetty.version>1.0.17-SNAPSHOT</http.jetty.version>
+ <http.jetty.version>1.0.20-SNAPSHOT</http.jetty.version>
<http.jetty.id>org.apache.felix.http.jetty12</http.jetty.id>
</properties>
</profile>
diff --git
a/http/itest/src/test/java/org/apache/felix/http/itest/servletapi3/HttpServiceTest.java
b/http/itest/src/test/java/org/apache/felix/http/itest/servletapi3/HttpServiceTest.java
index db32d2e9cc..e365496054 100644
---
a/http/itest/src/test/java/org/apache/felix/http/itest/servletapi3/HttpServiceTest.java
+++
b/http/itest/src/test/java/org/apache/felix/http/itest/servletapi3/HttpServiceTest.java
@@ -40,6 +40,7 @@ import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.apache.felix.http.javaxwrappers.ServletWrapper;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -54,6 +55,8 @@ import org.osgi.framework.wiring.BundleWiring;
import org.osgi.service.http.HttpService;
import org.osgi.service.http.runtime.HttpServiceRuntime;
+import jakarta.servlet.http.HttpServlet;
+
@RunWith(PaxExam.class)
@ExamReactorStrategy(PerMethod.class)
public class HttpServiceTest extends Servlet3BaseIntegrationTest {
@@ -139,35 +142,90 @@ public class HttpServiceTest extends
Servlet3BaseIntegrationTest {
@Test
public void testHttpServiceCapabiltiy() throws Exception {
setupLatches(0);
-
+
Bundle httpJettyBundle = getHttpJettyBundle();
-
+
BundleWiring wiring = httpJettyBundle.adapt(BundleWiring.class);
-
+
List<BundleCapability> capabilities =
wiring.getCapabilities("osgi.service");
-
+
assertFalse(capabilities.isEmpty());
-
+
boolean found = false;
-
+
for (BundleCapability capability : capabilities) {
@SuppressWarnings("unchecked")
List<String> objectClass = (List<String>)
capability.getAttributes().get(Constants.OBJECTCLASS);
-
+
assertNotNull(objectClass);
-
+
if(objectClass.contains(HttpService.class.getName())) {
String uses =
capability.getDirectives().get("uses");
-
+
assertNotNull(uses);
-
+
assertTrue(uses.contains(HttpService.class.getPackage().getName()));
-
+
found = true;
break;
}
}
-
+
assertTrue("Missing HttpService capability", found);
}
+
+ private class JakartaServlet extends HttpServlet {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void init() throws jakarta.servlet.ServletException {
+ super.init();
+ initLatch.countDown();
+ }
+
+ @Override
+ protected void doGet(jakarta.servlet.http.HttpServletRequest req,
jakarta.servlet.http.HttpServletResponse resp)
+ throws IOException {
+ resp.getWriter().print("helloworld");
+ resp.flushBuffer();
+ }
+
+ @Override
+ public void destroy() {
+ destroyLatch.countDown();
+ }
+ }
+
+ @Test
+ public void testRegisteringWrapperAsServlet() throws Exception {
+ this.setupLatches(1);
+ final HttpService service = this.getHttpService();
+ service.registerServlet("/testjakarta", new ServletWrapper(new
JakartaServlet()), null, null);
+
+ assertTrue(initLatch.await(5, TimeUnit.SECONDS));
+
+ assertContent("helloworld", createURL("/testjakarta"));
+
+ service.unregister("/testjakarta");
+ }
+
+ @Test
+ public void testRegisteringCustomWrapperAsServlet() throws Exception {
+ this.setupLatches(1);
+ final HttpService service = this.getHttpService();
+ service.registerServlet("/testjakarta", new ServletWrapper(new
JakartaServlet()) {
+ @Override
+ public void service(ServletRequest req, ServletResponse resp)
+ throws IOException {
+ resp.getWriter().print("helloworldwrapped");
+ resp.flushBuffer();
+ }
+ }, null, null);
+
+ assertTrue(initLatch.await(5, TimeUnit.SECONDS));
+
+ assertContent("helloworldwrapped", createURL("/testjakarta"));
+
+ service.unregister("/testjakarta");
+ }
}
diff --git
a/http/itest/src/test/java/org/apache/felix/http/itest/servletapi3/ServletContentTest.java
b/http/itest/src/test/java/org/apache/felix/http/itest/servletapi3/ServletContentTest.java
index 87320261ee..91c13e54aa 100644
---
a/http/itest/src/test/java/org/apache/felix/http/itest/servletapi3/ServletContentTest.java
+++
b/http/itest/src/test/java/org/apache/felix/http/itest/servletapi3/ServletContentTest.java
@@ -21,7 +21,7 @@ package org.apache.felix.http.itest.servletapi3;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static
org.osgi.service.http.whiteboard.HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN;
-
+
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
@@ -32,11 +32,14 @@ import java.util.Hashtable;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
-
+
import javax.servlet.Servlet;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.apache.felix.http.javaxwrappers.ServletWrapper;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -44,7 +47,9 @@ import org.ops4j.pax.exam.junit.PaxExam;
import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
import org.ops4j.pax.exam.spi.reactors.PerMethod;
import org.osgi.framework.ServiceRegistration;
-
+
+import jakarta.servlet.http.HttpServlet;
+
@RunWith(PaxExam.class)
@ExamReactorStrategy(PerMethod.class)
public class ServletContentTest extends Servlet3BaseIntegrationTest {
@@ -81,7 +86,7 @@ public class ServletContentTest extends
Servlet3BaseIntegrationTest {
registrations.add(m_context.registerService(Servlet.class.getName(),
servletWithErrorCode, servletProps));
}
-
+
@After
public void unregisterServices() throws InterruptedException {
for (ServiceRegistration<?> serviceRegistration : registrations) {
@@ -117,5 +122,67 @@ public class ServletContentTest extends
Servlet3BaseIntegrationTest {
assertContent("/myservlet");
}
+
+ private class JakartaServlet extends HttpServlet {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void init() throws jakarta.servlet.ServletException {
+ super.init();
+ initLatch.countDown();
+ }
+
+ @Override
+ protected void doGet(jakarta.servlet.http.HttpServletRequest req,
jakarta.servlet.http.HttpServletResponse resp)
+ throws IOException {
+ resp.getWriter().print("helloworld");
+ resp.flushBuffer();
+ }
+
+ @Override
+ public void destroy() {
+ destroyLatch.countDown();
+ }
+ }
+
+ @Test
+ public void testRegisteringWrapperAsServlet() throws Exception {
+ this.setupLatches(1);
+
+ final Dictionary<String, Object> servletProps = new Hashtable<>();
+ servletProps.put(HTTP_WHITEBOARD_SERVLET_PATTERN, "/testjakarta");
+
+ final ServiceRegistration<Servlet> reg =
m_context.registerService(Servlet.class, new ServletWrapper(new
JakartaServlet()), servletProps);
+
+ assertTrue(initLatch.await(DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS));
+
+ assertContent("helloworld", createURL("/testjakarta"));
+
+ reg.unregister();
+ assertTrue(destroyLatch.await(DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS));
+ }
+
+ @Test
+ public void testRegisteringCustomWrapperAsServlet() throws Exception {
+ this.setupLatches(1);
+
+ final Dictionary<String, Object> servletProps = new Hashtable<>();
+ servletProps.put(HTTP_WHITEBOARD_SERVLET_PATTERN, "/testjakarta");
+
+ final ServiceRegistration<Servlet> reg =
m_context.registerService(Servlet.class, new ServletWrapper(new
JakartaServlet()) {
+ @Override
+ public void service(ServletRequest req, ServletResponse resp)
+ throws IOException {
+ resp.getWriter().print("helloworldwrapped");
+ resp.flushBuffer();
+ }
+ }, servletProps);
+
+ assertTrue(initLatch.await(DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS));
+
+ assertContent("helloworldwrapped", createURL("/testjakarta"));
+
+ reg.unregister();
+ assertTrue(destroyLatch.await(DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS));
+ }
}
-
\ No newline at end of file
diff --git a/http/jetty/pom.xml b/http/jetty/pom.xml
index 2ecbd6fddb..70dfe8b24d 100644
--- a/http/jetty/pom.xml
+++ b/http/jetty/pom.xml
@@ -494,7 +494,7 @@
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.http.base</artifactId>
- <version>5.1.8</version>
+ <version>5.1.9-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
diff --git a/http/jetty12/pom.xml b/http/jetty12/pom.xml
index 58f421813c..9d97aa0087 100644
--- a/http/jetty12/pom.xml
+++ b/http/jetty12/pom.xml
@@ -724,7 +724,7 @@
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.http.base</artifactId>
- <version>5.1.8</version>
+ <version>5.1.9-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>