use of org.aopalliance.intercept.MethodInvocation in project shiro by apache.
the class SecureRemoteInvocationFactoryTest method testSessionManagerProxyNonStartRemoteInvocation.
@Test
public void testSessionManagerProxyNonStartRemoteInvocation() throws Exception {
SecureRemoteInvocationFactory factory = new SecureRemoteInvocationFactory();
MethodInvocation mi = createMock(MethodInvocation.class);
Method method = getMethod("getSession", SessionManager.class);
expect(mi.getMethod()).andReturn(method).anyTimes();
String dummySessionId = UUID.randomUUID().toString();
SessionKey sessionKey = new DefaultSessionKey(dummySessionId);
Object[] args = { sessionKey };
expect(mi.getArguments()).andReturn(args).anyTimes();
replay(mi);
RemoteInvocation ri = factory.createRemoteInvocation(mi);
verify(mi);
assertEquals(dummySessionId, ri.getAttribute(SecureRemoteInvocationFactory.SESSION_ID_KEY));
}
use of org.aopalliance.intercept.MethodInvocation in project camunda-bpm-platform by camunda.
the class ProcessScope method createDirtyCheckingProxy.
private Object createDirtyCheckingProxy(final String name, final Object scopedObject) throws Throwable {
ProxyFactory proxyFactoryBean = new ProxyFactory(scopedObject);
proxyFactoryBean.setProxyTargetClass(this.proxyTargetClass);
proxyFactoryBean.addAdvice(new MethodInterceptor() {
public Object invoke(MethodInvocation methodInvocation) throws Throwable {
Object result = methodInvocation.proceed();
persistVariable(name, scopedObject);
return result;
}
});
return proxyFactoryBean.getProxy(this.classLoader);
}
use of org.aopalliance.intercept.MethodInvocation in project spring-cloud-stream by spring-cloud.
the class DefaultPollableMessageSource method setSource.
public void setSource(MessageSource<?> source) {
ProxyFactory pf = new ProxyFactory(source);
class ReceiveAdvice implements MethodInterceptor {
private final List<ChannelInterceptor> interceptors = new ArrayList<>();
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
Object result = invocation.proceed();
if (result instanceof Message) {
Message<?> received = (Message<?>) result;
for (ChannelInterceptor interceptor : this.interceptors) {
received = interceptor.preSend(received, null);
if (received == null) {
return null;
}
}
return received;
}
return result;
}
}
final ReceiveAdvice advice = new ReceiveAdvice();
advice.interceptors.addAll(this.interceptors);
NameMatchMethodPointcutAdvisor sourceAdvisor = new NameMatchMethodPointcutAdvisor(advice);
sourceAdvisor.addMethodName("receive");
pf.addAdvisor(sourceAdvisor);
this.source = (MessageSource<?>) pf.getProxy();
}
use of org.aopalliance.intercept.MethodInvocation in project guice by google.
the class MethodInterceptionTest method testGetElements_interceptorBindings.
@Test
public void testGetElements_interceptorBindings() throws Exception {
@SuppressWarnings("rawtypes") Matcher<Class> classMatcher = Matchers.subclassesOf(List.class);
Matcher<Method> methodMatcher = Matchers.returns(Matchers.identicalTo(int.class));
MethodInterceptor interceptor = new MethodInterceptor() {
@Override
public Object invoke(MethodInvocation methodInvocation) throws Throwable {
return null;
}
};
Injector injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bindInterceptor(classMatcher, methodMatcher, interceptor);
}
});
final List<InterceptorBinding> interceptorBindings = new ArrayList<>();
for (Element element : injector.getElements()) {
element.acceptVisitor(new DefaultElementVisitor<Void>() {
@Override
public Void visit(InterceptorBinding interceptorBinding) {
interceptorBindings.add(interceptorBinding);
return null;
}
});
}
assertThat(interceptorBindings).hasSize(1);
InterceptorBinding extractedBinding = interceptorBindings.get(0);
assertSame(classMatcher, extractedBinding.getClassMatcher());
assertSame(methodMatcher, extractedBinding.getMethodMatcher());
assertSame(interceptor, extractedBinding.getInterceptors().get(0));
}
use of org.aopalliance.intercept.MethodInvocation in project guice by google.
the class JpaPersistModule method bindFinder.
private <T> void bindFinder(Class<T> iface) {
if (!isDynamicFinderValid(iface)) {
return;
}
InvocationHandler finderInvoker = new InvocationHandler() {
@Inject
JpaFinderProxy finderProxy;
@Override
public Object invoke(final Object thisObject, final Method method, final Object[] args) throws Throwable {
// Don't intercept non-finder methods like equals and hashcode.
if (!method.isAnnotationPresent(Finder.class)) {
// and hashcode as a proxy (!) for the proxy's equals and hashcode.
return method.invoke(this, args);
}
return finderProxy.invoke(new MethodInvocation() {
@Override
public Method getMethod() {
return method;
}
@Override
public Object[] getArguments() {
return null == args ? new Object[0] : args;
}
@Override
public Object proceed() throws Throwable {
return method.invoke(thisObject, args);
}
@Override
public Object getThis() {
throw new UnsupportedOperationException("Bottomless proxies don't expose a this.");
}
@Override
public AccessibleObject getStaticPart() {
throw new UnsupportedOperationException();
}
});
}
};
requestInjection(finderInvoker);
// Proxy must produce instance of type given.
@SuppressWarnings("unchecked") T proxy = (T) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class<?>[] { iface }, finderInvoker);
bind(iface).toInstance(proxy);
}
Aggregations