Permalink
Browse files

AS7-4430 InterceptorContext.getTarget() returns null for PrePassivate…

… and PostActivate methods
  • Loading branch information...
1 parent 57aab58 commit 97e9c62eb8a827e46612a4fa6573093d3581c09d @stuartwdouglas stuartwdouglas committed Apr 9, 2012
View
1 .../src/main/java/org/jboss/as/ejb3/component/stateful/StatefulSessionComponentInstance.java
@@ -141,6 +141,7 @@ private Object execute(final Interceptor interceptor, final Method method, final
interceptorContext.putPrivateData(ComponentInstance.class, this);
interceptorContext.putPrivateData(InvokeMethodOnTargetInterceptor.PARAMETERS_KEY, parameters);
interceptorContext.setContextData(new HashMap<String, Object>());
+ interceptorContext.setTarget(getInstance());
try {
return interceptor.processInvocation(interceptorContext);
} catch (Error e) {
View
38 ...t/java/org/jboss/as/test/integration/ejb/stateful/passivation/PassivationInterceptor.java
@@ -0,0 +1,38 @@
+package org.jboss.as.test.integration.ejb.stateful.passivation;
+
+import java.io.Serializable;
+
+import javax.ejb.PostActivate;
+import javax.ejb.PrePassivate;
+import javax.interceptor.InvocationContext;
+
+/**
+ * @author Stuart Douglas
+ */
+public class PassivationInterceptor implements Serializable {
+
+ private static volatile Object postActivateTarget, prePassivateTarget;
+
+ @PostActivate
+ public void postActivate(final InvocationContext ctx) throws Exception {
+ postActivateTarget = ctx.getTarget();
+ ctx.proceed();
+ }
+ @PrePassivate
+ public void prePassivate(final InvocationContext ctx) throws Exception {
+ prePassivateTarget = ctx.getTarget();
+ ctx.proceed();
+ }
+
+ public static void reset() {
+ postActivateTarget = prePassivateTarget = null;
+ }
+
+ public static Object getPostActivateTarget() {
+ return postActivateTarget;
+ }
+
+ public static Object getPrePassivateTarget() {
+ return prePassivateTarget;
+ }
+}
View
6 ...g/jboss/as/test/integration/ejb/stateful/passivation/PassivationSucceedsUnitTestCase.java
@@ -122,6 +122,7 @@ private static ModelNode getAddress() {
@Test
public void testPassivationMaxSize() throws Exception {
+ PassivationInterceptor.reset();
TestPassivationRemote remote1 = (TestPassivationRemote) ctx.lookup("java:module/"
+ TestPassivationBean.class.getSimpleName());
Assert.assertEquals("Returned remote1 result was not expected", TestPassivationRemote.EXPECTED_RESULT,
@@ -149,10 +150,13 @@ public void testPassivationMaxSize() throws Exception {
remote1.remove();
remote2.remove();
+ Assert.assertTrue(PassivationInterceptor.getPostActivateTarget() instanceof TestPassivationBean);
+ Assert.assertTrue(PassivationInterceptor.getPrePassivateTarget() instanceof TestPassivationBean);
}
@Test
public void testPassivationIdleTimeout() throws Exception {
+ PassivationInterceptor.reset();
// Lookup and create stateful instance
TestPassivationRemote remote = (TestPassivationRemote) ctx.lookup("java:module/"
+ TestPassivationBean.class.getSimpleName());
@@ -169,5 +173,7 @@ public void testPassivationIdleTimeout() throws Exception {
// Ensure that @PrePassivate was called during the client sleep
Assert.assertTrue("@PrePassivate not called, check CacheConfig and client sleep time", remote.hasBeenPassivated());
remote.remove();
+ Assert.assertTrue(PassivationInterceptor.getPostActivateTarget() instanceof TestPassivationBean);
+ Assert.assertTrue(PassivationInterceptor.getPrePassivateTarget() instanceof TestPassivationBean);
}
}
View
2 ...test/java/org/jboss/as/test/integration/ejb/stateful/passivation/TestPassivationBean.java
@@ -32,6 +32,7 @@
import javax.ejb.Remote;
import javax.ejb.Remove;
import javax.ejb.Stateful;
+import javax.interceptor.Interceptors;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceContextType;
@@ -44,6 +45,7 @@
@Stateful
@Remote(TestPassivationRemote.class)
@Cache("passivating")
+@Interceptors(PassivationInterceptor.class)
public class TestPassivationBean extends PassivationSuperClass implements TestPassivationRemote {
private static final Logger log = Logger.getLogger(TestPassivationBean.class);

0 comments on commit 97e9c62

Please sign in to comment.