From fc64c13ed8d4da78b15aba081819814316127d34 Mon Sep 17 00:00:00 2001 From: Tim Ward Date: Tue, 29 Jan 2019 16:16:58 +0000 Subject: [PATCH] Add a capability advertising that the HttpService is provided by this bundle Fixes [FELIX-6029] --- .../felix/http/itest/HttpServiceTest.java | 47 +++++++++++++++++++ http/jetty/pom.xml | 4 +- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/http/itest/src/test/java/org/apache/felix/http/itest/HttpServiceTest.java b/http/itest/src/test/java/org/apache/felix/http/itest/HttpServiceTest.java index 518e55b351d..e91395c3539 100644 --- a/http/itest/src/test/java/org/apache/felix/http/itest/HttpServiceTest.java +++ b/http/itest/src/test/java/org/apache/felix/http/itest/HttpServiceTest.java @@ -19,6 +19,9 @@ package org.apache.felix.http.itest; +import static javax.servlet.http.HttpServletResponse.SC_NOT_FOUND; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import java.io.IOException; @@ -29,6 +32,7 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; +import javax.naming.directory.SearchControls; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; @@ -44,7 +48,11 @@ 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.Bundle; +import org.osgi.framework.Constants; import org.osgi.framework.ServiceRegistration; +import org.osgi.framework.wiring.BundleCapability; +import org.osgi.framework.wiring.BundleWiring; import org.osgi.service.http.HttpService; import org.osgi.service.http.runtime.HttpServiceRuntime; @@ -142,4 +150,43 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) } } + /** + * Tests the starting of Jetty. + */ + @Test + public void testHttpServiceCapabiltiy() throws Exception + { + setupLatches(0); + + Bundle httpJettyBundle = getHttpJettyBundle(); + + BundleWiring wiring = httpJettyBundle.adapt(BundleWiring.class); + + List capabilities = wiring.getCapabilities("osgi.service"); + + assertFalse(capabilities.isEmpty()); + + boolean found = false; + + for (BundleCapability capability : capabilities) { + @SuppressWarnings("unchecked") + List objectClass = (List) 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); + } + } diff --git a/http/jetty/pom.xml b/http/jetty/pom.xml index 9ef46abb16b..220887b85b1 100644 --- a/http/jetty/pom.xml +++ b/http/jetty/pom.xml @@ -109,7 +109,9 @@ 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.service;objectClass:List<String>="org.osgi.service.http.runtime.HttpServiceRuntime"; - uses:="org.osgi.service.http.runtime,org.osgi.service.http.runtime.dto" + uses:="org.osgi.service.http.runtime,org.osgi.service.http.runtime.dto", + osgi.service;objectClass:List<String>="org.osgi.service.http.HttpService"; + uses:="org.osgi.service.http" osgi.contract;filter:="(&(osgi.contract=JavaServlet)(version=3.1))"