[jboss-cvs] JBossAS SVN: r94457 - in projects/webbeans-ri-int/trunk: deployer/src/test/java/org/jboss/test/deployers/test and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Oct 7 06:08:38 EDT 2009
Author: marius.bogoevici
Date: 2009-10-07 06:08:37 -0400 (Wed, 07 Oct 2009)
New Revision: 94457
Added:
projects/webbeans-ri-int/trunk/ejb/src/main/java/org/jboss/webbeans/integration/ejb/interceptor/
projects/webbeans-ri-int/trunk/ejb/src/main/java/org/jboss/webbeans/integration/ejb/interceptor/DelegatingInterceptorInvocationContext.java
projects/webbeans-ri-int/trunk/ejb/src/main/java/org/jboss/webbeans/integration/ejb/interceptor/Jsr299BindingsInterceptor.java
Modified:
projects/webbeans-ri-int/trunk/deployer/src/main/java/org/jboss/webbeans/integration/deployer/metadata/WBEjbInterceptorMetadataDeployer.java
projects/webbeans-ri-int/trunk/deployer/src/test/java/org/jboss/test/deployers/test/PostDeployersTestCase.java
projects/webbeans-ri-int/trunk/ejb/src/main/java/org/jboss/webbeans/integration/ejb/JBossEJBDescriptorAdaptor.java
projects/webbeans-ri-int/trunk/ejb/src/main/java/org/jboss/webbeans/integration/ejb/JBossEjbServices.java
projects/webbeans-ri-int/trunk/ejb/src/main/java/org/jboss/webbeans/integration/ejb/SessionBeanInterceptor.java
Log:
Base for supporting the implementation of EjbServices.registerInterceptors() with JBoss integration.
(functionality not complete)
Modified: projects/webbeans-ri-int/trunk/deployer/src/main/java/org/jboss/webbeans/integration/deployer/metadata/WBEjbInterceptorMetadataDeployer.java
===================================================================
--- projects/webbeans-ri-int/trunk/deployer/src/main/java/org/jboss/webbeans/integration/deployer/metadata/WBEjbInterceptorMetadataDeployer.java 2009-10-07 09:59:29 UTC (rev 94456)
+++ projects/webbeans-ri-int/trunk/deployer/src/main/java/org/jboss/webbeans/integration/deployer/metadata/WBEjbInterceptorMetadataDeployer.java 2009-10-07 10:08:37 UTC (rev 94457)
@@ -21,6 +21,8 @@
*/
package org.jboss.webbeans.integration.deployer.metadata;
+import java.util.Iterator;
+
import org.jboss.deployers.spi.DeploymentException;
import org.jboss.deployers.spi.deployer.DeploymentStages;
import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
@@ -44,11 +46,15 @@
@SuppressWarnings("deprecation")
public class WBEjbInterceptorMetadataDeployer extends WebBeansAwareMetadataDeployer<JBossMetaData>
{
- public static final String INTERCEPTOR_CLASS_NAME = "org.jboss.webbeans.integration.ejb.SessionBeanInterceptor";
+ public static final String CONTEXT_INTERCEPTOR_CLASS_NAME = "org.jboss.webbeans.integration.ejb.SessionBeanInterceptor";
+ public static final String BINDINGS_INTERCEPTOR_CLASS_NAME = "org.jboss.webbeans.integration.ejb.interceptor.Jsr299BindingsInterceptor";
private InterceptorMetaData SBI;
- private InterceptorBindingMetaData IBMD;
+ private InterceptorMetaData BIND;
+ private InterceptorBindingMetaData CONTEXT_IBMD;
+ private InterceptorBindingMetaData BINDINGS_IMDB;
+
public WBEjbInterceptorMetadataDeployer()
{
super(JBossMetaData.class, true);
@@ -57,16 +63,28 @@
addInput("merged." + JBossMetaData.class.getName());
setStage(DeploymentStages.POST_CLASSLOADER);
- // create interceptor metadata instance
+ // create interceptor metadata instance for session beans
SBI = new InterceptorMetaData();
- SBI.setInterceptorClass(INTERCEPTOR_CLASS_NAME);
+ SBI.setInterceptorClass(CONTEXT_INTERCEPTOR_CLASS_NAME);
+ // create interceptor metadata instance for JSR-299 specific bindings
+ BIND = new InterceptorMetaData();
+ BIND.setInterceptorClass(BINDINGS_INTERCEPTOR_CLASS_NAME);
+
// create interceptor binding metadata instance
- IBMD = new InterceptorBindingMetaData();
+ CONTEXT_IBMD = createInterceptorBindingMetadata(CONTEXT_INTERCEPTOR_CLASS_NAME);
+ BINDINGS_IMDB = createInterceptorBindingMetadata(BINDINGS_INTERCEPTOR_CLASS_NAME);
+
+ }
+
+ private InterceptorBindingMetaData createInterceptorBindingMetadata(String interceptorClassName)
+ {
+ InterceptorBindingMetaData ibmd = new InterceptorBindingMetaData();
InterceptorClassesMetaData interceptorClasses = new InterceptorClassesMetaData();
- interceptorClasses.add(INTERCEPTOR_CLASS_NAME);
- IBMD.setInterceptorClasses(interceptorClasses);
- IBMD.setEjbName("*");
+ interceptorClasses.add(interceptorClassName);
+ ibmd.setInterceptorClasses(interceptorClasses);
+ ibmd.setEjbName("*");
+ return ibmd;
}
protected void internalDeploy(VFSDeploymentUnit unit, JBossMetaData jbmd, VirtualFile wbXml) throws DeploymentException
@@ -76,6 +94,7 @@
{
InterceptorsMetaData imd = new InterceptorsMetaData();
imd.add(SBI);
+ imd.add(BIND);
EjbJar3xMetaData ejmd = new EjbJar30MetaData();
ejmd.setInterceptors(imd);
@@ -84,6 +103,7 @@
else
{
interceptors.add(SBI); // clone?
+ interceptors.add(BIND);
}
JBossAssemblyDescriptorMetaData assemblyDescriptor = jbmd.getAssemblyDescriptor();
@@ -99,18 +119,30 @@
assemblyDescriptor.setInterceptorBindings(interceptorBindings);
}
// Add this as the first binding in the list so that it is called first...
- interceptorBindings.add(0, IBMD); // clone?
-
+ interceptorBindings.add(0, CONTEXT_IBMD); // clone?
+
+ //Add JSR-299 binding interceptor as the last (all others have to be called first)
+ interceptorBindings.add(BINDINGS_IMDB);
+
// Check to see there is a defined order; if we aren't first, warn
for (InterceptorBindingMetaData interceptorBinding : interceptorBindings)
{
if (interceptorBinding.getInterceptorOrder() != null && ! interceptorBinding.getInterceptorOrder().isEmpty())
{
- if (!INTERCEPTOR_CLASS_NAME.equals(interceptorBinding.getInterceptorOrder().iterator().next()))
+ if (!CONTEXT_INTERCEPTOR_CLASS_NAME.equals(interceptorBinding.getInterceptorOrder().iterator().next()))
{
- log.warn("The Web Beans SessionnBeanInterceptor is not the inner most EJB interceptor in this deployment. JSR299 injection may not work correctly. Specify " + INTERCEPTOR_CLASS_NAME + " as the first interceptor in the interceptor ordering for " + interceptorBinding.getEjbName());
+ log.warn("The Web Beans SessionnBeanInterceptor is not the inner most EJB interceptor in this deployment. JSR299 injection may not work correctly. Specify " + CONTEXT_INTERCEPTOR_CLASS_NAME + " as the first interceptor in the interceptor ordering for " + interceptorBinding.getEjbName());
}
// TODO automagically make ours the first?
+ Object lastInterceptorClassName;
+ Iterator<String> iterator = interceptorBinding.getInterceptorOrder().iterator();
+ do {
+ lastInterceptorClassName = iterator.next();
+ } while (iterator.hasNext());
+ if (!BINDINGS_INTERCEPTOR_CLASS_NAME.equals(lastInterceptorClassName))
+ {
+ log.warn("The Web Beans Jsr299BindingsInterceptor is not the outer most EJB interceptor in this deployment. JSR299 requires that @InterceptorBinding-bound interceptors should execute after @Interceptors-registered interceptors. Specify " + BINDINGS_INTERCEPTOR_CLASS_NAME + " as the last interceptor in the interceptor ordering for " + interceptorBinding.getEjbName());
+ }
}
}
}
Modified: projects/webbeans-ri-int/trunk/deployer/src/test/java/org/jboss/test/deployers/test/PostDeployersTestCase.java
===================================================================
--- projects/webbeans-ri-int/trunk/deployer/src/test/java/org/jboss/test/deployers/test/PostDeployersTestCase.java 2009-10-07 09:59:29 UTC (rev 94456)
+++ projects/webbeans-ri-int/trunk/deployer/src/test/java/org/jboss/test/deployers/test/PostDeployersTestCase.java 2009-10-07 10:08:37 UTC (rev 94457)
@@ -180,7 +180,7 @@
assertNotNull(ejbmd);
InterceptorsMetaData interceptors = ejbmd.getInterceptors();
assertNotNull(interceptors);
- InterceptorMetaData imd = interceptors.get(WBEjbInterceptorMetadataDeployer.INTERCEPTOR_CLASS_NAME);
+ InterceptorMetaData imd = interceptors.get(WBEjbInterceptorMetadataDeployer.CONTEXT_INTERCEPTOR_CLASS_NAME);
assertNotNull(imd);
}
Modified: projects/webbeans-ri-int/trunk/ejb/src/main/java/org/jboss/webbeans/integration/ejb/JBossEJBDescriptorAdaptor.java
===================================================================
--- projects/webbeans-ri-int/trunk/ejb/src/main/java/org/jboss/webbeans/integration/ejb/JBossEJBDescriptorAdaptor.java 2009-10-07 09:59:29 UTC (rev 94456)
+++ projects/webbeans-ri-int/trunk/ejb/src/main/java/org/jboss/webbeans/integration/ejb/JBossEJBDescriptorAdaptor.java 2009-10-07 10:08:37 UTC (rev 94457)
@@ -4,12 +4,14 @@
import org.jboss.ejb3.common.resolvers.spi.EjbReferenceResolver;
import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData;
import org.jboss.webbeans.ejb.spi.EjbDescriptor;
+import org.jboss.webbeans.ejb.spi.InterceptorBindings;
import org.jboss.webbeans.integration.util.Reflections;
public abstract class JBossEJBDescriptorAdaptor<T> implements EjbDescriptor<T>
{
private final Class<T> beanClass;
private final String ejbName;
+ private InterceptorBindings interceptorBindings;
public JBossEJBDescriptorAdaptor(JBossEnterpriseBeanMetaData enterpriseBeanMetaData, DeploymentUnit deploymentUnit, EjbReferenceResolver resolver)
{
@@ -82,5 +84,15 @@
public int hashCode()
{
return getEjbName().hashCode();
- }
+ }
+
+ public void setInterceptorBindings(InterceptorBindings interceptorBindings)
+ {
+ this.interceptorBindings = interceptorBindings;
+ }
+
+ public InterceptorBindings getInterceptorBindings()
+ {
+ return interceptorBindings;
+ }
}
\ No newline at end of file
Modified: projects/webbeans-ri-int/trunk/ejb/src/main/java/org/jboss/webbeans/integration/ejb/JBossEjbServices.java
===================================================================
--- projects/webbeans-ri-int/trunk/ejb/src/main/java/org/jboss/webbeans/integration/ejb/JBossEjbServices.java 2009-10-07 09:59:29 UTC (rev 94456)
+++ projects/webbeans-ri-int/trunk/ejb/src/main/java/org/jboss/webbeans/integration/ejb/JBossEjbServices.java 2009-10-07 10:08:37 UTC (rev 94457)
@@ -5,6 +5,8 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
import javax.ejb.EJB;
import javax.enterprise.inject.spi.InjectionPoint;
@@ -39,7 +41,8 @@
protected EjbReferenceResolver resolver;
private final List<EjbDescriptor<?>> ejbs = new ArrayList<EjbDescriptor<?>>();
private final List<String> ejbContainerNames = new ArrayList<String>();
-
+ private Map<String, InterceptorBindings> interceptorBindings = new ConcurrentHashMap<String, InterceptorBindings>();
+
public JBossEjbServices() throws NamingException
{
super();
@@ -115,8 +118,11 @@
public void registerInterceptors(EjbDescriptor<?> ejbDescriptor, InterceptorBindings interceptorBindings)
{
- // TODO register interceptors for given EJB descriptor
- throw new UnsupportedOperationException("Not implemented");
+ //this.interceptorBindings.put(ejbDescriptor.getEjbName(), interceptorBindings);
+ if (ejbDescriptor instanceof JBossEJBDescriptorAdaptor)
+ {
+ ((JBossEJBDescriptorAdaptor)ejbDescriptor).setInterceptorBindings(interceptorBindings);
+ }
}
public Object resolveRemoteEjb(String jndiName, String mappedName, String ejbLink)
@@ -209,6 +215,11 @@
return Collections.unmodifiableCollection(ejbContainerNames);
}
+ public InterceptorBindings getInterceptorBindings(EjbDescriptor<?> ejbDescriptor)
+ {
+ return interceptorBindings.get(ejbDescriptor.getEjbName());
+ }
+
public void cleanup()
{
ejbContainerNames.clear();
Modified: projects/webbeans-ri-int/trunk/ejb/src/main/java/org/jboss/webbeans/integration/ejb/SessionBeanInterceptor.java
===================================================================
--- projects/webbeans-ri-int/trunk/ejb/src/main/java/org/jboss/webbeans/integration/ejb/SessionBeanInterceptor.java 2009-10-07 09:59:29 UTC (rev 94456)
+++ projects/webbeans-ri-int/trunk/ejb/src/main/java/org/jboss/webbeans/integration/ejb/SessionBeanInterceptor.java 2009-10-07 10:08:37 UTC (rev 94457)
@@ -40,6 +40,7 @@
* Interceptor for handling EJB post-construct tasks
*
* @author Pete Muir
+ * @author Marius Bogoevici
*/
public class SessionBeanInterceptor implements Serializable
{
@@ -75,7 +76,10 @@
private CreationalContext<Object> creationalContext;
private InjectionTarget<Object> injectionTarget;
-
+
+ public static final String CREATIONAL_CONTEXT = "org.jboss.webbeans.integration.ejb.SessionBeanInterceptor.creationalContext";
+ public static final String EJB_DESCRIPTOR = "org.jboss.webbeans.integration.ejb.SessionBeanInterceptor.ejbName";
+
/**
* Gets the underlying target and calls the post-construct method
*
@@ -91,6 +95,8 @@
Bean<Object> bean = beanManager.getBean(descriptor);
creationalContext = beanManager.createCreationalContext(bean);
injectionTarget.inject(invocationContext.getTarget(), creationalContext);
+ invocationContext.getContextData().put(CREATIONAL_CONTEXT, creationalContext);
+ invocationContext.getContextData().put(EJB_DESCRIPTOR, descriptor);
invocationContext.proceed();
}
Added: projects/webbeans-ri-int/trunk/ejb/src/main/java/org/jboss/webbeans/integration/ejb/interceptor/DelegatingInterceptorInvocationContext.java
===================================================================
--- projects/webbeans-ri-int/trunk/ejb/src/main/java/org/jboss/webbeans/integration/ejb/interceptor/DelegatingInterceptorInvocationContext.java (rev 0)
+++ projects/webbeans-ri-int/trunk/ejb/src/main/java/org/jboss/webbeans/integration/ejb/interceptor/DelegatingInterceptorInvocationContext.java 2009-10-07 10:08:37 UTC (rev 94457)
@@ -0,0 +1,84 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual
+ * contributors by the @authors tag. See the copyright.txt in the
+ * distribution for a full listing of individual contributors.
+ *
+ * Licensed 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.jboss.webbeans.integration.ejb.interceptor;
+
+import java.lang.reflect.Method;
+import java.util.Queue;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentLinkedQueue;
+
+import javax.interceptor.InvocationContext;
+import javax.enterprise.inject.spi.Interceptor;
+import javax.enterprise.inject.spi.InterceptionType;
+
+public class DelegatingInterceptorInvocationContext implements InvocationContext
+{
+
+ private InvocationContext delegateInvocationContext;
+
+ private Queue<Interceptor> invocationQueue;
+ private Queue<Object> interceptorInstances;
+
+ private InterceptionType interceptionType;
+
+ public DelegatingInterceptorInvocationContext(InvocationContext delegateInvocationContext, List<Interceptor<?>> interceptors, List<Object> instances, InterceptionType interceptionType)
+ {
+ this.delegateInvocationContext = delegateInvocationContext;
+ this.interceptionType = interceptionType;
+ this.invocationQueue = new ConcurrentLinkedQueue<Interceptor>(interceptors);
+ this.interceptorInstances = new ConcurrentLinkedQueue<Object>(instances);
+ }
+
+ public Map<String, Object> getContextData()
+ {
+ return delegateInvocationContext.getContextData();
+ }
+
+ public Method getMethod()
+ {
+ return delegateInvocationContext.getMethod();
+ }
+
+ public Object[] getParameters()
+ {
+ return delegateInvocationContext.getParameters();
+ }
+
+ public Object getTarget()
+ {
+ return delegateInvocationContext.getTarget();
+ }
+
+ public Object proceed() throws Exception
+ {
+ if (!invocationQueue.isEmpty())
+ {
+ return invocationQueue.remove().intercept(interceptionType, interceptorInstances.remove(), this);
+ }
+ else
+ {
+ return delegateInvocationContext.proceed();
+ }
+ }
+
+ public void setParameters(Object[] params)
+ {
+ delegateInvocationContext.setParameters(params);
+ }
+}
\ No newline at end of file
Added: projects/webbeans-ri-int/trunk/ejb/src/main/java/org/jboss/webbeans/integration/ejb/interceptor/Jsr299BindingsInterceptor.java
===================================================================
--- projects/webbeans-ri-int/trunk/ejb/src/main/java/org/jboss/webbeans/integration/ejb/interceptor/Jsr299BindingsInterceptor.java (rev 0)
+++ projects/webbeans-ri-int/trunk/ejb/src/main/java/org/jboss/webbeans/integration/ejb/interceptor/Jsr299BindingsInterceptor.java 2009-10-07 10:08:37 UTC (rev 94457)
@@ -0,0 +1,130 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual
+ * contributors by the @authors tag. See the copyright.txt in the
+ * distribution for a full listing of individual contributors.
+ *
+ * Licensed 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.jboss.webbeans.integration.ejb.interceptor;
+
+import java.io.Serializable;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.Resource;
+import javax.annotation.PreDestroy;
+import javax.interceptor.InvocationContext;
+import javax.interceptor.AroundInvoke;
+import javax.enterprise.inject.spi.Interceptor;
+import javax.enterprise.inject.spi.InterceptionType;
+import javax.enterprise.context.spi.CreationalContext;
+import javax.ejb.SessionContext;
+
+import org.jboss.webbeans.manager.api.WebBeansManager;
+import org.jboss.webbeans.ejb.spi.InterceptorBindings;
+import org.jboss.webbeans.ejb.spi.EjbDescriptor;
+import org.jboss.webbeans.integration.ejb.SessionBeanInterceptor;
+import org.jboss.webbeans.integration.ejb.JBossEJBDescriptorAdaptor;
+
+/**
+ * Interceptor for applying the JSR-299 specific interceptor bindings.
+ *
+ * It is a separate interceptor, as it needs to be applied after all
+ * the other existing interceptors.
+ *
+ * @author Marius Bogoevici
+ */
+public class Jsr299BindingsInterceptor implements Serializable
+{
+
+ @Resource(mappedName="java:app/BeanManager")
+ private WebBeansManager beanManager;
+
+ @Resource
+ private SessionContext sessionContext;
+
+ private InterceptorBindings interceptorBindings;
+
+ private Map<String, Object> interceptorInstances;
+
+ @PostConstruct
+ public void doPostConstruct(InvocationContext invocationContext) throws Exception
+ {
+ // create contextual instances for interceptors
+ interceptorInstances = new ConcurrentHashMap<String, Object>();
+ EjbDescriptor<?> ejbDescriptor = (EjbDescriptor<?>) invocationContext.getContextData().get(SessionBeanInterceptor.EJB_DESCRIPTOR);
+ //interceptorBindings = ejbServices.getInterceptorBindings(ejbDescriptor);
+ // TODO get the bindings associated with the EjbDescriptor or the EjbServices instance
+
+ if (interceptorBindings != null)
+ {
+ for (Interceptor interceptor : interceptorBindings.getAllInterceptors())
+ {
+ CreationalContext creationalContext = (CreationalContext) invocationContext.getContextData().get(SessionBeanInterceptor.CREATIONAL_CONTEXT);
+ interceptorInstances.put(interceptor.getName(), beanManager.getContext(interceptor.getScope()).get(interceptor, creationalContext));
+ }
+
+ doLifecycleInterception(invocationContext, InterceptionType.POST_CONSTRUCT);
+ }
+ }
+
+ @PreDestroy
+ public void doPreDestroy(InvocationContext invocationContext) throws Exception
+ {
+ doLifecycleInterception(invocationContext, InterceptionType.PRE_DESTROY);
+ }
+
+ @AroundInvoke
+ public void doAroundInvoke(InvocationContext invocationContext) throws Exception
+ {
+ doMethodInterception(invocationContext, InterceptionType.AROUND_INVOKE);
+ }
+
+ private void doLifecycleInterception(InvocationContext invocationContext, InterceptionType interceptionType)
+ throws Exception
+ {
+ if (interceptorBindings != null)
+ {
+ List<Interceptor<?>> currentInterceptors = interceptorBindings.getLifecycleInterceptors(interceptionType);
+ doInterception(invocationContext, interceptionType, currentInterceptors);
+ }
+ }
+
+ private void doMethodInterception(InvocationContext invocationContext, InterceptionType interceptionType)
+ throws Exception
+ {
+ if (interceptorBindings != null)
+ {
+ List<Interceptor<?>> currentInterceptors = interceptorBindings.getMethodInterceptors(interceptionType, invocationContext.getMethod());
+ doInterception(invocationContext, interceptionType, currentInterceptors);
+ }
+ }
+
+ private void doInterception(InvocationContext invocationContext, InterceptionType interceptionType, List<Interceptor<?>> currentInterceptors)
+ throws Exception
+ {
+ List<Object> currentInterceptorInstances = new ArrayList<Object>();
+ for (Interceptor<?> interceptor: currentInterceptors)
+ {
+ currentInterceptorInstances.add(interceptorInstances.get(interceptor.getName()));
+ }
+ new DelegatingInterceptorInvocationContext(invocationContext, currentInterceptors, currentInterceptorInstances, interceptionType).proceed();
+ }
+
+
+
+
+}
More information about the jboss-cvs-commits
mailing list