Skip to content

Commit

Permalink
[WFLY-10146] Simplify invokeInNoTx
Browse files Browse the repository at this point in the history
  • Loading branch information
dmlloyd committed Apr 5, 2018
1 parent 6b6019c commit dbff0ce
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 28 deletions.
4 changes: 3 additions & 1 deletion ejb3/src/main/java/org/jboss/as/ejb3/logging/EjbLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
import org.jboss.logging.annotations.Message;
import org.jboss.logging.annotations.MessageLogger;
import org.jboss.logging.annotations.Param;
import org.jboss.logging.annotations.Signature;
import org.jboss.metadata.ejb.spec.MethodParametersMetaData;
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.ServiceName;
Expand Down Expand Up @@ -2931,7 +2932,8 @@ public interface EjbLogger extends BasicLogger {
DeploymentUnitProcessingException ejbBusinessMethodMustBePublic(final Method method);

@Message(id = 442, value = "Unexpected Error")
EJBException unexpectedError();
@Signature(String.class)
EJBException unexpectedError(@Cause Throwable cause);

@Message(id = 443, value = "EJB 3.1 FR 13.3.3: BMT bean %s should complete transaction before returning.")
String transactionNotComplete(String componentName);
Expand Down
38 changes: 11 additions & 27 deletions ejb3/src/main/java/org/jboss/as/ejb3/tx/CMTTxInterceptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import static org.jboss.as.ejb3.tx.util.StatusHelper.statusAsString;

import java.lang.reflect.UndeclaredThrowableException;
import java.rmi.RemoteException;

import javax.ejb.EJBException;
Expand Down Expand Up @@ -175,31 +176,6 @@ public void handleExceptionInOurTx(InterceptorContext invocation, Throwable t, T
throw (Exception) t;
}

public void handleExceptionInNoTx(InterceptorContext invocation, Throwable t, final EJBComponent component) throws Exception {
ApplicationExceptionDetails ae = component.getApplicationException(t.getClass(), invocation.getMethod());
if (ae != null) {
throw (Exception) t;
}

// if it's neither EJBException nor RemoteException
if (!(t instanceof EJBException || t instanceof RemoteException)) {
// errors and unchecked are wrapped into EJBException
if (t instanceof Error) {
//t = new EJBException(formatException("Unexpected Error", t));
Throwable cause = t;
t = EjbLogger.ROOT_LOGGER.unexpectedError();
t.initCause(cause);
} else if (t instanceof RuntimeException) {
t = new EJBException((Exception) t);
} else {
// an application exception
throw (Exception) t;
}
}

throw (Exception) t;
}

public Object processInvocation(InterceptorContext invocation) throws Exception {
final EJBComponent component = (EJBComponent) invocation.getPrivateData(Component.class);
final ContextTransactionManager tm = ContextTransactionManager.getInstance();
Expand Down Expand Up @@ -242,10 +218,18 @@ protected Object invokeInCallerTx(InterceptorContext invocation, Transaction tx,
protected Object invokeInNoTx(InterceptorContext invocation, final EJBComponent component) throws Exception {
try {
return invocation.proceed();
} catch (Error e) {
throw EjbLogger.ROOT_LOGGER.unexpectedError(e);
} catch (EJBException e) {
throw e;
} catch (RuntimeException e) {
ApplicationExceptionDetails ae = component.getApplicationException(e.getClass(), invocation.getMethod());
throw ae != null ? e : new EJBException(e);
} catch (Exception e) {
throw e;
} catch (Throwable t) {
handleExceptionInNoTx(invocation, t, component);
throw new EJBException(new UndeclaredThrowableException(t));
}
throw new RuntimeException("UNREACHABLE");
}

protected Object invokeInOurTx(InterceptorContext invocation, final EJBComponent component) throws Exception {
Expand Down

0 comments on commit dbff0ce

Please sign in to comment.