use of javax.interceptor.AroundInvoke in project wildfly by wildfly.
the class MyBaseInterceptor method baseInvoke.
@AroundInvoke
public Object baseInvoke(InvocationContext ctx) throws Exception {
baseSession2.doit();
if (baseTm == null) {
throw new RuntimeException("tm was null");
}
if (baseDs == null) {
throw new RuntimeException("ds was null");
}
if (baseEm == null) {
throw new RuntimeException("em was null");
}
if (baseSession == null) {
throw new RuntimeException("session was null");
}
if (baseFactory == null) {
throw new RuntimeException("factory was null");
}
if (baseSessionFactory == null) {
throw new RuntimeException("sessionFactory was null");
}
baseSession2Method.doit();
if (baseTmMethod == null) {
throw new RuntimeException("tm was null");
}
if (baseDsMethod == null) {
throw new RuntimeException("ds was null");
}
if (baseEmMethod == null) {
throw new RuntimeException("em was null");
}
if (baseSessionMethod == null) {
throw new RuntimeException("session was null");
}
if (baseFactoryMethod == null) {
throw new RuntimeException("factory was null");
}
if (baseSessionFactoryMethod == null) {
throw new RuntimeException("sessionFactory was null");
}
ArrayList list = (ArrayList) ctx.proceed();
list.add(0, "MyBaseInterceptor");
return list;
}
use of javax.interceptor.AroundInvoke in project tomee by apache.
the class InterceptorMdbBean method aroundInvoke.
@AroundInvoke
public Object aroundInvoke(final InvocationContext ctx) throws Exception {
final Object[] objArr = ctx.getParameters();
final Message msg = (Message) objArr[0];
msg.setBooleanProperty("MethodLevelBusinessMethodInterception", true);
ctx.setParameters(objArr);
return ctx.proceed();
}
use of javax.interceptor.AroundInvoke in project tomee by apache.
the class MdbInterceptor method mdbInterceptor.
@AroundInvoke
public Object mdbInterceptor(final InvocationContext ctx) throws Exception {
final Object[] objArr = ctx.getParameters();
final Message msg = (Message) objArr[0];
msg.clearProperties();
msg.setBooleanProperty("ClassLevelBusinessMethodInterception", true);
ctx.setParameters(objArr);
return ctx.proceed();
}
use of javax.interceptor.AroundInvoke in project wildfly by wildfly.
the class ServerSecurityInterceptor method aroundInvoke.
@AroundInvoke
public Object aroundInvoke(final InvocationContext invocationContext) throws Exception {
Principal desiredUser = null;
RealmUser connectionUser = null;
Map<String, Object> contextData = invocationContext.getContextData();
if (contextData.containsKey(DELEGATED_USER_KEY)) {
desiredUser = new SimplePrincipal((String) contextData.get(DELEGATED_USER_KEY));
Connection con = RemotingContext.getConnection();
if (con != null) {
SecurityIdentity localIdentity = con.getLocalIdentity();
if (localIdentity != null) {
connectionUser = new RealmUser(localIdentity.getPrincipal().getName());
}
} else {
throw new IllegalStateException("Delegation user requested but no user on connection found.");
}
}
SecurityContext cachedSecurityContext = null;
boolean contextSet = false;
try {
if (desiredUser != null && connectionUser != null && (desiredUser.getName().equals(connectionUser.getName()) == false)) {
try {
// The final part of this check is to verify that the change does actually indicate a change in user.
// We have been requested to switch user and have successfully identified the user from the connection
// so now we attempt the switch.
cachedSecurityContext = SecurityContextAssociation.getSecurityContext();
final SecurityContext nextContext = SecurityContextFactory.createSecurityContext(desiredUser, new CurrentUserCredential(connectionUser.getName()), new Subject(), "fooSecurityDomain");
SecurityContextAssociation.setSecurityContext(nextContext);
// keep track that we switched the security context
contextSet = true;
RemotingContext.clear();
} catch (Exception e) {
LOGGER.error("Failed to switch security context for user", e);
// Don't propagate the exception stacktrace back to the client for security reasons
throw new EJBAccessException("Unable to attempt switching of user.");
}
}
return invocationContext.proceed();
} finally {
// switch back to original security context
if (contextSet) {
SecurityContextAssociation.setSecurityContext(cachedSecurityContext);
}
}
}
use of javax.interceptor.AroundInvoke in project Payara by payara.
the class BulkheadInterceptor method intercept.
@AroundInvoke
public Object intercept(InvocationContext invocationContext) throws Exception {
Object proceededInvocationContext = null;
FaultToleranceService faultToleranceService = Globals.getDefaultBaseServiceLocator().getService(FaultToleranceService.class);
InvocationManager invocationManager = Globals.getDefaultBaseServiceLocator().getService(InvocationManager.class);
Config config = null;
try {
config = ConfigProvider.getConfig();
} catch (IllegalArgumentException ex) {
logger.log(Level.INFO, "No config could be found", ex);
}
try {
String appName = faultToleranceService.getApplicationName(invocationManager, invocationContext);
// Attempt to proceed the InvocationContext with Bulkhead semantics if Fault Tolerance is enabled
if (faultToleranceService.isFaultToleranceEnabled(appName, config)) {
logger.log(Level.FINER, "Proceeding invocation with bulkhead semantics");
proceededInvocationContext = bulkhead(invocationContext);
} else {
// If fault tolerance isn't enabled, just proceed as normal
logger.log(Level.FINE, "Fault Tolerance not enabled for {0}, proceeding normally without bulkhead.", faultToleranceService.getApplicationName(invocationManager, invocationContext));
proceededInvocationContext = invocationContext.proceed();
}
} catch (Exception ex) {
Retry retry = FaultToleranceCdiUtils.getAnnotation(beanManager, Retry.class, invocationContext);
if (retry != null) {
logger.log(Level.FINE, "Retry annotation found on method, propagating error upwards.");
throw ex;
} else {
// If an exception was thrown, check if the method is annotated with @Fallback
Fallback fallback = FaultToleranceCdiUtils.getAnnotation(beanManager, Fallback.class, invocationContext);
// If the method was annotated with Fallback, attempt it, otherwise just propagate the exception upwards
if (fallback != null) {
logger.log(Level.FINE, "Fallback annotation found on method, and no Retry annotation - " + "falling back from Bulkhead");
FallbackPolicy fallbackPolicy = new FallbackPolicy(fallback, config, invocationContext);
proceededInvocationContext = fallbackPolicy.fallback(invocationContext);
} else {
logger.log(Level.FINE, "Fallback annotation not found on method, propagating error upwards.", ex);
throw ex;
}
}
}
return proceededInvocationContext;
}
Aggregations