[jboss-cvs] JBossAS SVN: r104289 - in projects/ejb3/trunk/interceptors: src/main/java/org/jboss/ejb3/interceptors/aop and 3 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Apr 28 04:49:37 EDT 2010
Author: wolfc
Date: 2010-04-28 04:49:35 -0400 (Wed, 28 Apr 2010)
New Revision: 104289
Added:
projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/interceptors/test/ejbthree2080/
projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/interceptors/test/ejbthree2080/MyStateMachine.java
projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/interceptors/test/ejbthree2080/StateMachineLocal.java
projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/interceptors/test/ejbthree2080/unit/
projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/interceptors/test/ejbthree2080/unit/AOPWeirdnessTestCase.java
Modified:
projects/ejb3/trunk/interceptors/pom.xml
projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/InjectInterceptorsFactory.java
Log:
EJBTHREE-2080: ignore static methods
Modified: projects/ejb3/trunk/interceptors/pom.xml
===================================================================
--- projects/ejb3/trunk/interceptors/pom.xml 2010-04-28 07:52:18 UTC (rev 104288)
+++ projects/ejb3/trunk/interceptors/pom.xml 2010-04-28 08:49:35 UTC (rev 104289)
@@ -36,8 +36,10 @@
<echo message="aopc in action" />
+ <!--suppress MavenModelInspection -->
<taskdef name="aopc" classname="org.jboss.aop.ant.AopC" classpath="${cp}" />
+ <!--suppress MavenModelInspection -->
<aopc compilerclasspath="${cp}" verbose="true">
<aoppath path="${basedir}/src/test/resources/ejbthree1950/jboss-aop.xml" />
<!--
@@ -137,5 +139,11 @@
<version>2.0.0.CR1</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <version>1.8.4</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
Modified: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/InjectInterceptorsFactory.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/InjectInterceptorsFactory.java 2010-04-28 07:52:18 UTC (rev 104288)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/InjectInterceptorsFactory.java 2010-04-28 08:49:35 UTC (rev 104289)
@@ -21,17 +21,6 @@
*/
package org.jboss.ejb3.interceptors.aop;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-import javax.annotation.PostConstruct;
-import javax.interceptor.AroundInvoke;
-import javax.interceptor.ExcludeClassInterceptors;
-import javax.interceptor.ExcludeDefaultInterceptors;
-import javax.interceptor.InvocationContext;
-
import org.jboss.aop.Advisor;
import org.jboss.aop.InstanceAdvisor;
import org.jboss.aop.advice.Interceptor;
@@ -43,6 +32,17 @@
import org.jboss.ejb3.interceptors.lang.ClassHelper;
import org.jboss.logging.Logger;
+import javax.annotation.PostConstruct;
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.ExcludeClassInterceptors;
+import javax.interceptor.ExcludeDefaultInterceptors;
+import javax.interceptor.InvocationContext;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
/**
* Comment
*
@@ -169,7 +169,9 @@
@Override
public Object createPerJoinpoint(Advisor advisor, Joinpoint jp)
{
- log.warn("WEIRDNESS IN AOP: advisor " + advisor);
+ // EJBTHREE-2080: we can ignore static methods, because no instance is available then
+ if(!isStaticMethodJoinpoint(jp))
+ log.warn("EJBTHREE-2080: WEIRDNESS IN AOP: advisor " + advisor + " on joinpoint " + jp);
return new InterceptorSequencer(new Interceptor[0]);
// If we're not running instrumented classes there is no instance advisor during
// construction. (I've no clue why.)
@@ -189,4 +191,10 @@
{
return advisor.hasAnnotation(method, ExcludeDefaultInterceptors.class) || advisor.resolveAnnotation(ExcludeDefaultInterceptors.class) != null;
}
+
+ private static boolean isStaticMethodJoinpoint(Joinpoint jp)
+ {
+ return((jp instanceof MethodJoinpoint) &&
+ Modifier.isStatic(((MethodJoinpoint) jp).getMethod().getModifiers()));
+ }
}
Added: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/interceptors/test/ejbthree2080/MyStateMachine.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/interceptors/test/ejbthree2080/MyStateMachine.java (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/interceptors/test/ejbthree2080/MyStateMachine.java 2010-04-28 08:49:35 UTC (rev 104289)
@@ -0,0 +1,76 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright (c) 2010, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.interceptors.test.ejbthree2080;
+
+import javax.annotation.PostConstruct;
+import javax.ejb.Stateful;
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.InvocationContext;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import static org.jboss.ejb3.interceptors.test.ejbthree2080.StateMachineLocal.State.*;
+
+/**
+ * @author <a href="cdewolf at redhat.com">Carlo de Wolf</a>
+ */
+ at Stateful
+public class MyStateMachine implements StateMachineLocal
+{
+ private static AtomicInteger invocations = new AtomicInteger(0);
+ private State state;
+
+ /**
+ * To make sure InjectInterceptorsFactory is in there.
+ */
+ @AroundInvoke
+ public Object aroundInvoke(InvocationContext ctx) throws Exception
+ {
+ invocations.incrementAndGet();
+ return ctx.proceed();
+ }
+
+ @PostConstruct
+ protected void initialize()
+ {
+ this.state = INITIALIZED;
+ }
+
+ public static int invocations()
+ {
+ return invocations.getAndSet(0);
+ }
+
+ public static String mapState(State state)
+ {
+ return state.name();
+ }
+
+ public void start()
+ {
+ this.state = STARTED;
+ }
+
+ public void stop()
+ {
+ this.state = STOPPED;
+ }
+}
Added: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/interceptors/test/ejbthree2080/StateMachineLocal.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/interceptors/test/ejbthree2080/StateMachineLocal.java (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/interceptors/test/ejbthree2080/StateMachineLocal.java 2010-04-28 08:49:35 UTC (rev 104289)
@@ -0,0 +1,41 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright (c) 2010, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.interceptors.test.ejbthree2080;
+
+import javax.ejb.Local;
+
+/**
+ * @author <a href="cdewolf at redhat.com">Carlo de Wolf</a>
+ */
+ at Local
+public interface StateMachineLocal
+{
+ public enum State
+ {
+ INITIALIZED,
+ STARTED,
+ STOPPED,
+ }
+
+ void start();
+ void stop();
+}
Added: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/interceptors/test/ejbthree2080/unit/AOPWeirdnessTestCase.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/interceptors/test/ejbthree2080/unit/AOPWeirdnessTestCase.java (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/interceptors/test/ejbthree2080/unit/AOPWeirdnessTestCase.java 2010-04-28 08:49:35 UTC (rev 104289)
@@ -0,0 +1,94 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright (c) 2010, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.interceptors.test.ejbthree2080.unit;
+
+import org.apache.log4j.Appender;
+import org.apache.log4j.spi.LoggingEvent;
+import org.jboss.aspects.common.AOPDeployer;
+import org.jboss.ejb3.interceptors.aop.InjectInterceptorsFactory;
+import org.jboss.ejb3.interceptors.proxy.ProxyContainer;
+import org.jboss.ejb3.interceptors.test.ejbthree2080.MyStateMachine;
+import org.jboss.ejb3.interceptors.test.ejbthree2080.StateMachineLocal;
+import org.jboss.logging.Logger;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.mockito.ArgumentMatcher;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.*;
+
+/**
+ * @author <a href="cdewolf at redhat.com">Carlo de Wolf</a>
+ */
+public class AOPWeirdnessTestCase
+{
+ private static final Logger log = Logger.getLogger(AOPWeirdnessTestCase.class);
+ private static AOPDeployer deployer = new AOPDeployer("proxy/jboss-aop.xml");
+
+ @AfterClass
+ public static void afterClass()
+ {
+ log.info(deployer.undeploy());
+ }
+
+ @BeforeClass
+ public static void beforeClass() throws Exception
+ {
+ log.info(deployer.deploy());
+ }
+
+ @Test
+ public void test1() throws Throwable
+ {
+ Appender appender = mock(Appender.class);
+ doThrow(new AssertionError("logging WEIRDNESS IN AOP")).when(appender).doAppend(weirdnessInAOP());
+ org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(InjectInterceptorsFactory.class);
+ logger.addAppender(appender);
+ try
+ {
+ ProxyContainer<MyStateMachine> container = new ProxyContainer<MyStateMachine>("AOPWeirdnessTestCase", "InterceptorContainer", MyStateMachine.class);
+
+ Class<?> interfaces[] = { StateMachineLocal.class };
+ StateMachineLocal proxy = container.constructProxy(interfaces);
+
+ proxy.start();
+
+ assertEquals(1, MyStateMachine.invocations());
+ }
+ finally
+ {
+ logger.removeAppender(appender);
+ }
+ }
+
+ private static LoggingEvent weirdnessInAOP()
+ {
+ return argThat(new ArgumentMatcher<LoggingEvent>() {
+ @Override
+ public boolean matches(Object argument)
+ {
+ return ((LoggingEvent) argument).getRenderedMessage().contains("WEIRDNESS IN AOP");
+ }
+ });
+ }
+}
More information about the jboss-cvs-commits
mailing list