use of javax.interceptor.AroundInvoke in project indy by Commonjava.
the class MetricsInterceptor method operation.
@AroundInvoke
public Object operation(InvocationContext context) throws Exception {
if (!config.isMetricsEnabled())
return context.proceed();
IndyMetrics metrics = context.getMethod().getAnnotation(IndyMetrics.class);
if (metrics == null) {
return context.proceed();
}
logger.debug("Gathering metrics for: {}", context.getContextData());
Measure measures = metrics.measure();
List<Timer.Context> timers = Stream.of(measures.timers()).map(named -> util.getTimer(named).time()).collect(Collectors.toList());
try {
return context.proceed();
} catch (Exception e) {
Measure me = metrics.exceptions();
Stream.of(me.meters()).forEach((named) -> {
Meter requests = util.getMeter(named);
requests.mark();
});
throw e;
} finally {
if (timers != null) {
timers.forEach(Timer.Context::stop);
}
Stream.of(measures.meters()).forEach((named) -> {
Meter requests = util.getMeter(named);
requests.mark();
});
}
}
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 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 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 tomee by apache.
the class EjbInterceptor method intercept.
@AroundInvoke
public Object intercept(InvocationContext context) throws Exception {
Endpoint endpoint = this.exchange.get(Endpoint.class);
Service service = endpoint.getService();
Binding binding = ((JaxWsEndpointImpl) endpoint).getJaxwsBinding();
this.exchange.put(InvocationContext.class, context);
if (binding.getHandlerChain() == null || binding.getHandlerChain().isEmpty()) {
// no handlers so let's just directly invoke the bean
log.debug("No handlers found.");
EjbMethodInvoker invoker = (EjbMethodInvoker) service.getInvoker();
return invoker.directEjbInvoke(this.exchange, this.method, this.params);
} else {
// have handlers so have to run handlers now and redo data binding
// as handlers can change the soap message
log.debug("Handlers found.");
Message inMessage = exchange.getInMessage();
PhaseInterceptorChain chain = new PhaseInterceptorChain(bus.getExtension(PhaseManager.class).getInPhases());
chain.setFaultObserver(endpoint.getOutFaultObserver());
/*
* Since we have to re-do data binding and the XMLStreamReader
* contents are already consumed by prior data binding step
* we have to reinitialize the XMLStreamReader from the SOAPMessage
* created by SAAJInInterceptor.
*/
if (inMessage instanceof SoapMessage) {
try {
reserialize((SoapMessage) inMessage);
} catch (Exception e) {
throw new ServerRuntimeException("Failed to reserialize soap message", e);
}
} else {
// TODO: how to handle XML/HTTP binding?
}
this.exchange.setOutMessage(null);
// install default interceptors
chain.add(new ServiceInvokerInterceptor());
//chain.add(new OutgoingChainInterceptor()); // it is already in the enclosing chain, if we add it there we are in the tx so we write the message in the tx!
// See http://cwiki.apache.org/CXF20DOC/interceptors.html
// install Holder and Wrapper interceptors
chain.add(new WrapperClassInInterceptor());
chain.add(new HolderInInterceptor());
// install interceptors for handler processing
chain.add(new MustUnderstandInterceptor());
chain.add(new LogicalHandlerInInterceptor(binding));
chain.add(new SOAPHandlerInterceptor(binding));
// install data binding interceptors - todo: check we need it
copyDataBindingInterceptors(chain, inMessage.getInterceptorChain());
InterceptorChain oldChain = inMessage.getInterceptorChain();
inMessage.setInterceptorChain(chain);
try {
chain.doIntercept(inMessage);
} finally {
inMessage.setInterceptorChain(oldChain);
}
// TODO: the result should be deserialized from SOAPMessage
Object result = getResult();
return result;
}
}
Aggregations