Author: rmannibucau
Date: Thu Jun 8 15:16:32 2017
New Revision: 1798078
URL: http://svn.apache.org/viewvc?rev=1798078&view=rev
Log:
OWB-1194 @AroundConstruct with EJB style interceptor
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/ConstructorInterceptorInvocationContext.java
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/constructor/AroundConstructTest.java
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/ConstructorInterceptorInvocationContext.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/ConstructorInterceptorInvocationContext.java?rev=1798078&r1=1798077&r2=1798078&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/ConstructorInterceptorInvocationContext.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/ConstructorInterceptorInvocationContext.java
Thu Jun 8 15:16:32 2017
@@ -42,6 +42,18 @@ public class ConstructorInterceptorInvoc
public Object getNewInstance()
{
+ if (newInstance == null)
+ {
+ try
+ {
+ directProceed();
+ return newInstance;
+ }
+ catch (final Exception e)
+ {
+ throw ExceptionUtil.throwAsRuntimeException(e);
+ }
+ }
return newInstance;
}
Modified:
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/constructor/AroundConstructTest.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/constructor/AroundConstructTest.java?rev=1798078&r1=1798077&r2=1798078&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/constructor/AroundConstructTest.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/constructor/AroundConstructTest.java
Thu Jun 8 15:16:32 2017
@@ -25,6 +25,7 @@ import javax.inject.Inject;
import javax.interceptor.AroundConstruct;
import javax.interceptor.Interceptor;
import javax.interceptor.InterceptorBinding;
+import javax.interceptor.Interceptors;
import javax.interceptor.InvocationContext;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
@@ -34,6 +35,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import static java.util.Arrays.asList;
import static org.junit.Assert.assertEquals;
public class AroundConstructTest extends AbstractUnitTest
@@ -52,8 +54,15 @@ public class AroundConstructTest extends
startContainer(beanClasses, Collections.<String>emptyList(), true);
assertEquals(1, IllGetYourConstructorInvocation.count);
- shutDownContainer();
+ }
+ @Test
+ public void ejbStyle()
+ {
+ OldStyle.count = 0;
+ startContainer(asList(Simple.class, OldStyle.class),
Collections.emptyList(), false);
+ getInstance(Simple.class).callForNothing();
+ assertEquals(1, OldStyle.count);
}
@ConstructorInterceptorBinding
@@ -76,6 +85,27 @@ public class AroundConstructTest extends
{
}
+ @Interceptors(OldStyle.class)
+ public static class Simple
+ {
+ public void callForNothing()
+ {
+ // no-op, just to ensure the bean exists
+ }
+ }
+
+ @Interceptor
+ public static class OldStyle
+ {
+ public static int count = 0;
+
+ @AroundConstruct
+ public void around(final InvocationContext ic)
+ {
+ count++;
+ }
+ }
+
@ConstructorInterceptorBinding
@Interceptor
public static class IllGetYourConstructorInvocation