ARIES-1959 Reorganize owb and weld http extensions
Signed-off-by: Raymond Augé <rotty3000@apache.org>
diff --git a/cdi-bom/pom.xml b/cdi-bom/pom.xml
index 0692ee8..91d52cd 100644
--- a/cdi-bom/pom.xml
+++ b/cdi-bom/pom.xml
@@ -59,7 +59,13 @@
</dependency>
<dependency>
<groupId>org.apache.aries.cdi</groupId>
- <artifactId>org.apache.aries.cdi.extension.http</artifactId>
+ <artifactId>org.apache.aries.cdi.extension.http.owb</artifactId>
+ <version>${project.version}</version>
+ <scope>runtime</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.aries.cdi</groupId>
+ <artifactId>org.apache.aries.cdi.extension.http.weld</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
diff --git a/cdi-executable/base.bndrun b/cdi-executable/base.bndrun
new file mode 100644
index 0000000..0e23676
--- /dev/null
+++ b/cdi-executable/base.bndrun
@@ -0,0 +1,39 @@
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+#-runtrace: false
+#-runvm: -Xdebug, "-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000"
+
+-standalone: true
+-runee: JavaSE-1.8
+-runfw: org.eclipse.osgi
+-runkeep: true
+-runproperties: \
+ eclipse.log.enabled=false,\
+ logback.configurationFile=file:${.}/logback.xml,\
+ org.osgi.service.http.port=8080,\
+ osgi.console=
+
+-resolve.effective: resolve, active
+
+-runpath: \
+ ch.qos.logback.classic,\
+ ch.qos.logback.core,\
+ org.apache.felix.logback,\
+ slf4j.api
+
+-runsystempackages: \
+ org.slf4j;version=1.7.28,\
+ org.slf4j.event;version=1.7.28,\
+ org.slf4j.helpers;version=1.7.28,\
+ org.slf4j.spi;version=1.7.28,\
+ sun.misc
diff --git a/cdi-executable/owb-executable.bndrun b/cdi-executable/owb-executable.bndrun
index 3a0c023..4557b7c 100644
--- a/cdi-executable/owb-executable.bndrun
+++ b/cdi-executable/owb-executable.bndrun
@@ -10,48 +10,20 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-#-runtrace: false
-#-runvm: -Xdebug, "-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000"
-
--standalone: true
--runee: JavaSE-1.8
--runfw: org.eclipse.osgi
--runkeep: true
--runproperties: \
- eclipse.log.enabled=false,\
- logback.configurationFile=file:${.}/logback.xml,\
- org.osgi.service.http.port=8080,\
- osgi.console=
-
--resolve.effective: resolve, active
-
--runpath: \
- ch.qos.logback.classic,\
- ch.qos.logback.core,\
- org.apache.felix.logback,\
- slf4j.api
-
--runsystempackages: \
- org.slf4j;version=1.7.28,\
- org.slf4j.event;version=1.7.28,\
- org.slf4j.helpers;version=1.7.28,\
- org.slf4j.spi;version=1.7.28,\
- sun.misc
+-include: base.bndrun
+#-runjdb: 8000
-runrequires: \
osgi.identity;filter:='(osgi.identity=org.apache.aries.cdi.owb)',\
osgi.identity;filter:='(osgi.identity=org.apache.felix.gogo.command)'
-runblacklist: \
- osgi.identity;filter:='(osgi.identity=org.apache.aries.cdi.weld)'
+ osgi.identity;filter:='(osgi.identity=*weld*)'
-runbundles: \
- javax.servlet.jsp-api;version='[2.3.3,2.3.4)',\
openwebbeans-impl;version='[2.0.13,2.0.14)',\
openwebbeans-spi;version='[2.0.13,2.0.14)',\
- openwebbeans-web;version='[2.0.13,2.0.14)',\
org.apache.aries.cdi.extender;version='[1.1.0,1.1.1)',\
- org.apache.aries.cdi.extra;version='[1.1.0,1.1.1)',\
org.apache.aries.cdi.owb;version='[1.1.0,1.1.1)',\
org.apache.aries.cdi.spi;version='[1.1.0,1.1.1)',\
org.apache.aries.spifly.dynamic.framework.extension;version='[1.2.3,1.2.4)',\
@@ -60,7 +32,6 @@
org.apache.felix.gogo.command;version='[1.1.0,1.1.1)',\
org.apache.felix.gogo.runtime;version='[1.1.2,1.1.3)',\
org.apache.felix.gogo.shell;version='[1.1.2,1.1.3)',\
- org.apache.felix.http.servlet-api;version='[1.1.2,1.1.3)',\
org.apache.geronimo.specs.geronimo-annotation_1.3_spec;version='[1.1.0,1.1.1)',\
org.apache.geronimo.specs.geronimo-atinject_1.0_spec;version='[1.1.0,1.1.1)',\
org.apache.geronimo.specs.geronimo-el_2.2_spec;version='[1.1.0,1.1.1)',\
diff --git a/cdi-executable/weld-executable.bndrun b/cdi-executable/weld-executable.bndrun
index a8b5d95..4103d24 100644
--- a/cdi-executable/weld-executable.bndrun
+++ b/cdi-executable/weld-executable.bndrun
@@ -10,33 +10,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-#-runtrace: false
-#-runvm: -Xdebug, "-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000"
-
--standalone: true
--runee: JavaSE-1.8
--runfw: org.eclipse.osgi
--runkeep: true
--runproperties: \
- eclipse.log.enabled=false,\
- logback.configurationFile=file:${.}/logback.xml,\
- org.osgi.service.http.port=8080,\
- osgi.console=
-
--resolve.effective: resolve, active
-
--runpath: \
- ch.qos.logback.classic,\
- ch.qos.logback.core,\
- org.apache.felix.logback,\
- slf4j.api
-
--runsystempackages: \
- org.slf4j;version=1.7.28,\
- org.slf4j.event;version=1.7.28,\
- org.slf4j.helpers;version=1.7.28,\
- org.slf4j.spi;version=1.7.28,\
- sun.misc
+-include: base.bndrun
+#-runjdb: 8000
-runrequires: \
osgi.identity;filter:='(osgi.identity=javax.ejb-api)',\
@@ -45,7 +20,7 @@
osgi.identity;filter:='(osgi.identity=org.apache.felix.gogo.command)'
-runblacklist: \
- osgi.identity;filter:='(osgi.identity=org.apache.aries.cdi.owb)'
+ osgi.identity;filter:='(osgi.identity=*owb*)'
-runbundles: \
javax.ejb-api;version='[3.2.0,3.2.1)',\
diff --git a/cdi-extension-http/LICENSE b/cdi-extension-http-owb/LICENSE
similarity index 100%
rename from cdi-extension-http/LICENSE
rename to cdi-extension-http-owb/LICENSE
diff --git a/cdi-extension-http/NOTICE b/cdi-extension-http-owb/NOTICE
similarity index 100%
rename from cdi-extension-http/NOTICE
rename to cdi-extension-http-owb/NOTICE
diff --git a/cdi-extension-http/pom.xml b/cdi-extension-http-owb/pom.xml
similarity index 72%
copy from cdi-extension-http/pom.xml
copy to cdi-extension-http-owb/pom.xml
index 03a4216..701d3d2 100644
--- a/cdi-extension-http/pom.xml
+++ b/cdi-extension-http-owb/pom.xml
@@ -26,8 +26,8 @@
<relativePath>..</relativePath>
</parent>
- <artifactId>org.apache.aries.cdi.extension.http</artifactId>
- <name>Apache Aries CDI - Http Extension</name>
+ <artifactId>org.apache.aries.cdi.extension.http.owb</artifactId>
+ <name>Apache Aries CDI - Http Extension for OpenWebBeans</name>
<description>
Provides support to CDI bundles for http servlet scopes; @RequestScoped,
@SessionScoped and @ConversationScoped.
@@ -84,43 +84,9 @@
<artifactId>geronimo-jcdi_2.0_spec</artifactId>
</dependency>
<dependency>
- <groupId>org.jboss.weld</groupId>
- <artifactId>weld-osgi-bundle</artifactId>
- <version>${weld.version}</version>
- <exclusions>
- <exclusion>
- <groupId>javax.annotation</groupId>
- <artifactId>javax.annotation-api</artifactId>
- </exclusion>
- <exclusion>
- <groupId>javax.enterprise</groupId>
- <artifactId>cdi-api</artifactId>
- </exclusion>
- <exclusion>
- <groupId>javax.inject</groupId>
- <artifactId>javax.inject</artifactId>
- </exclusion>
- <exclusion>
- <groupId>org.jboss.spec.javax.annotation</groupId>
- <artifactId>jboss-annotations-api_1.3_spec</artifactId>
- </exclusion>
- <exclusion>
- <groupId>org.jboss.spec.javax.ejb</groupId>
- <artifactId>jboss-ejb-api_3.2_spec</artifactId>
- </exclusion>
- <exclusion>
- <groupId>org.jboss.spec.javax.el</groupId>
- <artifactId>jboss-el-api_3.0_spec</artifactId>
- </exclusion>
- <exclusion>
- <groupId>org.jboss.spec.javax.interceptor</groupId>
- <artifactId>jboss-interceptors-api_1.2_spec</artifactId>
- </exclusion>
- <exclusion>
- <groupId>org.jboss.spec.javax.transaction</groupId>
- <artifactId>jboss-transaction-api_1.2_spec</artifactId>
- </exclusion>
- </exclusions>
+ <groupId>org.apache.openwebbeans</groupId>
+ <artifactId>openwebbeans-web</artifactId>
+ <version>${owb.version}</version>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
diff --git a/cdi-extension-http/src/main/java/org/apache/aries/cdi/extension/http/HttpActivator.java b/cdi-extension-http-owb/src/main/java/org/apache/aries/cdi/extension/http/HttpActivator.java
similarity index 71%
copy from cdi-extension-http/src/main/java/org/apache/aries/cdi/extension/http/HttpActivator.java
copy to cdi-extension-http-owb/src/main/java/org/apache/aries/cdi/extension/http/HttpActivator.java
index 5875ff0..7bddc93 100644
--- a/cdi-extension-http/src/main/java/org/apache/aries/cdi/extension/http/HttpActivator.java
+++ b/cdi-extension-http-owb/src/main/java/org/apache/aries/cdi/extension/http/HttpActivator.java
@@ -24,6 +24,9 @@
import javax.enterprise.inject.spi.Extension;
+import org.apache.webbeans.spi.ContainerLifecycle;
+import org.apache.webbeans.spi.ContextsService;
+import org.apache.webbeans.spi.ConversationService;
import org.osgi.annotation.bundle.Header;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
@@ -39,9 +42,21 @@
public void start(BundleContext context) throws Exception {
Dictionary<String, Object> properties = new Hashtable<>();
properties.put(CDI_EXTENSION_PROPERTY, "aries.cdi.http");
- properties.put(SERVICE_DESCRIPTION, "Aries CDI - HTTP Portable Extension Factory");
+ properties.put("aries.cdi.http.provider", "OpenWebBeans");
+ properties.put(SERVICE_DESCRIPTION, "Aries CDI - HTTP Portable Extension Factory for OpenWebBeans");
properties.put(SERVICE_VENDOR, "Apache Software Foundation");
+ // Web mode - minimal set, see META-INF/openwebbeans/openwebbeans.properties in openwebbeans-web for details
+ properties.put(
+ ContainerLifecycle.class.getName(),
+ org.apache.webbeans.web.lifecycle.WebContainerLifecycle.class.getName());
+ properties.put(
+ ContextsService.class.getName(),
+ org.apache.webbeans.web.context.WebContextsService.class.getName());
+ properties.put(
+ ConversationService.class.getName(),
+ org.apache.webbeans.web.context.WebConversationService.class.getName());
+
_serviceRegistration = context.registerService(
Extension.class, new HttpExtensionFactory(), properties);
}
diff --git a/cdi-owb/src/main/java/org/apache/aries/cdi/owb/web/WebExtension.java b/cdi-extension-http-owb/src/main/java/org/apache/aries/cdi/extension/http/HttpExtension.java
similarity index 85%
rename from cdi-owb/src/main/java/org/apache/aries/cdi/owb/web/WebExtension.java
rename to cdi-extension-http-owb/src/main/java/org/apache/aries/cdi/extension/http/HttpExtension.java
index 4a8f4c5..f5cc667 100644
--- a/cdi-owb/src/main/java/org/apache/aries/cdi/owb/web/WebExtension.java
+++ b/cdi-extension-http-owb/src/main/java/org/apache/aries/cdi/extension/http/HttpExtension.java
@@ -12,9 +12,10 @@
* limitations under the License.
*/
-package org.apache.aries.cdi.owb.web;
+package org.apache.aries.cdi.extension.http;
import static java.util.Collections.list;
+import static java.util.Optional.ofNullable;
import static javax.interceptor.Interceptor.Priority.LIBRARY_AFTER;
import static org.osgi.framework.Constants.SERVICE_DESCRIPTION;
import static org.osgi.framework.Constants.SERVICE_RANKING;
@@ -24,6 +25,7 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Proxy;
import java.util.ArrayList;
import java.util.Dictionary;
import java.util.HashSet;
@@ -69,13 +71,50 @@
import org.apache.aries.cdi.spi.configuration.Configuration;
import org.apache.webbeans.config.WebBeansContext;
import org.apache.webbeans.spi.ContainerLifecycle;
+import org.apache.webbeans.web.lifecycle.test.MockServletContext;
+import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.cdi.annotations.Service;
-public class WebExtension implements Extension {
+@SuppressWarnings("serial")
+public class HttpExtension extends ServletContextEvent implements Extension {
+ private final BundleContext bundleContext;
+ private final ServletContext proxyContext;
private volatile Configuration configuration;
+ private volatile ServletContext delegateContext;
+
+ public HttpExtension(Bundle bundle) {
+ super(new MockServletContext());
+
+ this.bundleContext = bundle.getBundleContext();
+
+ // ensure we can switch the impl and keep ServletContextBean working with an updated context
+ this.proxyContext = ServletContext.class.cast(Proxy.newProxyInstance(ServletContext.class.getClassLoader(),
+ new Class<?>[]{ServletContext.class},
+ (proxy, method, args) -> {
+ try {
+ return method.invoke(ofNullable(delegateContext).orElseGet(HttpExtension.super::getServletContext), args);
+ }
+ catch (final InvocationTargetException ite) {
+ throw ite.getTargetException();
+ }
+ }));
+ }
+
+ public void setDelegate(final ServletContext delegateContext) {
+ this.delegateContext = delegateContext;
+ }
+
+ public ServletContext getOriginal() {
+ return super.getServletContext();
+ }
+
+ @Override
+ public ServletContext getServletContext() {
+ return proxyContext;
+ }
void getConfiguration(@Observes Configuration configuration) {
this.configuration = configuration;
@@ -235,10 +274,10 @@
void afterDeploymentValidation(
@Observes @Priority(LIBRARY_AFTER + 800)
- AfterDeploymentValidation adv, BeanManager beanManager, BundleContext bundleContext) {
+ AfterDeploymentValidation adv, BeanManager beanManager) {
Dictionary<String, Object> properties = new Hashtable<>();
- properties.put(SERVICE_DESCRIPTION, "Aries CDI - HTTP Portable Extension");
+ properties.put(SERVICE_DESCRIPTION, "Aries CDI - HTTP Portable Extension for OpenWebBeans");
properties.put(SERVICE_VENDOR, "Apache Software Foundation");
properties.put(HTTP_WHITEBOARD_CONTEXT_SELECT, configuration.get(HTTP_WHITEBOARD_CONTEXT_SELECT));
properties.put(HTTP_WHITEBOARD_LISTENER, Boolean.TRUE.toString());
@@ -277,25 +316,17 @@
@Override
public void contextInitialized(ServletContextEvent event) {
- // update the sce to have the real one in CDI
- try {
- final Class<?> usc = event.getServletContext().getClassLoader()
- .loadClass("org.apache.aries.cdi.container.internal.servlet.UpdatableServletContext");
- final Object uscInstance = webBeansContext.getService(usc);
- usc.getMethod("setDelegate", ServletContext.class)
- .invoke(uscInstance, event.getServletContext());
+ ServletContext realSC = event.getServletContext();
- // propagate attributes from the temporary sc
- final ServletContext original = ServletContext.class.cast(usc.getMethod("getOriginal").invoke(uscInstance));
- list(original.getAttributeNames())
- .forEach(attr -> event.getServletContext().setAttribute(attr, original.getAttribute(attr)));
- }
- catch (final ClassNotFoundException | NoSuchMethodException | IllegalAccessException cnfe) {
- // no-op, weirdly using another extender impl
- }
- catch (final InvocationTargetException ite) {
- throw new IllegalStateException(ite.getTargetException());
- }
+ // update the sce to have the real one in CDI
+ setDelegate(realSC);
+
+ // propagate attributes from the temporary sc
+ list(getOriginal().getAttributeNames()).forEach(
+ attr -> realSC.setAttribute(attr, getOriginal().getAttribute(attr)));
+
+ realSC.setAttribute(BundleContext.class.getName(), bundleContext);
+ realSC.setAttribute(WebBeansContext.class.getName(), webBeansContext);
// already started in the activator so let's skip it, just ensure it is skipped if re-called
event.getServletContext().setAttribute(getClass().getName(), true);
diff --git a/cdi-owb/src/main/java/org/apache/aries/cdi/owb/web/WebExtensionFactory.java b/cdi-extension-http-owb/src/main/java/org/apache/aries/cdi/extension/http/HttpExtensionFactory.java
similarity index 85%
rename from cdi-owb/src/main/java/org/apache/aries/cdi/owb/web/WebExtensionFactory.java
rename to cdi-extension-http-owb/src/main/java/org/apache/aries/cdi/extension/http/HttpExtensionFactory.java
index 3c02024..906b898 100644
--- a/cdi-owb/src/main/java/org/apache/aries/cdi/owb/web/WebExtensionFactory.java
+++ b/cdi-extension-http-owb/src/main/java/org/apache/aries/cdi/extension/http/HttpExtensionFactory.java
@@ -12,7 +12,7 @@
* limitations under the License.
*/
-package org.apache.aries.cdi.owb.web;
+package org.apache.aries.cdi.extension.http;
import javax.enterprise.inject.spi.Extension;
@@ -20,13 +20,13 @@
import org.osgi.framework.PrototypeServiceFactory;
import org.osgi.framework.ServiceRegistration;
-public class WebExtensionFactory implements PrototypeServiceFactory<Extension> {
+public class HttpExtensionFactory implements PrototypeServiceFactory<Extension> {
@Override
public Extension getService(
Bundle bundle, ServiceRegistration<Extension> registration) {
- return new WebExtension();
+ return new HttpExtension(bundle);
}
@Override
diff --git a/cdi-extension-http/src/main/java/org/apache/aries/cdi/extension/http/package-info.java b/cdi-extension-http-owb/src/main/java/org/apache/aries/cdi/extension/http/package-info.java
similarity index 100%
rename from cdi-extension-http/src/main/java/org/apache/aries/cdi/extension/http/package-info.java
rename to cdi-extension-http-owb/src/main/java/org/apache/aries/cdi/extension/http/package-info.java
diff --git a/cdi-extension-http/LICENSE b/cdi-extension-http-weld/LICENSE
similarity index 100%
copy from cdi-extension-http/LICENSE
copy to cdi-extension-http-weld/LICENSE
diff --git a/cdi-extension-http/NOTICE b/cdi-extension-http-weld/NOTICE
similarity index 100%
copy from cdi-extension-http/NOTICE
copy to cdi-extension-http-weld/NOTICE
diff --git a/cdi-extension-http/pom.xml b/cdi-extension-http-weld/pom.xml
similarity index 97%
rename from cdi-extension-http/pom.xml
rename to cdi-extension-http-weld/pom.xml
index 03a4216..fecf888 100644
--- a/cdi-extension-http/pom.xml
+++ b/cdi-extension-http-weld/pom.xml
@@ -26,8 +26,8 @@
<relativePath>..</relativePath>
</parent>
- <artifactId>org.apache.aries.cdi.extension.http</artifactId>
- <name>Apache Aries CDI - Http Extension</name>
+ <artifactId>org.apache.aries.cdi.extension.http.weld</artifactId>
+ <name>Apache Aries CDI - Http Extension for Weld</name>
<description>
Provides support to CDI bundles for http servlet scopes; @RequestScoped,
@SessionScoped and @ConversationScoped.
diff --git a/cdi-extension-http/src/main/java/org/apache/aries/cdi/extension/http/HttpActivator.java b/cdi-extension-http-weld/src/main/java/org/apache/aries/cdi/extension/http/HttpActivator.java
similarity index 95%
rename from cdi-extension-http/src/main/java/org/apache/aries/cdi/extension/http/HttpActivator.java
rename to cdi-extension-http-weld/src/main/java/org/apache/aries/cdi/extension/http/HttpActivator.java
index 5875ff0..901f932 100644
--- a/cdi-extension-http/src/main/java/org/apache/aries/cdi/extension/http/HttpActivator.java
+++ b/cdi-extension-http-weld/src/main/java/org/apache/aries/cdi/extension/http/HttpActivator.java
@@ -39,7 +39,8 @@
public void start(BundleContext context) throws Exception {
Dictionary<String, Object> properties = new Hashtable<>();
properties.put(CDI_EXTENSION_PROPERTY, "aries.cdi.http");
- properties.put(SERVICE_DESCRIPTION, "Aries CDI - HTTP Portable Extension Factory");
+ properties.put("aries.cdi.http.provider", "Weld");
+ properties.put(SERVICE_DESCRIPTION, "Aries CDI - HTTP Portable Extension Factory for Weld");
properties.put(SERVICE_VENDOR, "Apache Software Foundation");
_serviceRegistration = context.registerService(
diff --git a/cdi-extension-http/src/main/java/org/apache/aries/cdi/extension/http/HttpExtension.java b/cdi-extension-http-weld/src/main/java/org/apache/aries/cdi/extension/http/HttpExtension.java
similarity index 100%
rename from cdi-extension-http/src/main/java/org/apache/aries/cdi/extension/http/HttpExtension.java
rename to cdi-extension-http-weld/src/main/java/org/apache/aries/cdi/extension/http/HttpExtension.java
diff --git a/cdi-extension-http/src/main/java/org/apache/aries/cdi/extension/http/HttpExtensionFactory.java b/cdi-extension-http-weld/src/main/java/org/apache/aries/cdi/extension/http/HttpExtensionFactory.java
similarity index 100%
rename from cdi-extension-http/src/main/java/org/apache/aries/cdi/extension/http/HttpExtensionFactory.java
rename to cdi-extension-http-weld/src/main/java/org/apache/aries/cdi/extension/http/HttpExtensionFactory.java
diff --git a/cdi-extension-http/src/main/java/org/apache/aries/cdi/extension/http/package-info.java b/cdi-extension-http-weld/src/main/java/org/apache/aries/cdi/extension/http/package-info.java
similarity index 100%
copy from cdi-extension-http/src/main/java/org/apache/aries/cdi/extension/http/package-info.java
copy to cdi-extension-http-weld/src/main/java/org/apache/aries/cdi/extension/http/package-info.java
diff --git a/cdi-itests/owb-itest.bndrun b/cdi-itests/owb-itest.bndrun
index 20c12d2..96b6624 100644
--- a/cdi-itests/owb-itest.bndrun
+++ b/cdi-itests/owb-itest.bndrun
@@ -17,7 +17,7 @@
osgi.identity;filter:='(osgi.identity=org.apache.aries.cdi.owb)'
-runblacklist: \
- osgi.identity;filter:='(osgi.identity=org.apache.aries.cdi.weld)'
+ osgi.identity;filter:='(osgi.identity=*weld*)'
-runbundles: \
biz.aQute.junit;version='[4.3.1,4.3.2)',\
@@ -26,6 +26,7 @@
openwebbeans-spi;version='[2.0.13,2.0.14)',\
openwebbeans-web;version='[2.0.13,2.0.14)',\
org.apache.aries.cdi.extender;version='[1.1.0,1.1.1)',\
+ org.apache.aries.cdi.extension.http.owb;version='[1.1.0,1.1.1)',\
org.apache.aries.cdi.extension.jndi;version='[1.1.0,1.1.1)',\
org.apache.aries.cdi.extension.mp-config;version='[1.1.0,1.1.1)',\
org.apache.aries.cdi.extension.mp-metrics;version='[1.1.0,1.1.1)',\
diff --git a/cdi-itests/weld-itest.bndrun b/cdi-itests/weld-itest.bndrun
index 136b9c0..169a2f7 100644
--- a/cdi-itests/weld-itest.bndrun
+++ b/cdi-itests/weld-itest.bndrun
@@ -19,14 +19,7 @@
osgi.identity;filter:='(osgi.identity=org.apache.aries.cdi.weld)'
-runblacklist: \
- osgi.identity;filter:='(osgi.identity=org.apache.aries.cdi.owb)'
-
--runsystempackages: \
- org.slf4j;version=1.7.25,\
- org.slf4j.event;version=1.7.25,\
- org.slf4j.helpers;version=1.7.25,\
- org.slf4j.spi;version=1.7.25,\
- sun.misc
+ osgi.identity;filter:='(osgi.identity=*owb*)'
-runbundles: \
biz.aQute.junit;version='[4.3.1,4.3.2)',\
@@ -34,7 +27,7 @@
javax.transaction-api;version='[1.2.0,1.2.1)',\
jboss-classfilewriter;version='[1.2.3,1.2.4)',\
org.apache.aries.cdi.extender;version='[1.1.0,1.1.1)',\
- org.apache.aries.cdi.extension.http;version='[1.1.0,1.1.1)',\
+ org.apache.aries.cdi.extension.http.weld;version='[1.1.0,1.1.1)',\
org.apache.aries.cdi.extension.jndi;version='[1.1.0,1.1.1)',\
org.apache.aries.cdi.extension.mp-config;version='[1.1.0,1.1.1)',\
org.apache.aries.cdi.extension.mp-metrics;version='[1.1.0,1.1.1)',\
diff --git a/cdi-owb/pom.xml b/cdi-owb/pom.xml
index 66c47c4..e4de12d 100644
--- a/cdi-owb/pom.xml
+++ b/cdi-owb/pom.xml
@@ -53,11 +53,6 @@
<bnd><![CDATA[
-cdiannotations:
-noclassforname: true
- #Import-Package: \
- # org.apache.webbeans.servlet;resolution:=optional,\
- # org.apache.webbeans.web.*;resolution:=optional,\
- # javax.servlet.*;resolution:=optional,\
- # *
]]></bnd>
</configuration>
</plugin>
@@ -97,11 +92,6 @@
<version>${owb.version}</version>
</dependency>
<dependency>
- <groupId>org.apache.openwebbeans</groupId>
- <artifactId>openwebbeans-web</artifactId>
- <version>${owb.version}</version>
- </dependency>
- <dependency>
<groupId>org.apache.xbean</groupId>
<artifactId>xbean-bundleutils</artifactId>
<version>4.15</version>
diff --git a/cdi-owb/src/main/java/org/apache/aries/cdi/owb/Activator.java b/cdi-owb/src/main/java/org/apache/aries/cdi/owb/Activator.java
index 7474276..91e8fb3 100644
--- a/cdi-owb/src/main/java/org/apache/aries/cdi/owb/Activator.java
+++ b/cdi-owb/src/main/java/org/apache/aries/cdi/owb/Activator.java
@@ -17,13 +17,10 @@
import static org.osgi.framework.Constants.BUNDLE_ACTIVATOR;
import static org.osgi.framework.Constants.SERVICE_DESCRIPTION;
import static org.osgi.framework.Constants.SERVICE_VENDOR;
-import static org.osgi.service.cdi.CDIConstants.CDI_EXTENSION_PROPERTY;
import java.util.Dictionary;
import java.util.Hashtable;
-import javax.enterprise.inject.spi.Extension;
-
import org.apache.aries.cdi.spi.CDIContainerInitializer;
import org.osgi.annotation.bundle.Header;
import org.osgi.framework.BundleActivator;
@@ -36,8 +33,6 @@
)
public class Activator implements BundleActivator {
- public static final boolean webEnabled = true;
-
@Override
public void start(BundleContext bundleContext) throws Exception {
System.setProperty("openwebbeans.web.sci.active", "false"); // we handle it ourself, disable this jetty feature
@@ -47,27 +42,13 @@
_containerInitializer = bundleContext.registerService(
CDIContainerInitializer.class, new OWBCDIContainerInitializerFactory(bundleContext), properties);
-
- if (webEnabled) {
- properties = new Hashtable<>();
- properties.put(CDI_EXTENSION_PROPERTY, "aries.cdi.http");
- properties.put(SERVICE_DESCRIPTION, "Aries CDI - OpenWebBeans Web Extension Factory");
- properties.put(SERVICE_VENDOR, "Apache Software Foundation");
-
- _webExtension = bundleContext.registerService(
- Extension.class, new org.apache.aries.cdi.owb.web.WebExtensionFactory(), properties);
- }
}
@Override
public void stop(BundleContext context) throws Exception {
_containerInitializer.unregister();
- if (_webExtension != null) {
- _webExtension.unregister();
- }
}
private ServiceRegistration<CDIContainerInitializer> _containerInitializer;
- private ServiceRegistration<Extension> _webExtension;
}
diff --git a/cdi-owb/src/main/java/org/apache/aries/cdi/owb/OWBCDIContainerInitializer.java b/cdi-owb/src/main/java/org/apache/aries/cdi/owb/OWBCDIContainerInitializer.java
index 3dbe9bb..fc665d7 100644
--- a/cdi-owb/src/main/java/org/apache/aries/cdi/owb/OWBCDIContainerInitializer.java
+++ b/cdi-owb/src/main/java/org/apache/aries/cdi/owb/OWBCDIContainerInitializer.java
@@ -15,6 +15,8 @@
package org.apache.aries.cdi.owb;
import static java.util.Objects.requireNonNull;
+import static org.osgi.framework.namespace.PackageNamespace.PACKAGE_NAMESPACE;
+import static org.osgi.service.cdi.CDIConstants.CDI_EXTENSION_PROPERTY;
import java.io.IOException;
import java.lang.annotation.Annotation;
@@ -45,13 +47,10 @@
import org.apache.webbeans.portable.events.ExtensionLoader;
import org.apache.webbeans.spi.ApplicationBoundaryService;
import org.apache.webbeans.spi.ContainerLifecycle;
-import org.apache.webbeans.spi.ContextsService;
-import org.apache.webbeans.spi.ConversationService;
import org.apache.webbeans.spi.DefiningClassService;
import org.apache.webbeans.spi.ScannerService;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
-import org.osgi.framework.namespace.PackageNamespace;
import org.osgi.framework.wiring.BundleCapability;
import org.osgi.framework.wiring.BundleWire;
import org.osgi.framework.wiring.BundleWiring;
@@ -110,12 +109,12 @@
spiLoader.getBundles().add(owbBundleContext.getBundle());
BundleWiring bundleWiring = owbBundleContext.getBundle().adapt(BundleWiring.class);
- List<BundleWire> requiredWires = bundleWiring.getRequiredWires(PackageNamespace.PACKAGE_NAMESPACE);
+ List<BundleWire> requiredWires = bundleWiring.getRequiredWires(PACKAGE_NAMESPACE);
for (BundleWire bundleWire : requiredWires) {
BundleCapability capability = bundleWire.getCapability();
Map<String, Object> attributes = capability.getAttributes();
- String packageName = (String)attributes.get(PackageNamespace.PACKAGE_NAMESPACE);
+ String packageName = (String)attributes.get(PACKAGE_NAMESPACE);
if (!packageName.startsWith("org.apache.webbeans.")) {
continue;
}
@@ -149,22 +148,21 @@
new CdiScannerService(beanClasses, beanDescriptorURLs));
services.put(BundleContext.class, clientBundleContext);
- if (Activator.webEnabled) {
- // Web mode - minimal set, see META-INF/openwebbeans/openwebbeans.properties in openwebbeans-web for details
- // todo: enable to not use web?
- properties.setProperty(
- ContainerLifecycle.class.getName(),
- org.apache.webbeans.web.lifecycle.WebContainerLifecycle.class.getName());
- properties.setProperty(
- ContextsService.class.getName(),
- org.apache.webbeans.web.context.WebContextsService.class.getName());
- properties.setProperty(
- ConversationService.class.getName(),
- org.apache.webbeans.web.context.WebConversationService.class.getName());
+ // If we find the OpenWebBeans "aries.cdi.http" Extension enable web mode.
+ // This Extension will have properties:
+ // osgi.cdi.extension = aries.cdi.http
+ // aries.cdi.http.provider = OpenWebBeans
+ extensions.entrySet().stream().filter(
+ e -> "aries.cdi.http".equals(e.getValue().get(CDI_EXTENSION_PROPERTY)) &&
+ "OpenWebBeans".equalsIgnoreCase(String.valueOf(e.getValue().get("aries.cdi.http.provider")))
+ ).findFirst().ifPresent(entry -> {
+ // The service properties of the extension should list any properties needed
+ // to configure OWB for web support.
+ properties.putAll(entry.getValue());
- startObject = new org.apache.aries.cdi.owb.web.UpdatableServletContext(bootstrap, clientBundleContext);
- services.put(org.apache.aries.cdi.owb.web.UpdatableServletContext.class, startObject);
- }
+ // The extension itself implements ServletContextEvent so set as the start object
+ startObject = entry.getKey();
+ });
bootstrap = new WebBeansContext(services, properties) {
private final ExtensionLoader overridenExtensionLoader = new ExtensionLoader(this) {
diff --git a/cdi-owb/src/main/java/org/apache/aries/cdi/owb/web/UpdatableServletContext.java b/cdi-owb/src/main/java/org/apache/aries/cdi/owb/web/UpdatableServletContext.java
deleted file mode 100644
index a732a3e..0000000
--- a/cdi-owb/src/main/java/org/apache/aries/cdi/owb/web/UpdatableServletContext.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/**
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.aries.cdi.owb.web;
-
-import static java.util.Optional.ofNullable;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Proxy;
-
-import javax.servlet.ServletContext;
-import javax.servlet.ServletContextEvent;
-
-import org.apache.webbeans.config.WebBeansContext;
-import org.apache.webbeans.web.lifecycle.test.MockServletContext;
-import org.osgi.framework.BundleContext;
-
-@SuppressWarnings("serial")
-public class UpdatableServletContext extends ServletContextEvent {
- private final WebBeansContext bootstrap;
- private final BundleContext bundleContext;
- private final ServletContext context;
- private ServletContext delegate;
-
- public UpdatableServletContext(WebBeansContext bootstrap, BundleContext bundleContext) {
- super(new MockServletContext());
- this.bootstrap = bootstrap;
- this.bundleContext = bundleContext;
-
- // ensure we can switch the impl and keep ServletContextBean working with an updated context
- this.context = ServletContext.class.cast(Proxy.newProxyInstance(ServletContext.class.getClassLoader(),
- new Class<?>[]{ServletContext.class},
- (proxy, method, args) -> {
- try {
- return method.invoke(ofNullable(delegate).orElseGet(UpdatableServletContext.super::getServletContext), args);
- }
- catch (final InvocationTargetException ite) {
- throw ite.getTargetException();
- }
- }));
- }
-
- public void setDelegate(final ServletContext delegate) {
- this.delegate = delegate;
- this.delegate.setAttribute(BundleContext.class.getName(), bundleContext);
- this.delegate.setAttribute(WebBeansContext.class.getName(), bootstrap);
- }
-
- public ServletContext getOriginal() {
- return super.getServletContext();
- }
-
- @Override
- public ServletContext getServletContext() {
- return context;
- }
-}
diff --git a/cdi-owb/src/main/java/org/apache/aries/cdi/owb/web/package-info.java b/cdi-owb/src/main/java/org/apache/aries/cdi/owb/web/package-info.java
deleted file mode 100644
index 2312388..0000000
--- a/cdi-owb/src/main/java/org/apache/aries/cdi/owb/web/package-info.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/**
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-@org.osgi.annotation.bundle.Capability(
- attribute = "objectClass:List<String>=javax.enterprise.inject.spi.Extension",
- namespace = SERVICE_NAMESPACE
-)
-@org.osgi.annotation.bundle.Capability(
- name = "aries.cdi.http",
- namespace = CDI_EXTENSION_PROPERTY,
- uses= {
- javax.annotation.Priority.class,
- javax.enterprise.context.spi.Context.class,
- javax.enterprise.event.Observes.class,
- javax.enterprise.inject.spi.Extension.class,
- javax.servlet.ServletContextListener.class,
- javax.servlet.http.HttpSessionListener.class
- },
- version = "1.0.0"
-)
-//Deliberately depend on Http Whiteboard version 1.0.0 (the spec annotation starts at 1.1.0)
-@org.osgi.annotation.bundle.Requirement(
- name = "osgi.http",
- namespace = IMPLEMENTATION_NAMESPACE,
- version = "1.0.0",
- resolution = OPTIONAL
-)
-@org.osgi.service.cdi.annotations.RequireCDIImplementation
-package org.apache.aries.cdi.owb.web;
-
-import static org.osgi.annotation.bundle.Requirement.Resolution.OPTIONAL;
-import static org.osgi.namespace.implementation.ImplementationNamespace.IMPLEMENTATION_NAMESPACE;
-import static org.osgi.namespace.service.ServiceNamespace.SERVICE_NAMESPACE;
-import static org.osgi.service.cdi.CDIConstants.CDI_EXTENSION_PROPERTY;
diff --git a/pom.xml b/pom.xml
index 4b70611..ca87fc5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -72,7 +72,8 @@
<module>cdi-spi</module>
<module>cdi-extender</module>
<module>cdi-extension-el-jsp</module>
- <module>cdi-extension-http</module>
+ <module>cdi-extension-http-owb</module>
+ <module>cdi-extension-http-weld</module>
<module>cdi-extension-jndi</module>
<module>cdi-extension-mp-config</module>
<module>cdi-extension-mp-metrics</module>