You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2016/08/13 16:03:40 UTC
tomee git commit: moving cdi activation for EJB modules earlier to
scan modules (ie respect the spec)
Repository: tomee
Updated Branches:
refs/heads/master c72fb7204 -> df25e829d
moving cdi activation for EJB modules earlier to scan modules (ie respect the spec)
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/df25e829
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/df25e829
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/df25e829
Branch: refs/heads/master
Commit: df25e829d9313b19fe5d8c6172eccfb1cbfb671b
Parents: c72fb72
Author: Romain manni-Bucau <rm...@gmail.com>
Authored: Sat Aug 13 18:01:26 2016 +0200
Committer: Romain manni-Bucau <rm...@gmail.com>
Committed: Sat Aug 13 18:01:26 2016 +0200
----------------------------------------------------------------------
.../java/org/apache/openejb/cdi/CdiEjbBean.java | 9 ++
.../openejb/config/AnnotationDeployer.java | 90 ++++++++++++--------
.../openejb/config/EjbJarInfoBuilder.java | 23 -----
.../cxf/rs/CdiConstructorInjectionTest.java | 2 +
.../openejb/server/cxf/rs/EJBProviderTest.java | 2 +
5 files changed, 66 insertions(+), 60 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tomee/blob/df25e829/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiEjbBean.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiEjbBean.java b/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiEjbBean.java
index 9e5c809..30d381e 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiEjbBean.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiEjbBean.java
@@ -454,6 +454,15 @@ public class CdiEjbBean<T> extends BaseEjbBean<T> implements InterceptedMarker,
}
@Override
+ public void defineInterceptorStack(final Bean<T> bean, final AnnotatedType<T> annotatedType, final WebBeansContext webBeansContext) {
+ super.defineInterceptorStack(bean,
+ isDynamicBean(bean) ?
+ (AnnotatedType<T>) webBeansContext.getAnnotatedElementFactory()
+ .newAnnotatedType(CdiEjbBean.class.cast(bean).getBeanContext().getManagedClass()) : annotatedType,
+ webBeansContext);
+ }
+
+ @Override
protected boolean needsProxy() {
return !bean.beanContext.isDynamicallyImplemented() && super.needsProxy();
}
http://git-wip-us.apache.org/repos/asf/tomee/blob/df25e829/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java b/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
index 93fcf5b..528fb33 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
@@ -246,6 +246,8 @@ import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
@@ -1298,43 +1300,6 @@ public class AnnotationDeployer implements DynamicDeployer {
final IAnnotationFinder finder = ejbModule.getFinder();
-
- final Map<URL, List<String>> managedClasses;
- {
- final Beans beans = ejbModule.getBeans();
-
- if (beans != null) {
- managedClasses = beans.getManagedClasses();
- getBeanClasses(beans.getUri(), finder, managedClasses, beans.getNotManagedClasses(), ejbModule.getAltDDs());
-
- // passing jar location to be able to manage maven classes/test-classes which have the same moduleId
- String id = ejbModule.getModuleId();
- if (ejbModule.getJarLocation() != null &&
- (ejbModule.getJarLocation().contains(ejbModule.getModuleId() + "/target/test-classes".replace("/", File.separator)) ||
- ejbModule.getJarLocation().contains(ejbModule.getModuleId() + "/build/classes/test".replace("/", File.separator)))) {
- // with maven/gradle if both src/main/java and src/test/java are deployed
- // moduleId.Comp exists twice so it fails
- // here we simply modify the test comp bean name to avoid it
- id += "_test";
- }
- final String name = BeanContext.Comp.openejbCompName(id);
- final org.apache.openejb.jee.ManagedBean managedBean = new CompManagedBean(name, BeanContext.Comp.class);
- managedBean.setTransactionType(TransactionType.BEAN);
- ejbModule.getEjbJar().addEnterpriseBean(managedBean);
-
- if ("true".equals(SystemInstance.get().getProperty("openejb.cdi.support.@Startup", "true"))) {
- final List<Annotated<Class<?>>> forceStart = finder.findMetaAnnotatedClasses(Startup.class);
- final List<String> startupBeans = beans.getStartupBeans();
- for (final Annotated<Class<?>> clazz : forceStart) {
- startupBeans.add(clazz.get().getName());
- }
- }
- } else {
- managedClasses = new HashMap<>();
- }
- }
-
-
// Fill in default sessionType for xml declared EJBs
for (final EnterpriseBean bean : ejbModule.getEjbJar().getEnterpriseBeans()) {
if (!(bean instanceof SessionBean)) {
@@ -1534,6 +1499,57 @@ public class AnnotationDeployer implements DynamicDeployer {
}
}
+ { // after having found EJB for auto CDI activation
+ final Map<URL, List<String>> managedClasses;
+ Beans beans = ejbModule.getBeans();
+ if (beans == null && !ejbModule.getEjbJar().getEnterpriseBeansByEjbName().isEmpty()
+ && Boolean.parseBoolean(ejbModule.getProperties().getProperty("openejb.cdi.activated", "true"))
+ && Boolean.parseBoolean(SystemInstance.get().getProperty("openejb.cdi.activated-on-ejb", "true"))) {
+ logger.info("Activating CDI in ACTIVATED mode in module '" + ejbModule.getModuleUri() + "' cause EJB were found\n" +
+ " add openejb.cdi.activated=false in application.properties to switch it off or\n" +
+ " openejb.cdi.activated-on-ejb=false in conf/system.properties" +
+ " to switch it off");
+ beans = new Beans();
+ beans.setBeanDiscoveryMode("ANNOTATED");
+ beans.setVersion("1.1");
+ try {
+ ejbModule.getModuleUri().toURL();
+ beans.setUri(ejbModule.getModuleUri().toASCIIString());
+ } catch (final MalformedURLException | IllegalArgumentException iae) { // test? fake a URI
+ beans.setUri(URI.create("jar:file://!/" + ejbModule.getModuleUri().toASCIIString() + "/META-INF/beans.xml").toASCIIString());
+ }
+ ejbModule.setBeans(beans);
+ }
+
+ if (beans != null) {
+ managedClasses = beans.getManagedClasses();
+ getBeanClasses(beans.getUri(), finder, managedClasses, beans.getNotManagedClasses(), ejbModule.getAltDDs());
+
+ // passing jar location to be able to manage maven classes/test-classes which have the same moduleId
+ String id = ejbModule.getModuleId();
+ if (ejbModule.getJarLocation() != null &&
+ (ejbModule.getJarLocation().contains(ejbModule.getModuleId() + "/target/test-classes".replace("/", File.separator)) ||
+ ejbModule.getJarLocation().contains(ejbModule.getModuleId() + "/build/classes/test".replace("/", File.separator)))) {
+ // with maven/gradle if both src/main/java and src/test/java are deployed
+ // moduleId.Comp exists twice so it fails
+ // here we simply modify the test comp bean name to avoid it
+ id += "_test";
+ }
+ final String name = BeanContext.Comp.openejbCompName(id);
+ final org.apache.openejb.jee.ManagedBean managedBean = new CompManagedBean(name, BeanContext.Comp.class);
+ managedBean.setTransactionType(TransactionType.BEAN);
+ ejbModule.getEjbJar().addEnterpriseBean(managedBean);
+
+ if ("true".equals(SystemInstance.get().getProperty("openejb.cdi.support.@Startup", "true"))) {
+ final List<Annotated<Class<?>>> forceStart = finder.findMetaAnnotatedClasses(Startup.class);
+ final List<String> startupBeans = beans.getStartupBeans();
+ for (final Annotated<Class<?>> clazz : forceStart) {
+ startupBeans.add(clazz.get().getName());
+ }
+ }
+ }
+ }
+
// ejb can be rest bean and only then in standalone so scan providers here too
// adding them to app since they should be in the app classloader
if (ejbModule.getAppModule() != null) {
http://git-wip-us.apache.org/repos/asf/tomee/blob/df25e829/container/openejb-core/src/main/java/org/apache/openejb/config/EjbJarInfoBuilder.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/config/EjbJarInfoBuilder.java b/container/openejb-core/src/main/java/org/apache/openejb/config/EjbJarInfoBuilder.java
index bf3e7c0..1d0ba80 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/config/EjbJarInfoBuilder.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/config/EjbJarInfoBuilder.java
@@ -102,7 +102,6 @@ import org.apache.openejb.util.Messages;
import org.apache.webbeans.spi.BeanArchiveService;
import java.net.MalformedURLException;
-import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
@@ -314,28 +313,6 @@ public class EjbJarInfoBuilder {
bda.decorators.addAll(beans.getDecorators());
bda.stereotypeAlternatives.addAll(beans.getAlternativeStereotypes());
}
- } else if (!ejbJar.enterpriseBeans.isEmpty() && Boolean.parseBoolean(jar.getProperties().getProperty("openejb.cdi.activated", "true"))) {
- // TOMEE-1901
- ejbJar.beans = new BeansInfo();
- ejbJar.beans.version = "1.1";
- ejbJar.beans.discoveryMode = "ANNOTATED";
-
-
- final BeansInfo.BDAInfo bdaInfo = new BeansInfo.BDAInfo();
- try {
- bdaInfo.uri = ejbJar.moduleUri == null ? DEFAULT_BEANS_XML_KEY.toURI() : ejbJar.moduleUri;
- try {
- bdaInfo.uri.toURL();
- } catch (final MalformedURLException | IllegalArgumentException iae) { // test? fake a URI
- bdaInfo.uri = URI.create("jar:file://!/" + bdaInfo.uri.toASCIIString() + "/META-INF/beans.xml");
- }
- } catch (final URISyntaxException e) {
- logger.warning(e.getMessage(), e);
- }
- ejbJar.beans.noDescriptorBdas.add(bdaInfo);
- for (final EnterpriseBeanInfo ebi : ejbJar.enterpriseBeans) {
- bdaInfo.managedClasses.add(ebi.ejbClass);
- }
}
return ejbJar;
http://git-wip-us.apache.org/repos/asf/tomee/blob/df25e829/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/CdiConstructorInjectionTest.java
----------------------------------------------------------------------
diff --git a/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/CdiConstructorInjectionTest.java b/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/CdiConstructorInjectionTest.java
index 72b70eb..7b2a643c 100644
--- a/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/CdiConstructorInjectionTest.java
+++ b/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/CdiConstructorInjectionTest.java
@@ -30,6 +30,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.context.Dependent;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.GET;
@@ -77,6 +78,7 @@ public class CdiConstructorInjectionTest {
assertEquals("GET", WebClient.create("http://localhost:" + port + "/app").path("/bar").get(String.class));
}
+ @Dependent
public static class Service {
public String bar() {
return "service";
http://git-wip-us.apache.org/repos/asf/tomee/blob/df25e829/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/EJBProviderTest.java
----------------------------------------------------------------------
diff --git a/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/EJBProviderTest.java b/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/EJBProviderTest.java
index 91bd323..88ee612 100644
--- a/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/EJBProviderTest.java
+++ b/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/EJBProviderTest.java
@@ -30,6 +30,7 @@ import javax.annotation.Resource;
import javax.ejb.LocalBean;
import javax.ejb.SessionContext;
import javax.ejb.Singleton;
+import javax.enterprise.context.Dependent;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
@@ -108,6 +109,7 @@ public class EJBProviderTest {
}
}
+ @Dependent
public static class Helper {
String data() {
return "Oh Yeah!";