You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by jl...@apache.org on 2007/12/28 21:15:07 UTC

svn commit: r607320 - in /openejb/trunk/openejb3: container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ examples/interceptors/src/main/java/org/superbiz/interceptors/ examples/interceptors/src/test/java/org/superbiz/interceptors/

Author: jlaskowski
Date: Fri Dec 28 12:15:06 2007
New Revision: 607320

URL: http://svn.apache.org/viewvc?rev=607320&view=rev
Log:
Some changes while fixing OPENEJB-583 Method-level @ExcludeClassInterceptors disables class-level @ExcludeDefaultInterceptors:

 o example to reproduce the issue with (disabled) tests
 o small yet important typo fix to understand what DMB had in mind while writing the code ;-)
 o small and (un)important fixes for how interceptors are handled

Added:
    openejb/trunk/openejb3/examples/interceptors/src/main/java/org/superbiz/interceptors/ThirdSLSBean.java   (with props)
    openejb/trunk/openejb3/examples/interceptors/src/main/java/org/superbiz/interceptors/ThirdSLSBeanLocal.java   (with props)
    openejb/trunk/openejb3/examples/interceptors/src/test/java/org/superbiz/interceptors/ThirdSLSBeanTest.java   (with props)
Modified:
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/InterceptorBindingBuilder.java

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/InterceptorBindingBuilder.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/InterceptorBindingBuilder.java?rev=607320&r1=607319&r2=607320&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/InterceptorBindingBuilder.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/InterceptorBindingBuilder.java Fri Dec 28 12:15:06 2007
@@ -222,7 +222,7 @@
     private List<InterceptorBindingInfo> processBindings(Method method, String ejbName, List<InterceptorBindingInfo> bindings){
         List<InterceptorBindingInfo> methodBindings = new ArrayList<InterceptorBindingInfo>();
 
-        // The only critical thing to understand in this loop as that
+        // The only critical thing to understand in this loop is that
         // the bindings have already been sorted high to low (first to last)
         // in this order:
         //
@@ -274,8 +274,10 @@
                 excludes.add(level);
                 continue;
             }
-
-            methodBindings.add(info);
+            boolean excludeInterceptorsOnly = info.interceptors.size() == 0 && info.interceptorOrder.size() == 0;
+            if (!excludeInterceptorsOnly) {
+                methodBindings.add(info);
+            }
             if (info.excludeClassInterceptors) excludes.add(Level.CLASS);
             if (info.excludeDefaultInterceptors) excludes.add(Level.PACKAGE);
         }
@@ -293,7 +295,7 @@
 
         // do we have parameters?
         List<String> params = methodInfo.methodParams;
-        if (params == null) return true;
+        if (params == null || params.size() == 0) return true;
 
         // do we have the same number of parameters?
         if (params.size() != method.getParameterTypes().length) return false;
@@ -340,10 +342,15 @@
     }
 
     private static Type type(Level level, InterceptorBindingInfo info) {
-        if (info.interceptorOrder.size() > 0) return Type.EXPLICIT_ORDERING;
-        if (level == Level.CLASS && info.excludeClassInterceptors && info.excludeDefaultInterceptors)
+        if (info.interceptorOrder.size() > 0) {
+            return Type.EXPLICIT_ORDERING;
+        }
+        if (level == Level.CLASS && info.excludeClassInterceptors && info.excludeDefaultInterceptors) {
             return Type.SAME_AND_LOWER_EXCLUSION;
-        if (level == Level.CLASS && info.excludeClassInterceptors) return Type.SAME_LEVEL_EXCLUSION;
+        }
+        if (level == Level.CLASS && info.excludeClassInterceptors) {
+            return Type.SAME_LEVEL_EXCLUSION;
+        }
         return Type.ADDITION_OR_LOWER_EXCLUSION;
     }
 

Added: openejb/trunk/openejb3/examples/interceptors/src/main/java/org/superbiz/interceptors/ThirdSLSBean.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/interceptors/src/main/java/org/superbiz/interceptors/ThirdSLSBean.java?rev=607320&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/interceptors/src/main/java/org/superbiz/interceptors/ThirdSLSBean.java (added)
+++ openejb/trunk/openejb3/examples/interceptors/src/main/java/org/superbiz/interceptors/ThirdSLSBean.java Fri Dec 28 12:15:06 2007
@@ -0,0 +1,52 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.superbiz.interceptors;
+
+import javax.ejb.Stateless;
+import javax.interceptor.*;
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * @version $Rev$ $Date$
+ */
+@Stateless
+@Interceptors({ClassLevelInterceptorOne.class, ClassLevelInterceptorTwo.class})
+@ExcludeDefaultInterceptors
+public class ThirdSLSBean implements ThirdSLSBeanLocal {
+
+    @Interceptors({MethodLevelInterceptorOne.class, MethodLevelInterceptorTwo.class})
+    public List<String> businessMethod() {
+        List<String> list = new ArrayList<String>();
+        list.add("businessMethod");
+        return list;
+    }
+
+    @Interceptors({MethodLevelInterceptorOne.class, MethodLevelInterceptorTwo.class})    
+    @ExcludeClassInterceptors
+    public List<String> anotherBusinessMethod() {
+        List<String> list = new ArrayList<String>();
+        list.add("anotherBusinessMethod");
+        return list;
+    }
+
+
+    @AroundInvoke
+    protected Object beanClassBusinessMethodInterceptor(InvocationContext ic) throws Exception {
+        return Utils.addClassSimpleName(ic, this.getClass().getSimpleName());
+    }    
+}

Propchange: openejb/trunk/openejb3/examples/interceptors/src/main/java/org/superbiz/interceptors/ThirdSLSBean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: openejb/trunk/openejb3/examples/interceptors/src/main/java/org/superbiz/interceptors/ThirdSLSBean.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: openejb/trunk/openejb3/examples/interceptors/src/main/java/org/superbiz/interceptors/ThirdSLSBean.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: openejb/trunk/openejb3/examples/interceptors/src/main/java/org/superbiz/interceptors/ThirdSLSBean.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: openejb/trunk/openejb3/examples/interceptors/src/main/java/org/superbiz/interceptors/ThirdSLSBeanLocal.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/interceptors/src/main/java/org/superbiz/interceptors/ThirdSLSBeanLocal.java?rev=607320&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/interceptors/src/main/java/org/superbiz/interceptors/ThirdSLSBeanLocal.java (added)
+++ openejb/trunk/openejb3/examples/interceptors/src/main/java/org/superbiz/interceptors/ThirdSLSBeanLocal.java Fri Dec 28 12:15:06 2007
@@ -0,0 +1,28 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.superbiz.interceptors;
+
+import java.util.List;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface ThirdSLSBeanLocal {
+    List<String> businessMethod();
+
+    List<String> anotherBusinessMethod();
+}

Propchange: openejb/trunk/openejb3/examples/interceptors/src/main/java/org/superbiz/interceptors/ThirdSLSBeanLocal.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: openejb/trunk/openejb3/examples/interceptors/src/main/java/org/superbiz/interceptors/ThirdSLSBeanLocal.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: openejb/trunk/openejb3/examples/interceptors/src/main/java/org/superbiz/interceptors/ThirdSLSBeanLocal.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: openejb/trunk/openejb3/examples/interceptors/src/main/java/org/superbiz/interceptors/ThirdSLSBeanLocal.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: openejb/trunk/openejb3/examples/interceptors/src/test/java/org/superbiz/interceptors/ThirdSLSBeanTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/interceptors/src/test/java/org/superbiz/interceptors/ThirdSLSBeanTest.java?rev=607320&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/interceptors/src/test/java/org/superbiz/interceptors/ThirdSLSBeanTest.java (added)
+++ openejb/trunk/openejb3/examples/interceptors/src/test/java/org/superbiz/interceptors/ThirdSLSBeanTest.java Fri Dec 28 12:15:06 2007
@@ -0,0 +1,78 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.superbiz.interceptors;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import javax.naming.InitialContext;
+import javax.naming.Context;
+import java.util.Properties;
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ThirdSLSBeanTest {
+    private InitialContext initCtx;
+
+    @Before
+    public void setUp() throws Exception {
+        Properties properties = new Properties();
+        properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory");
+        properties.setProperty("openejb.deployments.classpath.include", ".*interceptors/target/classes.*");
+
+        initCtx = new InitialContext(properties);
+    }
+
+    // TODO: Enable it once OPENEJB-583 gets fixed
+    //@Test
+    public void testMethodWithDefaultInterceptorsExcluded() throws Exception {
+        ThirdSLSBeanLocal bean = (ThirdSLSBeanLocal) initCtx.lookup("ThirdSLSBeanLocal");
+
+        assert bean != null;
+
+        List<String> expected = new ArrayList<String>();
+        expected.add("ClassLevelInterceptorOne");
+        expected.add("ClassLevelInterceptorTwo");
+        expected.add("MethodLevelInterceptorOne");
+        expected.add("MethodLevelInterceptorTwo");
+        expected.add("ThirdSLSBean");
+        expected.add("businessMethod");
+
+        List<String> actual = bean.businessMethod();
+        assert expected.equals(actual) : "Expected " + expected + ", but got " + actual;
+    }
+
+    // TODO: Enable it once OPENEJB-583 gets fixed
+    //@Test
+    public void testMethodWithDefaultAndClassInterceptorsExcluded() throws Exception {
+        ThirdSLSBeanLocal bean = (ThirdSLSBeanLocal) initCtx.lookup("ThirdSLSBeanLocal");
+
+        assert bean != null;
+
+        List<String> expected = new ArrayList<String>();
+        expected.add("MethodLevelInterceptorOne");
+        expected.add("MethodLevelInterceptorTwo");
+        expected.add("ThirdSLSBean");
+        expected.add("anotherBusinessMethod");
+
+        List<String> actual = bean.anotherBusinessMethod();
+        assert expected.equals(actual) : "Expected " + expected + ", but got " + actual;
+    }
+}

Propchange: openejb/trunk/openejb3/examples/interceptors/src/test/java/org/superbiz/interceptors/ThirdSLSBeanTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: openejb/trunk/openejb3/examples/interceptors/src/test/java/org/superbiz/interceptors/ThirdSLSBeanTest.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: openejb/trunk/openejb3/examples/interceptors/src/test/java/org/superbiz/interceptors/ThirdSLSBeanTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: openejb/trunk/openejb3/examples/interceptors/src/test/java/org/superbiz/interceptors/ThirdSLSBeanTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain