Permalink
Browse files

AS7-5897 Introduced a feature to allow user application specific "con…

…tainer-interceptors" which gets applied before certain JBoss specific server side interceptors get applied
  • Loading branch information...
1 parent 45477e7 commit 3ad941690b6c7f3c256309ea0edd3eeea68d7af2 @jaikiran jaikiran committed with kabir Dec 13, 2012
Showing with 1,657 additions and 0 deletions.
  1. +3 −0 ee/src/main/java/org/jboss/as/ee/component/interceptors/InterceptorOrder.java
  2. +101 −0 ejb3/src/main/java/org/jboss/as/ejb3/component/ContainerInterceptorMethodInterceptorFactory.java
  3. +104 −0 ejb3/src/main/java/org/jboss/as/ejb3/component/EJBComponentDescription.java
  4. +321 −0 ejb3/src/main/java/org/jboss/as/ejb3/component/EJBContainerInterceptorsViewConfigurator.java
  5. +2 −0 ejb3/src/main/java/org/jboss/as/ejb3/component/EJBViewDescription.java
  6. +2 −0 ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/EjbJarParsingDeploymentUnitProcessor.java
  7. +319 −0 ...main/java/org/jboss/as/ejb3/deployment/processors/dd/ContainerInterceptorBindingsDDProcessor.java
  8. +45 −0 ejb3/src/main/java/org/jboss/as/ejb3/interceptor/ContainerInterceptorsMetaData.java
  9. +85 −0 ejb3/src/main/java/org/jboss/as/ejb3/interceptor/ContainerInterceptorsParser.java
  10. +3 −0 ejb3/src/main/java/org/jboss/as/ejb3/subsystem/EJB3SubsystemAdd.java
  11. +41 −0 ejb3/src/main/resources/jboss-ejb-container-interceptors_1_0.xsd
  12. +1 −0 server/src/main/java/org/jboss/as/server/deployment/Phase.java
  13. +44 −0 ...rc/test/java/org/jboss/as/test/integration/ejb/container/interceptor/AnotherFlowTrackingBean.java
  14. +37 −0 .../java/org/jboss/as/test/integration/ejb/container/interceptor/ClassLevelContainerInterceptor.java
  15. +46 −0 ...rc/test/java/org/jboss/as/test/integration/ejb/container/interceptor/ContainerInterceptorOne.java
  16. +205 −0 ...t/java/org/jboss/as/test/integration/ejb/container/interceptor/ContainerInterceptorsTestCase.java
  17. +31 −0 ...tion/basic/src/test/java/org/jboss/as/test/integration/ejb/container/interceptor/FlowTracker.java
  18. +64 −0 ...basic/src/test/java/org/jboss/as/test/integration/ejb/container/interceptor/FlowTrackingBean.java
  19. +37 −0 ...a/org/jboss/as/test/integration/ejb/container/interceptor/MethodSpecificContainerInterceptor.java
  20. +46 −0 ...rc/test/java/org/jboss/as/test/integration/ejb/container/interceptor/NonContainerInterceptor.java
  21. +57 −0 ...test/java/org/jboss/as/test/integration/ejb/container/interceptor/SimpleEJBClientInterceptor.java
  22. +62 −0 ...ration/basic/src/test/java/org/jboss/as/test/integration/ejb/container/interceptor/jboss-ejb3.xml
  23. +1 −0 ...gration/smoke/src/test/java/org/jboss/as/test/smoke/subsystem/xml/AbstractValidationUnitTest.java
@@ -135,6 +135,9 @@ private ComponentPassivation() {
public static final int EJB_EXCEPTION_LOGGING_INTERCEPTOR = 0x210;
public static final int SHUTDOWN_INTERCEPTOR = 0x220;
public static final int INVALID_METHOD_EXCEPTION = 0x230;
+ // Allows users to specify user application specific "container interceptors" which run before the
+ // other JBoss specific container interceptors like the security interceptor
+ public static final int USER_APP_SPECIFIC_CONTAINER_INTERCEPTORS = 0x249;
public static final int SECURITY_CONTEXT = 0x250;
public static final int EJB_SECURITY_AUTHORIZATION_INTERCEPTOR = 0x300;
// after security we take note of the invocation
@@ -0,0 +1,101 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2012, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.as.ejb3.component;
+
+import org.jboss.as.naming.ManagedReference;
+import org.jboss.invocation.Interceptor;
+import org.jboss.invocation.InterceptorContext;
+import org.jboss.invocation.InterceptorFactory;
+import org.jboss.invocation.InterceptorFactoryContext;
+import org.jboss.invocation.Interceptors;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+/**
+ * An {@link InterceptorFactory} responsible for creating {@link Interceptor} instance corresponding to a <code>container-interceptor</code>
+ * applicable for a EJB
+ *
+ * @author Jaikiran Pai
+ */
+final class ContainerInterceptorMethodInterceptorFactory implements InterceptorFactory {
+ private final ManagedReference interceptorInstanceRef;
+ private final Method method;
+
+ /**
+ * @param interceptorInstanceRef The managed reference to the container-interceptor instance
+ * @param method The method for which the interceptor has to be created
+ */
+ ContainerInterceptorMethodInterceptorFactory(final ManagedReference interceptorInstanceRef, final Method method) {
+ this.interceptorInstanceRef = interceptorInstanceRef;
+ this.method = method;
+ }
+
+ /**
+ * Creates and returns a {@link Interceptor} which invokes the underlying container-interceptor during a method invocation
+ *
+ * @param context The interceptor factory context
+ * @return
+ */
+ public Interceptor create(final InterceptorFactoryContext context) {
+ return new ContainerInterceptorMethodInterceptor(this.interceptorInstanceRef, method);
+ }
+
+
+ /**
+ * {@link Interceptor} responsible for invoking the underlying container-interceptor in its {@link #processInvocation(org.jboss.invocation.InterceptorContext)}
+ * method
+ */
+ private static final class ContainerInterceptorMethodInterceptor implements Interceptor {
+
+ private final ManagedReference interceptorInstanceRef;
+ private final Method method;
+
+ /**
+ * @param interceptorInstanceRef The managed reference to the container-interceptor instance
+ * @param method The method on which the interceptor applies
+ */
+ ContainerInterceptorMethodInterceptor(final ManagedReference interceptorInstanceRef, final Method method) {
+ this.method = method;
+ this.interceptorInstanceRef = interceptorInstanceRef;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object processInvocation(final InterceptorContext context) throws Exception {
+ // get the container-interceptor instance
+ final Object interceptorInstance = interceptorInstanceRef.getInstance();
+ try {
+ final Method method = this.method;
+ return method.invoke(interceptorInstance, context.getInvocationContext());
+ } catch (IllegalAccessException e) {
+ final IllegalAccessError n = new IllegalAccessError(e.getMessage());
+ n.setStackTrace(e.getStackTrace());
+ throw n;
+ } catch (InvocationTargetException e) {
+ throw Interceptors.rethrow(e.getCause());
+ }
+ }
+ }
+}
@@ -32,6 +32,7 @@
import org.jboss.as.ee.component.ComponentStartService;
import org.jboss.as.ee.component.ComponentView;
import org.jboss.as.ee.component.DependencyConfigurator;
+import org.jboss.as.ee.component.InterceptorDescription;
import org.jboss.as.ee.component.NamespaceConfigurator;
import org.jboss.as.ee.component.NamespaceViewConfigurator;
import org.jboss.as.ee.component.TCCLInterceptor;
@@ -69,6 +70,7 @@
import org.jboss.invocation.ImmediateInterceptorFactory;
import org.jboss.invocation.Interceptor;
import org.jboss.invocation.InterceptorContext;
+import org.jboss.invocation.proxy.MethodIdentifier;
import org.jboss.metadata.ejb.spec.EnterpriseBeanMetaData;
import org.jboss.metadata.javaee.spec.SecurityRolesMetaData;
import org.jboss.msc.service.Service;
@@ -204,6 +206,41 @@
private final ShutDownInterceptorFactory shutDownInterceptorFactory = new ShutDownInterceptorFactory();
/**
+ * The default container interceptors
+ */
+ private List<InterceptorDescription> defaultContainerInterceptors = new ArrayList<InterceptorDescription>();
+
+ /**
+ * Whether or not to exclude the default container interceptors for the EJB
+ */
+ private boolean excludeDefaultContainerInterceptors;
+
+ /**
+ * Container interceptors applicable for all methods of the EJB
+ */
+ private List<InterceptorDescription> classLevelContainerInterceptors = new ArrayList<InterceptorDescription>();
+
+ /**
+ * Container interceptors applicable per method of the EJB
+ */
+ private Map<MethodIdentifier, List<InterceptorDescription>> methodLevelContainerInterceptors = new HashMap<MethodIdentifier, List<InterceptorDescription>>();
+
+ /**
+ * Whether or not to exclude the default container interceptors applicable for the method of the EJB
+ */
+ private Map<MethodIdentifier, Boolean> excludeDefaultContainerInterceptorsForMethod = new HashMap<MethodIdentifier, Boolean>();
+
+ /**
+ * Whether or not to exclude the class level container interceptors applicable for the method of the EJB
+ */
+ private Map<MethodIdentifier, Boolean> excludeClassLevelContainerInterceptorsForMethod = new HashMap<MethodIdentifier, Boolean>();
+
+ /**
+ * Combination of class and method level container interceptors
+ */
+ private Set<InterceptorDescription> allContainerInterceptors;
+
+ /**
* Construct a new instance.
*
* @param componentName the component name
@@ -806,6 +843,73 @@ public ShutDownInterceptorFactory getShutDownInterceptorFactory() {
return shutDownInterceptorFactory;
}
+ public void setDefaultContainerInterceptors(final List<InterceptorDescription> defaultInterceptors) {
+ this.defaultContainerInterceptors = defaultInterceptors;
+ }
+
+ public List<InterceptorDescription> getDefaultContainerInterceptors() {
+ return this.defaultContainerInterceptors;
+ }
+
+ public void setClassLevelContainerInterceptors(final List<InterceptorDescription> containerInterceptors) {
+ this.classLevelContainerInterceptors = containerInterceptors;
+ }
+
+ public List<InterceptorDescription> getClassLevelContainerInterceptors() {
+ return this.classLevelContainerInterceptors;
+ }
+
+ public void setExcludeDefaultContainerInterceptors(boolean excludeDefaultContainerInterceptors) {
+ this.excludeDefaultContainerInterceptors = excludeDefaultContainerInterceptors;
+ }
+
+ public boolean isExcludeDefaultContainerInterceptors() {
+ return this.excludeDefaultContainerInterceptors;
+ }
+
+ public void excludeDefaultContainerInterceptors(final MethodIdentifier methodIdentifier) {
+ this.excludeDefaultContainerInterceptorsForMethod.put(methodIdentifier, true);
+ }
+
+ public boolean isExcludeDefaultContainerInterceptors(final MethodIdentifier methodIdentifier) {
+ return this.excludeDefaultContainerInterceptorsForMethod.get(methodIdentifier) != null;
+ }
+
+ public void excludeClassLevelContainerInterceptors(final MethodIdentifier methodIdentifier) {
+ this.excludeClassLevelContainerInterceptorsForMethod.put(methodIdentifier, true);
+ }
+
+ public boolean isExcludeClassLevelContainerInterceptors(final MethodIdentifier methodIdentifier) {
+ return this.excludeClassLevelContainerInterceptorsForMethod.get(methodIdentifier) != null;
+ }
+
+ public Map<MethodIdentifier, List<InterceptorDescription>> getMethodLevelContainerInterceptors() {
+ return this.methodLevelContainerInterceptors;
+ }
+
+ public void setMethodContainerInterceptors(final MethodIdentifier methodIdentifier, final List<InterceptorDescription> containerInterceptors) {
+ this.methodLevelContainerInterceptors.put(methodIdentifier, containerInterceptors);
+ }
+
+
+ /**
+ * Returns a combined map of class and method level container interceptors
+ *
+ */
+ public Set<InterceptorDescription> getAllContainerInterceptors() {
+ if (this.allContainerInterceptors == null) {
+ this.allContainerInterceptors = new HashSet<InterceptorDescription>();
+ this.allContainerInterceptors.addAll(this.classLevelContainerInterceptors);
+ if (!this.excludeDefaultContainerInterceptors) {
+ this.allContainerInterceptors.addAll(this.defaultContainerInterceptors);
+ }
+ for (List<InterceptorDescription> interceptors : this.methodLevelContainerInterceptors.values()) {
+ this.allContainerInterceptors.addAll(interceptors);
+ }
+ }
+ return this.allContainerInterceptors;
+ }
+
@Override
public String toString() {
return getClass().getName() + "{" +
Oops, something went wrong.

0 comments on commit 3ad9416

Please sign in to comment.