You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by rm...@apache.org on 2021/01/04 07:04:07 UTC
[openwebbeans] branch master updated: [OWB-1365] enforce to create
interceptor stack if validation is skipped
This is an automated email from the ASF dual-hosted git repository.
rmannibucau pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openwebbeans.git
The following commit(s) were added to refs/heads/master by this push:
new e3315a6 [OWB-1365] enforce to create interceptor stack if validation is skipped
e3315a6 is described below
commit e3315a66ce71bf6fdbdac82566c97dc2bb7951d4
Author: Romain Manni-Bucau <rm...@gmail.com>
AuthorDate: Mon Jan 4 08:03:59 2021 +0100
[OWB-1365] enforce to create interceptor stack if validation is skipped
---
.../org/apache/webbeans/config/BeansDeployer.java | 45 ++++++++++++++++++++++
.../webbeans/test/config/BeansDeployerTest.java | 25 +++++++++++-
2 files changed, 69 insertions(+), 1 deletion(-)
diff --git a/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java b/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
index 5eaf2c3..576335f 100644
--- a/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
+++ b/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
@@ -331,6 +331,51 @@ public class BeansDeployer
validateNames();
}
+ else
+ {
+ webBeansContext.getBeanManagerImpl().getBeans().forEach(bean -> {
+ if (BuiltInOwbBean.class.isInstance(bean))
+ {
+ Class<?> proxyable = BuiltInOwbBean.class.cast(bean).proxyableType();
+ if (proxyable != null)
+ {
+ AbstractProducer producer = AbstractProducer.class.cast(OwbBean.class.cast(bean).getProducer());
+ AnnotatedType<?> annotatedType = webBeansContext.getAnnotatedElementFactory()
+ .newAnnotatedType(proxyable);
+ producer.defineInterceptorStack(bean, annotatedType, webBeansContext);
+ }
+ }
+ else if (bean instanceof OwbBean &&
+ !(bean instanceof Interceptor) &&
+ !(bean instanceof Decorator))
+ {
+ AbstractProducer producer = null;
+ OwbBean<?> owbBean = (OwbBean<?>) bean;
+ if (ManagedBean.class.isInstance(bean)) // in this case don't use producer which can be wrapped
+ {
+ producer = ManagedBean.class.cast(bean).getOriginalInjectionTarget();
+ }
+ if (producer == null && owbBean.getProducer() instanceof AbstractProducer)
+ {
+ producer = (AbstractProducer) owbBean.getProducer();
+ }
+ if (producer != null)
+ {
+ AnnotatedType<?> annotatedType;
+ if (owbBean instanceof InjectionTargetBean)
+ {
+ annotatedType = ((InjectionTargetBean<?>) owbBean).getAnnotatedType();
+ }
+ else
+ {
+ annotatedType = webBeansContext.getAnnotatedElementFactory()
+ .newAnnotatedType(owbBean.getReturnType());
+ }
+ producer.defineInterceptorStack(owbBean, annotatedType, webBeansContext);
+ }
+ }
+ });
+ }
if (webBeansContext.getNotificationManager().getObserverMethods().stream()
.anyMatch(ObserverMethod::isAsync))
diff --git a/webbeans-impl/src/test/java/org/apache/webbeans/test/config/BeansDeployerTest.java b/webbeans-impl/src/test/java/org/apache/webbeans/test/config/BeansDeployerTest.java
index eae8d86..f0b6b49 100644
--- a/webbeans-impl/src/test/java/org/apache/webbeans/test/config/BeansDeployerTest.java
+++ b/webbeans-impl/src/test/java/org/apache/webbeans/test/config/BeansDeployerTest.java
@@ -18,6 +18,7 @@
*/
package org.apache.webbeans.test.config;
+import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
import static java.util.logging.Level.FINE;
import static org.junit.Assert.assertEquals;
@@ -32,6 +33,7 @@ import java.util.logging.LogRecord;
import java.util.logging.Logger;
import javax.annotation.Priority;
+import javax.enterprise.context.ApplicationScoped;
import javax.interceptor.AroundInvoke;
import javax.interceptor.Interceptor;
import javax.interceptor.InvocationContext;
@@ -49,6 +51,17 @@ public class BeansDeployerTest extends AbstractUnitTest
public final TestName testName = new TestName();
@Test
+ public void skipValidations()
+ {
+ addConfiguration("org.apache.webbeans.spi.deployer.skipValidations", "true");
+ startContainer(asList(TransactionalInterceptor.class, MyService.class),
+ singletonList(Thread.currentThread().getContextClassLoader()
+ .getResource(getClass().getName().replace('.', '/') + "/interceptorLogging/beans.xml")
+ .toExternalForm()));
+ assertEquals("tx", getInstance(MyService.class).tx());
+ }
+
+ @Test
public void interceptorLogging()
{
final Logger logger = Logger.getLogger(BeansDeployer.class.getName());
@@ -106,6 +119,16 @@ public class BeansDeployerTest extends AbstractUnitTest
" is already defined with priority 1000", record.getMessage());
}
+ @ApplicationScoped
+ public static class MyService
+ {
+ @Transactional
+ public String tx()
+ {
+ return "service";
+ }
+ }
+
@Interceptor
@Transactional
@Priority(Interceptor.Priority.LIBRARY_BEFORE)
@@ -114,7 +137,7 @@ public class BeansDeployerTest extends AbstractUnitTest
@AroundInvoke
public Object caller(final InvocationContext context) throws Exception
{
- return null;
+ return "tx";
}
}
}