本文整理汇总了Java中br.com.caelum.vraptor.interceptor.Interceptor类的典型用法代码示例。如果您正苦于以下问题:Java Interceptor类的具体用法?Java Interceptor怎么用?Java Interceptor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Interceptor类属于br.com.caelum.vraptor.interceptor包,在下文中一共展示了Interceptor类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handlerFor
import br.com.caelum.vraptor.interceptor.Interceptor; //导入依赖的package包/类
@Override
public InterceptorHandler handlerFor(final Class<?> type) {
return cachedHandlers.fetch(type, new Supplier<InterceptorHandler>() {
@Override
public InterceptorHandler get() {
if(type.isAnnotationPresent(Intercepts.class) && !Interceptor.class.isAssignableFrom(type)){
return new AspectStyleInterceptorHandler(type, stepInvoker, container, customAcceptsExecutor,
acceptsExecutor, interceptorExecutor);
}
return new ToInstantiateInterceptorHandler(container, type, executeMethodExceptionHandler);
}
});
}
示例2: execute
import br.com.caelum.vraptor.interceptor.Interceptor; //导入依赖的package包/类
@Override
public void execute(final InterceptorStack stack, final ControllerMethod method, final Object controllerInstance)
throws InterceptionException {
final Interceptor interceptor = (Interceptor) container.instanceFor(type);
if (interceptor == null) {
throw new InterceptionException("Unable to instantiate interceptor for " + type.getName()
+ ": the container returned null.");
}
if (interceptor.accepts(method)) {
logger.debug("Invoking interceptor {}", interceptor.getClass().getSimpleName());
executeSafely(stack, method, controllerInstance, interceptor);
} else {
stack.next(method, controllerInstance);
}
}
示例3: executeSafely
import br.com.caelum.vraptor.interceptor.Interceptor; //导入依赖的package包/类
private void executeSafely(final InterceptorStack stack, final ControllerMethod method, final Object controllerInstance, final Interceptor interceptor) {
Try result = Try.run(new Callable<Void>() {
@Override
public Void call() throws Exception {
interceptor.intercept(stack, method, controllerInstance);
return null;
}
});
if (result.failed()) {
executeMethodExceptionHandler.handle(result.getException());
}
}
示例4: shouldInvokeInterceptorsMethodIfAbleToInstantiateIt
import br.com.caelum.vraptor.interceptor.Interceptor; //导入依赖的package包/类
@Test
public void shouldInvokeInterceptorsMethodIfAbleToInstantiateIt() throws InterceptionException, IOException {
final Object instance = new Object();
when(container.instanceFor(Interceptor.class)).thenReturn(interceptor);
when(interceptor.accepts(method)).thenReturn(true);
ToInstantiateInterceptorHandler handler = new ToInstantiateInterceptorHandler(container, Interceptor.class, new ExecuteMethodExceptionHandler());
handler.execute(stack, method, instance);
verify(interceptor).intercept(stack, method, instance);
}
示例5: shouldNotInvokeInterceptorsMethodIfInterceptorDoesntAcceptsResource
import br.com.caelum.vraptor.interceptor.Interceptor; //导入依赖的package包/类
@Test
public void shouldNotInvokeInterceptorsMethodIfInterceptorDoesntAcceptsResource() throws InterceptionException, IOException {
final Object instance = new Object();
when(container.instanceFor(Interceptor.class)).thenReturn(interceptor);
when(interceptor.accepts(method)).thenReturn(false);
ToInstantiateInterceptorHandler handler = new ToInstantiateInterceptorHandler(container, Interceptor.class, new ExecuteMethodExceptionHandler());
handler.execute(stack, method, instance);
verify(interceptor, never()).intercept(stack, method, instance);
verify(stack).next(method, instance);
}