[jboss-cvs] JBossAS SVN: r101008 - in projects/ejb3/branches/jboss-ejb3-core-1.1.18_EJBTHREE-1876/src/main: resources and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Feb 16 00:09:05 EST 2010
Author: jbertram at redhat.com
Date: 2010-02-16 00:09:04 -0500 (Tue, 16 Feb 2010)
New Revision: 101008
Added:
projects/ejb3/branches/jboss-ejb3-core-1.1.18_EJBTHREE-1876/src/main/java/org/jboss/ejb3/interceptor/EJB3TCCLInterceptor.java
Modified:
projects/ejb3/branches/jboss-ejb3-core-1.1.18_EJBTHREE-1876/src/main/resources/ejb3-interceptors-aop.xml
Log:
JBPAPP-3748
Copied: projects/ejb3/branches/jboss-ejb3-core-1.1.18_EJBTHREE-1876/src/main/java/org/jboss/ejb3/interceptor/EJB3TCCLInterceptor.java (from rev 94177, projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/interceptor/EJB3TCCLInterceptor.java)
===================================================================
--- projects/ejb3/branches/jboss-ejb3-core-1.1.18_EJBTHREE-1876/src/main/java/org/jboss/ejb3/interceptor/EJB3TCCLInterceptor.java (rev 0)
+++ projects/ejb3/branches/jboss-ejb3-core-1.1.18_EJBTHREE-1876/src/main/java/org/jboss/ejb3/interceptor/EJB3TCCLInterceptor.java 2010-02-16 05:09:04 UTC (rev 101008)
@@ -0,0 +1,95 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, 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.interceptor;
+
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.ejb3.EJBContainer;
+import org.jboss.ejb3.EJBContainerInvocation;
+
+/**
+ * EJB3TCCLInterceptor
+ *
+ * {@link Interceptor} responsible for setting the correct Thread context classloader (TCCL)
+ * during the EJB invocation. The {@link EJBContainer}'s classloader is set as the
+ * TCCL for the duration of this invocation. The TCCL is then reset to the original
+ * classloader.
+ *
+ * Note: The TCCL switch happens from the point when this interceptor is invoked. So
+ * ideally, this interceptor should be the first in the chain of the AOP interceptors
+ * during the EJB invocation
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+// TODO : This interceptor can be moved out of "core", but that isn't too
+// straightforward right now because the container's classloader can
+// only be obtained from EJBContainer and would effectively mean a dependency on
+// ejb3-core. There's a way to avoid this by introducing a new interface which exposes
+// the container's classloader and this interface is then implemented by the EJBContainer.
+// The other component can then rely on this new interface to get hold of the classloader.
+// But overall, that approach isn't straightforward at this point and probably not worth the
+// efforts.
+public class EJB3TCCLInterceptor implements Interceptor
+{
+
+ /**
+ * Returns the name of the interceptor
+ * @see Interceptor#getName()
+ */
+ public String getName()
+ {
+ return this.getClass().getName();
+ }
+
+ /**
+ * Sets the TCCL to the classloader of the container so
+ * that the invocation happens in the context of the
+ * container's classloader. Finally upon return resets
+ * the TCCL to the previous classloader.
+ */
+ public Object invoke(Invocation invocation) throws Throwable
+ {
+ assert invocation instanceof EJBContainerInvocation : "Unexpected invocation type " + invocation.getClass()
+ + " - expected " + EJBContainerInvocation.class;
+
+ // get hold of the EJBContainer from the invocation
+ EJBContainer ejbContainer = EJBContainer.getEJBContainer(invocation.getAdvisor());
+
+ ClassLoader ejbContainerClassloader = ejbContainer.getClassloader();
+ ClassLoader previousClassLoader = Thread.currentThread().getContextClassLoader();
+ // TODO: Review for security manager privileged blocks
+ try
+ {
+ // Set the TCCL to the EJBContainer's classloader
+ Thread.currentThread().setContextClassLoader(ejbContainerClassloader);
+ // move on
+ return invocation.invokeNext();
+ }
+ finally
+ {
+ // reset to original TCCL
+ Thread.currentThread().setContextClassLoader(previousClassLoader);
+ }
+ }
+
+}
Modified: projects/ejb3/branches/jboss-ejb3-core-1.1.18_EJBTHREE-1876/src/main/resources/ejb3-interceptors-aop.xml
===================================================================
--- projects/ejb3/branches/jboss-ejb3-core-1.1.18_EJBTHREE-1876/src/main/resources/ejb3-interceptors-aop.xml 2010-02-16 04:50:21 UTC (rev 101007)
+++ projects/ejb3/branches/jboss-ejb3-core-1.1.18_EJBTHREE-1876/src/main/resources/ejb3-interceptors-aop.xml 2010-02-16 05:09:04 UTC (rev 101008)
@@ -69,7 +69,7 @@
<interceptor class="org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor" scope="PER_VM"/>
<interceptor class="org.jboss.ejb3.BlockContainerShutdownInterceptor" scope="PER_VM"/>
<interceptor factory="org.jboss.ejb3.connectionmanager.CachedConnectionInterceptorFactory" scope="PER_CLASS"/>
-
+ <interceptor class="org.jboss.ejb3.interceptor.EJB3TCCLInterceptor" scope="PER_VM"/>
<!--
INTERCEPTORS
-->
@@ -129,6 +129,7 @@
</stack>
<bind pointcut="execution(public * *->*(..))">
+ <interceptor-ref name="org.jboss.ejb3.interceptor.EJB3TCCLInterceptor"/>
<interceptor-ref name="org.jboss.aspects.currentinvocation.CurrentInvocationInterceptor"/>
<interceptor-ref name="org.jboss.ejb3.BlockContainerShutdownInterceptor"/>
</bind>
More information about the jboss-cvs-commits
mailing list