Skip to content
Permalink
Browse files

AS7-1317: redo tx interceptor integration and check the throws clause

  • Loading branch information...
wolfc authored and bstansberry committed Jul 18, 2011
1 parent 6744b33 commit 2b7aba6c8e5102b4dce763129c47b7714795c570
Showing with 295 additions and 83 deletions.
  1. +16 −16 ee/src/main/java/org/jboss/as/ee/component/interceptors/InterceptorOrder.java
  2. +32 −6 ejb3/src/main/java/org/jboss/as/ejb3/component/EJBComponent.java
  3. +27 −1 ...ain/java/org/jboss/as/ejb3/component/messagedriven/MessageDrivenInvocationContextInterceptor.java
  4. +28 −2 ejb3/src/main/java/org/jboss/as/ejb3/component/session/SessionInvocationContextInterceptor.java
  5. +5 −4 ejb3/src/main/java/org/jboss/as/ejb3/component/singleton/SingletonBMTInterceptor.java
  6. +5 −4 ejb3/src/main/java/org/jboss/as/ejb3/component/stateful/StatefulBMTInterceptor.java
  7. +1 −1 ejb3/src/main/java/org/jboss/as/ejb3/component/stateful/StatefulComponentInstanceInterceptor.java
  8. +4 −3 ejb3/src/main/java/org/jboss/as/ejb3/component/stateful/StatefulRemoveInterceptor.java
  9. +5 −4 ejb3/src/main/java/org/jboss/as/ejb3/component/stateless/StatelessBMTInterceptor.java
  10. +3 −15 ejb3/src/main/java/org/jboss/as/ejb3/tx/CMTTxInterceptor.java
  11. +4 −6 ejb3/src/main/java/org/jboss/as/ejb3/tx/CMTTxInterceptorFactory.java
  12. +11 −14 ejb3/src/main/java/org/jboss/as/ejb3/tx/SingletonLifecycleCMTTxInterceptor.java
  13. +4 −6 ejb3/src/main/java/org/jboss/as/ejb3/tx/SingletonLifecycleCMTTxInterceptorFactory.java
  14. +1 −1 pom.xml
  15. +51 −0 testsuite/spec/src/main/java/org/jboss/as/test/spec/ejb3/exception/Beanie.java
  16. +30 −0 testsuite/spec/src/main/java/org/jboss/as/test/spec/ejb3/exception/BeanieLocal.java
  17. +68 −0 testsuite/spec/src/test/java/org/jboss/as/test/spec/ejb3/exception/AppExceptionTestCase.java
@@ -61,9 +61,9 @@ private Component() {
public static final class ComponentPostConstruct {

public static final int TCCL_INTERCEPTOR = 0x100;
public static final int TRANSACTION_INTERCEPTOR = 0x200;
public static final int JPA_SFSB_PRE_CREATE = 0x300;
public static final int EJB_SESSION_CONTEXT_INTERCEPTOR = 0x400;
public static final int EJB_SESSION_CONTEXT_INTERCEPTOR = 0x200;
public static final int TRANSACTION_INTERCEPTOR = 0x300;
public static final int JPA_SFSB_PRE_CREATE = 0x400;
public static final int JNDI_NAMESPACE_INTERCEPTOR = 0x500;
public static final int INSTANTIATION_INTERCEPTORS = 0x600;
public static final int RESOURCE_INJECTION_INTERCEPTORS = 0x700;
@@ -82,15 +82,15 @@ private ComponentPostConstruct() {
public static final class ComponentPreDestroy {

public static final int TCCL_INTERCEPTOR = 0x100;
public static final int TRANSACTION_INTERCEPTOR = 0x101;
public static final int EJB_SESSION_CONTEXT_INTERCEPTOR = 0x200;
public static final int JNDI_NAMESPACE_INTERCEPTOR = 0x300;
public static final int JPA_SFSB_DESTROY = 0x400;
public static final int UNINJECTION_INTERCEPTORS = 0x500;
public static final int DESTRUCTION_INTERCEPTORS = 0x600;
public static final int USER_INTERCEPTORS = 0x700;
public static final int CDI_INTERCEPTORS = 0x800;
public static final int TERMINAL_INTERCEPTOR = 0x900;
public static final int TRANSACTION_INTERCEPTOR = 0x300;
public static final int JNDI_NAMESPACE_INTERCEPTOR = 0x400;
public static final int JPA_SFSB_DESTROY = 0x500;
public static final int UNINJECTION_INTERCEPTORS = 0x600;
public static final int DESTRUCTION_INTERCEPTORS = 0x700;
public static final int USER_INTERCEPTORS = 0x800;
public static final int CDI_INTERCEPTORS = 0x900;
public static final int TERMINAL_INTERCEPTOR = 0xA00;

private ComponentPreDestroy() {
}
@@ -103,11 +103,11 @@ private ComponentPreDestroy() {
public static final int SESSION_BEAN_EQUALS_HASHCODE = 0x100;
public static final int SECURITY_CONTEXT = 0x150;
public static final int EJB_SECURITY_AUTHORIZATION_INTERCEPTOR = 0x200;
public static final int CMT_TRANSACTION_INTERCEPTOR = 0x300;
public static final int ASSOCIATING_INTERCEPTOR = 0x400;
public static final int JPA_SFSB_INTERCEPTOR = 0x500;
public static final int SFSB_REMOVE_INTERCEPTOR = 0x600;
public static final int INVOCATION_CONTEXT_INTERCEPTOR = 0x700;
public static final int INVOCATION_CONTEXT_INTERCEPTOR = 0x300;
public static final int CMT_TRANSACTION_INTERCEPTOR = 0x400;
public static final int ASSOCIATING_INTERCEPTOR = 0x500;
public static final int JPA_SFSB_INTERCEPTOR = 0x600;
public static final int SFSB_REMOVE_INTERCEPTOR = 0x700;
public static final int COMPONENT_DISPATCHER = 0x800;


@@ -28,7 +28,6 @@
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.ejb3.context.CurrentInvocationContext;
import org.jboss.ejb3.context.spi.InvocationContext;
import org.jboss.ejb3.tx2.spi.TransactionalComponent;
import org.jboss.logging.Logger;
import org.jboss.msc.service.ServiceController;

@@ -51,6 +50,7 @@
import javax.transaction.TransactionSynchronizationRegistry;
import javax.transaction.UserTransaction;
import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.security.Principal;
import java.util.Collection;
@@ -62,9 +62,26 @@
/**
* @author <a href="mailto:cdewolf@redhat.com">Carlo de Wolf</a>
*/
public abstract class EJBComponent extends BasicComponent implements org.jboss.ejb3.context.spi.EJBComponent, TransactionalComponent {
public abstract class EJBComponent extends BasicComponent implements org.jboss.ejb3.context.spi.EJBComponent {
private static Logger log = Logger.getLogger(EJBComponent.class);

private static final ApplicationException APPLICATION_EXCEPTION = new ApplicationException() {
@Override
public boolean inherited() {
return true;
}

@Override
public boolean rollback() {
return false;
}

@Override
public Class<? extends Annotation> annotationType() {
return ApplicationException.class;
}
};

private final ConcurrentMap<MethodIntf, ConcurrentMap<String, ConcurrentMap<ArrayKey, TransactionAttributeType>>> txAttrs;

private final EJBUtilities utilities;
@@ -97,8 +114,7 @@ protected EJBComponent(final EJBComponentCreateService ejbComponentCreateService
this.securityMetaData = ejbComponentCreateService.getSecurityMetaData();
}

@Override
public ApplicationException getApplicationException(Class<?> exceptionClass) {
public ApplicationException getApplicationException(Class<?> exceptionClass, Method invokedMethod) {
ApplicationException applicationException = this.applicationExceptions.get(exceptionClass);
if (applicationException != null) {
return applicationException;
@@ -122,6 +138,18 @@ public ApplicationException getApplicationException(Class<?> exceptionClass) {
// move to next super class
superClass = superClass.getSuperclass();
}
// AS7-1317: examine the throws clause of the method
// An unchecked-exception is only an application exception if annotated (or described) as such.
// (see EJB 3.1 FR 14.2.1)
if (RuntimeException.class.isAssignableFrom(exceptionClass) || Error.class.isAssignableFrom(exceptionClass))
return null;
if (invokedMethod != null) {
final Class<?>[] exceptionTypes = invokedMethod.getExceptionTypes();
for (Class<?> type : exceptionTypes) {
if (type.isAssignableFrom(exceptionClass))
return APPLICATION_EXCEPTION;
}
}
// not an application exception, so return null.
return null;
}
@@ -222,7 +250,6 @@ public TransactionAttributeType getTransactionAttributeType(MethodIntf methodInt
return txAttr;
}

@Override
public TransactionManager getTransactionManager() {
return utilities.getTransactionManager();
}
@@ -231,7 +258,6 @@ public TransactionSynchronizationRegistry getTransactionSynchronizationRegistry(
return utilities.getTransactionSynchronizationRegistry();
}

@Override
public int getTransactionTimeout(Method method) {
return -1; // un-configured
}
@@ -21,16 +21,20 @@
*/
package org.jboss.as.ejb3.component.messagedriven;

import org.jboss.as.ee.component.Component;
import org.jboss.as.ee.component.ComponentInstance;
import org.jboss.ejb3.context.CurrentInvocationContext;
import org.jboss.ejb3.context.base.BaseInvocationContext;
import org.jboss.ejb3.context.spi.InvocationContext;
import org.jboss.ejb3.context.spi.MessageDrivenContext;
import org.jboss.ejb3.tx2.spi.TransactionalInvocationContext;
import org.jboss.invocation.ImmediateInterceptorFactory;
import org.jboss.invocation.Interceptor;
import org.jboss.invocation.InterceptorContext;
import org.jboss.invocation.InterceptorFactory;

import javax.ejb.ApplicationException;
import javax.ejb.TransactionAttributeType;
import java.lang.reflect.Method;
import java.util.Map;

@@ -60,7 +64,7 @@ public Object processInvocation(InterceptorContext context) throws Exception {
}
}

protected static class CustomInvocationContext extends BaseInvocationContext {
protected static class CustomInvocationContext extends BaseInvocationContext implements TransactionalInvocationContext {
private InterceptorContext context;

protected CustomInvocationContext(InterceptorContext context, Method method, Object[] parameters) {
@@ -69,16 +73,38 @@ protected CustomInvocationContext(InterceptorContext context, Method method, Obj
this.context = context;
}

@Override
public ApplicationException getApplicationException(Class<?> e) {
return getComponent().getApplicationException(e, getMethod());
}

@Override
public Map<String, Object> getContextData() {
return context.getContextData();
}

@Override
public MessageDrivenComponent getComponent() {
//return (MessageDrivenComponent) super.getComponent();
// this is faster
return (MessageDrivenComponent) context.getPrivateData(Component.class);
}

@Override
public MessageDrivenContext getEJBContext() {
return ((MessageDrivenComponentInstance) context.getPrivateData(ComponentInstance.class)).getMessageDrivenContext();
}

@Override
public TransactionAttributeType getTransactionAttribute() {
return getComponent().getTransactionAttributeType(getMethod());
}

@Override
public int getTransactionTimeout() {
return getComponent().getTransactionTimeout(getMethod());
}

@Override
public Object proceed() throws Exception {
return context.proceed();
@@ -21,6 +21,7 @@
*/
package org.jboss.as.ejb3.component.session;

import org.jboss.as.ee.component.Component;
import org.jboss.as.ee.component.ComponentInstance;
import org.jboss.as.ee.component.ComponentViewInstance;
import org.jboss.as.ejb3.component.CancellationFlag;
@@ -29,11 +30,14 @@
import org.jboss.ejb3.context.spi.InvocationContext;
import org.jboss.ejb3.context.spi.SessionContext;
import org.jboss.ejb3.context.spi.SessionInvocationContext;
import org.jboss.ejb3.tx2.spi.TransactionalInvocationContext;
import org.jboss.invocation.ImmediateInterceptorFactory;
import org.jboss.invocation.Interceptor;
import org.jboss.invocation.InterceptorContext;
import org.jboss.invocation.InterceptorFactory;

import javax.ejb.ApplicationException;
import javax.ejb.TransactionAttributeType;
import java.lang.reflect.Method;
import java.security.Principal;
import java.util.Map;
@@ -71,7 +75,7 @@ public Object processInvocation(InterceptorContext context) throws Exception {
}
}

protected static class CustomSessionInvocationContext extends BaseSessionInvocationContext {
protected static class CustomSessionInvocationContext extends BaseSessionInvocationContext implements TransactionalInvocationContext {
private InterceptorContext context;

protected CustomSessionInvocationContext(boolean lifecycleCallback, InterceptorContext context, Class<?> invokedBusinessInterface, Method method, Object[] parameters) {
@@ -80,9 +84,21 @@ protected CustomSessionInvocationContext(boolean lifecycleCallback, InterceptorC
this.context = context;
}

@Override
public ApplicationException getApplicationException(Class<?> e) {
return getComponent().getApplicationException(e, getMethod());
}

@Override
public Principal getCallerPrincipal() {
return ((SessionBeanComponent) getComponent()).getCallerPrincipal();
return getComponent().getCallerPrincipal();
}

@Override
public SessionBeanComponent getComponent() {
//return (SessionBeanComponent) super.getComponent();
// this is faster
return (SessionBeanComponent) context.getPrivateData(Component.class);
}

@Override
@@ -95,6 +111,16 @@ public SessionContext getEJBContext() {
return ((SessionBeanComponentInstance) context.getPrivateData(ComponentInstance.class)).getSessionContext();
}

@Override
public TransactionAttributeType getTransactionAttribute() {
return getComponent().getTransactionAttributeType(getMethod());
}

@Override
public int getTransactionTimeout() {
return getComponent().getTransactionTimeout(getMethod());
}

@Override
public Object proceed() throws Exception {
return context.proceed();
@@ -22,8 +22,9 @@

package org.jboss.as.ejb3.component.singleton;

import org.jboss.ejb3.context.spi.InvocationContext;
import org.jboss.ejb3.tx2.impl.StatelessBMTInterceptor;
import org.jboss.ejb3.tx2.spi.TransactionalComponent;
import org.jboss.ejb3.tx2.spi.TransactionalInvocationContext;
import org.jboss.invocation.Interceptor;
import org.jboss.invocation.InterceptorContext;

@@ -50,8 +51,8 @@ public SingletonBMTInterceptor(SingletonComponent component) {
}

@Override
protected TransactionalComponent getTransactionalComponent() {
return this.singletonComponent;
protected String getComponentName() {
return singletonComponent.getComponentName();
}

@Override
@@ -61,6 +62,6 @@ protected TransactionManager getTransactionManager() {

@Override
public Object processInvocation(InterceptorContext context) throws Exception {
return super.invoke(context.getInvocationContext());
return super.invoke((TransactionalInvocationContext) context.getPrivateData(InvocationContext.class));
}
}
@@ -21,7 +21,8 @@
*/
package org.jboss.as.ejb3.component.stateful;

import org.jboss.ejb3.tx2.spi.TransactionalComponent;
import org.jboss.ejb3.context.spi.InvocationContext;
import org.jboss.ejb3.tx2.spi.TransactionalInvocationContext;
import org.jboss.invocation.Interceptor;
import org.jboss.invocation.InterceptorContext;

@@ -38,8 +39,8 @@
}

@Override
protected TransactionalComponent getTransactionalComponent() {
return this.component;
protected String getComponentName() {
return component.getComponentName();
}

@Override
@@ -49,6 +50,6 @@ protected TransactionManager getTransactionManager() {

@Override
public Object processInvocation(InterceptorContext context) throws Exception {
return super.invoke(context.getInvocationContext());
return super.invoke((TransactionalInvocationContext) context.getPrivateData(InvocationContext.class));
}
}
@@ -61,7 +61,7 @@ public Object processInvocation(InterceptorContext context) throws Exception {
return context.proceed();
} catch (Exception ex) {
// Detect app exception
if (component.getApplicationException(ex.getClass()) != null) {
if (component.getApplicationException(ex.getClass(), context.getMethod()) != null) {
// it's an application exception, just throw it back.
throw ex;
}
@@ -29,6 +29,7 @@
import org.jboss.invocation.InterceptorContext;

import java.io.Serializable;
import java.lang.reflect.Method;

/**
* An interceptor which handles a invocation on a {@link javax.ejb.Remove} method of a stateful session bean. This interceptor
@@ -64,7 +65,7 @@ public Object processInvocation(InterceptorContext context) throws Exception {

// If it's an application exception and if the @Remove method has set "retainIfException" to true
// then just throw back the exception and don't remove the session instance.
if (this.isApplicationException(statefulComponent, e.getClass()) && this.retainIfException) {
if (this.isApplicationException(statefulComponent, e.getClass(), context.getMethod()) && this.retainIfException) {
throw e;
}
// otherwise, just remove it and throw back the original exception
@@ -88,8 +89,8 @@ public Object processInvocation(InterceptorContext context) throws Exception {
* @param exceptionClass The exception class
* @return
*/
private boolean isApplicationException(final EJBComponent ejbComponent, final Class<?> exceptionClass) {
return ejbComponent.getApplicationException(exceptionClass) != null;
private boolean isApplicationException(final EJBComponent ejbComponent, final Class<?> exceptionClass, final Method invokedMethod) {
return ejbComponent.getApplicationException(exceptionClass, invokedMethod) != null;
}


0 comments on commit 2b7aba6

Please sign in to comment.
You can’t perform that action at this time.