[jboss-cvs] JBossAS SVN: r109554 - in projects/ejb3/trunk/interceptors/src: main/java/org/jboss/ejb3/interceptors/lang and 5 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Nov 30 06:50:50 EST 2010
Author: wolfc
Date: 2010-11-30 06:50:49 -0500 (Tue, 30 Nov 2010)
New Revision: 109554
Added:
projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/interceptors/test/common/CurrentInvocationContextInterceptor.java
Modified:
projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/InvocationContextInterceptor.java
projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/lang/ScopedClassLoader.java
projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/basic/unit/BasicTestSetup.java
projects/ejb3/trunk/interceptors/src/test/resources/basic/jboss-aop.xml
projects/ejb3/trunk/interceptors/src/test/resources/log4j.xml
projects/ejb3/trunk/interceptors/src/test/resources/proxy/jboss-aop.xml
Log:
EJBTHREE-2203: delegate getContextData to ejb3-context
Modified: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/InvocationContextInterceptor.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/InvocationContextInterceptor.java 2010-11-30 10:36:32 UTC (rev 109553)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/InvocationContextInterceptor.java 2010-11-30 11:50:49 UTC (rev 109554)
@@ -2,10 +2,12 @@
import org.jboss.aop.joinpoint.Invocation;
import org.jboss.aop.joinpoint.MethodInvocation;
+import org.jboss.ejb3.context.CurrentInvocationContext;
import org.jboss.ejb3.context.base.BaseInvocationContext;
import java.lang.reflect.Method;
import java.util.Arrays;
+import java.util.Map;
/*
* JBoss, Home of Professional Open Source.
@@ -106,7 +108,13 @@
// Whether we're calling a business method or a lifecycle callback is beyond scope
// here. This must be explicitly set via setBusinessMethodInvocation.
}
-
+
+ @Override
+ public Map<String, Object> getContextData()
+ {
+ return CurrentInvocationContext.get().getContextData();
+ }
+
public Object getTarget()
{
return invocation.getTargetObject();
Modified: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/lang/ScopedClassLoader.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/lang/ScopedClassLoader.java 2010-11-30 10:36:32 UTC (rev 109553)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/lang/ScopedClassLoader.java 2010-11-30 11:50:49 UTC (rev 109554)
@@ -23,20 +23,43 @@
import java.net.URL;
import java.net.URLClassLoader;
+import java.util.HashSet;
+import java.util.Set;
/**
* Only load classes and resources from the given urls.
*
* @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
- * @version $Revision: $
+ * @version $Revision$
*/
public class ScopedClassLoader extends URLClassLoader
{
+ private Set<String> exceptions;
+
public ScopedClassLoader(URL[] urls)
{
+ this(urls, null);
+ }
+
+ public ScopedClassLoader(URL[] urls, String[] exceptions)
+ {
super(urls, null);
+
+ this.exceptions = new HashSet<String>();
+ for(String exception : exceptions)
+ {
+ this.exceptions.add(exception);
+ }
}
-
+
+ @Override
+ public URL findResource(String name)
+ {
+ if(exceptions.contains(name))
+ return null;
+ return super.findResource(name);
+ }
+
protected synchronized Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException
{
// First, check if the class has already been loaded
Added: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/interceptors/test/common/CurrentInvocationContextInterceptor.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/interceptors/test/common/CurrentInvocationContextInterceptor.java (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/interceptors/test/common/CurrentInvocationContextInterceptor.java 2010-11-30 11:50:49 UTC (rev 109554)
@@ -0,0 +1,135 @@
+/*
+ * 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.common;
+
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.aop.joinpoint.MethodInvocation;
+import org.jboss.ejb3.context.CurrentInvocationContext;
+import org.jboss.ejb3.context.base.BaseInvocationContext;
+
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * A temporary hack that mimics how core currently integrates with ejb3-context.
+ *
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ */
+public class CurrentInvocationContextInterceptor implements Interceptor
+{
+ @Override
+ public String getName()
+ {
+ return CurrentInvocationContextInterceptor.class.getName();
+ }
+
+ @Override
+ public Object invoke(Invocation invocation) throws Throwable
+ {
+ CurrentInvocationContext.push(new InvocationContext(invocation));
+ try
+ {
+ return invocation.invokeNext();
+ }
+ finally
+ {
+ CurrentInvocationContext.pop();
+ }
+ }
+
+ private static class InvocationContext extends BaseInvocationContext
+ {
+ private Invocation invocation;
+ private Map<String, Object> contextData = new HashMap<String, Object>();
+ private Method method = null;
+ private Object params[] = null;
+
+ private InvocationContext(Invocation invocation)
+ {
+ super(null, null);
+ this.invocation = invocation;
+ // Whether we're calling a business method or a lifecycle callback is beyond scope
+ // here. This must be explicitly set via setBusinessMethodInvocation.
+ }
+
+ public Map<String, Object> getContextData()
+ {
+ return contextData;
+ }
+
+ public Method getMethod()
+ {
+ return method;
+ }
+
+ public Object[] getParameters()
+ {
+ if(method == null)
+ throw new IllegalStateException("Get parameters is not allowed on lifecycle callbacks (EJB 3 12)");
+ return params;
+ }
+
+ public Object getTarget()
+ {
+ return invocation.getTargetObject();
+ }
+
+ public Object proceed() throws Exception
+ {
+ try
+ {
+ return invocation.invokeNext();
+ }
+ catch(Exception e)
+ {
+ throw e;
+ }
+ catch(Throwable t)
+ {
+ throw new RuntimeException(t);
+ }
+ }
+
+ private void setBusinessMethodInvocation(Method method, Object params[])
+ {
+ this.method = method;
+ this.params = params;
+ }
+
+ public void setParameters(Object[] params)
+ {
+ if(method == null)
+ throw new IllegalStateException("Setting parameters is not allowed on lifecycle callbacks (EJB 3 12)");
+ // TODO: might need more checks
+ this.params = params;
+ ((MethodInvocation) invocation).setArguments(params);
+ }
+
+ public String toString()
+ {
+ return "[target=" + getTarget() + ", method=" + method + ", parameters=" + Arrays.toString(params) + ", contextData=" + contextData + "]";
+ }
+ }
+}
Modified: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/basic/unit/BasicTestSetup.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/basic/unit/BasicTestSetup.java 2010-11-30 10:36:32 UTC (rev 109553)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/basic/unit/BasicTestSetup.java 2010-11-30 11:50:49 UTC (rev 109554)
@@ -21,8 +21,6 @@
*/
package org.jboss.ejb3.test.interceptors.basic.unit;
-import java.net.URL;
-
import org.jboss.aop.AspectManager;
import org.jboss.aop.AspectXmlLoader;
import org.jboss.aop.Domain;
@@ -30,8 +28,11 @@
import org.jboss.aop.classpool.AOPClassLoaderScopingPolicy;
import org.jboss.ejb3.interceptors.aop.DomainClassLoader;
import org.jboss.ejb3.interceptors.lang.ScopedClassLoader;
+import org.jboss.ejb3.interceptors.test.common.CurrentInvocationContextInterceptor;
import org.jboss.logging.Logger;
+import java.net.URL;
+
/**
*
* @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
@@ -59,7 +60,10 @@
String spec = getClass().getClassLoader().getResource(resourceName).toString();
URL deploymentURL = new URL(spec.substring(0, spec.length() - resourceName.length()));
log.info(deploymentURL);
- ScopedClassLoader deploymentClassLoader = new ScopedClassLoader(new URL[] { deploymentURL });
+ String exclusions[] = {
+ resource(CurrentInvocationContextInterceptor.class.getName()),
+ };
+ ScopedClassLoader deploymentClassLoader = new ScopedClassLoader(new URL[] { deploymentURL }, exclusions );
// Bootstrap AOP
URL url = Thread.currentThread().getContextClassLoader().getResource("basic/jboss-aop.xml");
@@ -110,4 +114,9 @@
{
return runner;
}
+
+ private String resource(String className)
+ {
+ return className.replace('.', '/') + ".class";
+ }
}
Modified: projects/ejb3/trunk/interceptors/src/test/resources/basic/jboss-aop.xml
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/resources/basic/jboss-aop.xml 2010-11-30 10:36:32 UTC (rev 109553)
+++ projects/ejb3/trunk/interceptors/src/test/resources/basic/jboss-aop.xml 2010-11-30 11:50:49 UTC (rev 109554)
@@ -3,6 +3,7 @@
<aspect name="InjectInterceptorsFactory" factory="org.jboss.ejb3.interceptors.aop.InjectInterceptorsFactory" scope="PER_JOINPOINT"/>
<aspect name="InterceptorsFactory" factory="org.jboss.ejb3.interceptors.aop.InterceptorsFactory" scope="PER_INSTANCE"/>
<aspect name="InterceptorsInterceptor" class="org.jboss.ejb3.interceptors.aop.InterceptorsInterceptor" scope="PER_INSTANCE"/>
+ <interceptor name="CurrentInvocationContextInterceptor" class="org.jboss.ejb3.interceptors.test.common.CurrentInvocationContextInterceptor" scope="PER_VM"/>
<aspect name="InvocationContextInterceptor" class="org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor" scope="PER_VM"/>
<aspect name="PostConstructInterceptor" class="org.jboss.ejb3.interceptors.aop.PostConstructInterceptor" scope="PER_INSTANCE"/>
@@ -63,6 +64,7 @@
<!-- TODO: we don't need invocation context here -->
<!-- TODO: we do until we've seperated the post constructs -->
<around name="setup" aspect="InvocationContextInterceptor"/>
+ <interceptor-ref name="CurrentInvocationContextInterceptor"/>
<around name="invoke" aspect="InterceptorsFactory"/>
</bind>
@@ -71,6 +73,7 @@
<bind pointcut="construction(@org.jboss.ejb3.interceptors.ManagedObject->new(..))">
<interceptor-ref name="LoggingInterceptor"/>
<around name="setup" aspect="InvocationContextInterceptor"/>
+ <interceptor-ref name="CurrentInvocationContextInterceptor"/>
<around name="postConstruct" aspect="InjectInterceptorsFactory"/>
</bind>
@@ -92,6 +95,7 @@
<bind pointcut="execution(* @org.jboss.ejb3.interceptors.ManagedObject->*(..))">
<around name="setup" aspect="InvocationContextInterceptor"/>
+ <interceptor-ref name="CurrentInvocationContextInterceptor"/>
<around name="fillMethod" aspect="InvocationContextInterceptor"/>
</bind>
@@ -115,6 +119,7 @@
<bind pointcut="execution(* @org.jboss.ejb3.interceptors.ManagedObject->*(..)) AND !beanLifecycleCallbackMethods">
<around name="setup" aspect="InvocationContextInterceptor"/>
+ <interceptor-ref name="CurrentInvocationContextInterceptor"/>
<around name="fillMethod" aspect="InvocationContextInterceptor"/>
<around name="aroundInvoke" aspect="InjectInterceptorsFactory"/>
</bind>
Modified: projects/ejb3/trunk/interceptors/src/test/resources/log4j.xml
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/resources/log4j.xml 2010-11-30 10:36:32 UTC (rev 109553)
+++ projects/ejb3/trunk/interceptors/src/test/resources/log4j.xml 2010-11-30 11:50:49 UTC (rev 109554)
@@ -113,7 +113,7 @@
</category>
<category name="org.jboss.ejb3.interceptors.aop.DomainClassLoader">
- <priority value="INFO"/>
+ <priority value="ALL"/>
</category>
<category name="org.jboss.ejb3.test">
Modified: projects/ejb3/trunk/interceptors/src/test/resources/proxy/jboss-aop.xml
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/resources/proxy/jboss-aop.xml 2010-11-30 10:36:32 UTC (rev 109553)
+++ projects/ejb3/trunk/interceptors/src/test/resources/proxy/jboss-aop.xml 2010-11-30 11:50:49 UTC (rev 109554)
@@ -3,6 +3,7 @@
<aspect name="InjectInterceptorsFactory" factory="org.jboss.ejb3.interceptors.aop.InjectInterceptorsFactory" scope="PER_JOINPOINT"/>
<aspect name="InterceptorsFactory" factory="org.jboss.ejb3.interceptors.aop.InterceptorsFactory" scope="PER_INSTANCE"/>
<aspect name="InterceptorsInterceptor" class="org.jboss.ejb3.interceptors.aop.InterceptorsInterceptor" scope="PER_INSTANCE"/>
+ <interceptor name="CurrentInvocationContextInterceptor" class="org.jboss.ejb3.interceptors.test.common.CurrentInvocationContextInterceptor" scope="PER_VM"/>
<aspect name="InvocationContextInterceptor" class="org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor" scope="PER_VM"/>
<aspect name="PostConstructInterceptor" class="org.jboss.ejb3.interceptors.aop.PostConstructInterceptor" scope="PER_INSTANCE"/>
@@ -33,6 +34,7 @@
<stack name="LifecycleCallbackStack">
<interceptor-ref name="CurrentInvocation"/>
<advice name="setup" aspect="InvocationContextInterceptor"/>
+ <interceptor-ref name="CurrentInvocationContextInterceptor"/>
<interceptor class="org.jboss.ejb3.test.interceptors.common.aop.InvocationCounterInterceptor"/>
</stack>
@@ -75,6 +77,7 @@
<!-- TODO: we don't need invocation context here -->
<!-- TODO: we do until we've seperated the post constructs -->
<around name="setup" aspect="InvocationContextInterceptor"/>
+ <interceptor-ref name="CurrentInvocationContextInterceptor"/>
<around name="invoke" aspect="InterceptorsFactory"/>
</bind>
@@ -83,6 +86,7 @@
<bind pointcut="construction(@org.jboss.ejb3.interceptors.ManagedObject->new(..))">
<interceptor-ref name="LoggingInterceptor"/>
<around name="setup" aspect="InvocationContextInterceptor"/>
+ <interceptor-ref name="CurrentInvocationContextInterceptor"/>
<around name="postConstruct" aspect="InjectInterceptorsFactory"/>
</bind>
@@ -104,6 +108,7 @@
<bind pointcut="execution(* @org.jboss.ejb3.interceptors.ManagedObject->*(..))">
<around name="setup" aspect="InvocationContextInterceptor"/>
+ <interceptor-ref name="CurrentInvocationContextInterceptor"/>
<around name="fillMethod" aspect="InvocationContextInterceptor"/>
</bind>
@@ -127,6 +132,7 @@
<bind pointcut="execution(* @org.jboss.ejb3.interceptors.ManagedObject->*(..)) AND !beanLifecycleCallbackMethods">
<around name="setup" aspect="InvocationContextInterceptor"/>
+ <interceptor-ref name="CurrentInvocationContextInterceptor"/>
<around name="fillMethod" aspect="InvocationContextInterceptor"/>
<around name="aroundInvoke" aspect="InjectInterceptorsFactory"/>
</bind>
More information about the jboss-cvs-commits
mailing list