本文整理汇总了Java中br.com.caelum.vraptor.controller.ControllerMethod类的典型用法代码示例。如果您正苦于以下问题:Java ControllerMethod类的具体用法?Java ControllerMethod怎么用?Java ControllerMethod使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ControllerMethod类属于br.com.caelum.vraptor.controller包,在下文中一共展示了ControllerMethod类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: intercept
import br.com.caelum.vraptor.controller.ControllerMethod; //导入依赖的package包/类
@Override
public void intercept(InterceptorStack stack, ControllerMethod method, Object controllerInstance)
throws InterceptionException {
if (this.session.isLogged()) {
Permissioned ann = method.getMethod().getAnnotation(Permissioned.class);
if (ann.value().getLevel() > session.getAccessLevel()) {
if (ann.permissions().length <= 0) {
this.unauthorized();
} else {
for (Class<? extends Permission> perm : ann.permissions()) {
if (session.getPermissions().contains(perm.getCanonicalName())) {
stack.next(method, controllerInstance);
return;
}
}
this.unauthorized();
}
} else {
stack.next(method, controllerInstance);
}
} else {
this.unauthorized();
}
}
示例2: intercept
import br.com.caelum.vraptor.controller.ControllerMethod; //导入依赖的package包/类
@Override
public void intercept(InterceptorStack stack, ControllerMethod method,
Object obj) throws InterceptionException {
ClassController<KarmaCalculator> mirrorOnKarma = new Mirror().on(KarmaCalculator.class);
List<Field> karmaCalculatorFields = mirrorOnKarma.reflectAll().fields();
for (Field field : karmaCalculatorFields) {
result.include(field.getName(), mirrorOnKarma.get().field(field));
}
PermissionRules[] rules = PermissionRules.values();
for (PermissionRules rule : rules) {
long karma = environmentKarma.get(rule);
result.include(rule.name(), karma);
}
stack.next(method, obj);
}
示例3: validate
import br.com.caelum.vraptor.controller.ControllerMethod; //导入依赖的package包/类
public void validate(@Observes MethodReady event, ControllerInstance controllerInstance, MethodInfo methodInfo,
Validator validator) {
ControllerMethod method = event.getControllerMethod();
if (hasConstraints(method)) {
Set<ConstraintViolation<Object>> violations = bvalidator.forExecutables().validateParameters(
controllerInstance.getController(), method.getMethod(), methodInfo.getParametersValues());
logger.debug("there are {} constraint violations at method {}.", violations.size(), method);
for (ConstraintViolation<Object> v : violations) {
String category = extractCategory(methodInfo.getValuedParameters(), v);
String msg = extractInternacionalizedMessage(v);
validator.add(new SimpleMessage(category, msg));
logger.debug("added message {}={} for contraint violation", category, msg);
}
}
}
示例4: shouldObeyPriorityOfRoutes
import br.com.caelum.vraptor.controller.ControllerMethod; //导入依赖的package包/类
@Test
public void shouldObeyPriorityOfRoutes() throws Exception {
Route first = mock(Route.class);
when(first.getControllerMethod()).thenReturn(anyControllerMethod());
Route second = mock(Route.class);
when(second.getControllerMethod()).thenReturn(anyControllerMethod());
ControllerMethod method2 = second.controllerMethod(request, "second");
router.add(second);
router.add(first);
when(first.getPriority()).thenReturn(Path.HIGH);
when(second.getPriority()).thenReturn(Path.LOW);
EnumSet<HttpMethod> get = EnumSet.of(HttpMethod.GET);
when(first.allowedMethods()).thenReturn(get);
when(second.allowedMethods()).thenReturn(get);
when(first.canHandle(anyString())).thenReturn(false);
when(second.canHandle(anyString())).thenReturn(true);
ControllerMethod found = router.parse("anything", HttpMethod.GET, request);
assertThat(found, is(method2));
}
示例5: execute
import br.com.caelum.vraptor.controller.ControllerMethod; //导入依赖的package包/类
public void execute(@Observes final InterceptorsExecuted event) {
Try run = Try.run(new Callable<Void>() {
@Override
public Void call() throws Exception {
ControllerMethod method = event.getControllerMethod();
methodReady.fire(new MethodReady(method));
Method reflectionMethod = method.getMethod();
Object[] parameters = methodInfo.getParametersValues();
log.debug("Invoking {}", reflectionMethod);
Object instance = event.getControllerInstance();
Object result = reflectionProvider.invoke(instance, reflectionMethod, parameters);
messages.assertAbsenceOfErrors();
methodInfo.setResult(result);
methodExecutedEvent.fire(new MethodExecuted(method, methodInfo));
return null;
}
});
if (run.failed()) {
Exception exception = run.getException();
executeMethodExceptionHandler.handle(exception);
}
}
示例6: willDeserializeForAnyContentTypeIfPossible
import br.com.caelum.vraptor.controller.ControllerMethod; //导入依赖的package包/类
@Test
public void willDeserializeForAnyContentTypeIfPossible() throws Exception {
final ControllerMethod consumesAnything = new DefaultControllerMethod(null,
DummyResource.class.getDeclaredMethod("consumesAnything", String.class, String.class));
when(request.getContentType()).thenReturn("application/xml");
methodInfo.setControllerMethod(consumesAnything);
final Deserializer deserializer = mock(Deserializer.class);
when(deserializer.deserialize(null, consumesAnything)).thenReturn(new Object[] {"abc", "def"});
when(deserializers.deserializerFor("application/xml", container)).thenReturn(deserializer);
observer.deserializes(new InterceptorsReady(consumesAnything), request, methodInfo, status);
assertEquals(methodInfo.getValuedParameters()[0].getValue(), "abc");
assertEquals(methodInfo.getValuedParameters()[1].getValue(), "def");
}
示例7: whenRefererMatchesAControllerShouldRedirectToIt
import br.com.caelum.vraptor.controller.ControllerMethod; //导入依赖的package包/类
@Test
public void whenRefererMatchesAControllerShouldRedirectToIt() throws Exception {
LogicResult logic = mock(LogicResult.class);
RefererController controller = mock(RefererController.class);
Method index = RefererController.class.getMethod("index");
ControllerMethod method = DefaultControllerMethod.instanceFor(RefererController.class, index);
when(request.getHeader("Referer")).thenReturn("http://localhost:8080/vraptor/no-controller");
when(request.getContextPath()).thenReturn("/vraptor");
when(router.parse("/no-controller", HttpMethod.GET, request)).thenReturn(method);
doReturn(logic).when(result).use(logic());
when(logic.redirectTo(RefererController.class)).thenReturn(controller);
refererResult.redirect();
verify(logic).redirectTo(RefererController.class);
verify(controller).index();
}
示例8: whenRefererMatchesAControllerShouldForwardToIt
import br.com.caelum.vraptor.controller.ControllerMethod; //导入依赖的package包/类
@Test
public void whenRefererMatchesAControllerShouldForwardToIt() throws Exception {
LogicResult logic = mock(LogicResult.class);
RefererController controller = mock(RefererController.class);
Method index = RefererController.class.getMethod("index");
ControllerMethod method = DefaultControllerMethod.instanceFor(RefererController.class, index);
when(request.getHeader("Referer")).thenReturn("http://localhost:8080/vraptor/no-controller");
when(request.getContextPath()).thenReturn("/vraptor");
when(router.parse("/no-controller", HttpMethod.GET, request)).thenReturn(method);
doReturn(logic).when(result).use(logic());
when(logic.forwardTo(RefererController.class)).thenReturn(controller);
refererResult.forward();
verify(logic).forwardTo(RefererController.class);
verify(controller).index();
}
示例9: usesTheFirstRegisteredRuleMatchingThePattern
import br.com.caelum.vraptor.controller.ControllerMethod; //导入依赖的package包/类
@Test
public void usesTheFirstRegisteredRuleMatchingThePattern() throws SecurityException, NoSuchMethodException {
Route route = mock(Route.class);
Route second = mock(Route.class, "second");
when(route.getControllerMethod()).thenReturn(anyControllerMethod());
when(second.getControllerMethod()).thenReturn(anyControllerMethod());
when(route.canHandle("/clients/add")).thenReturn(true);
when(second.canHandle("/clients/add")).thenReturn(true);
EnumSet<HttpMethod> all = EnumSet.allOf(HttpMethod.class);
when(route.allowedMethods()).thenReturn(all);
when(second.allowedMethods()).thenReturn(all);
when(route.controllerMethod(request, "/clients/add")).thenReturn(method);
when(route.getPriority()).thenReturn(Path.HIGHEST);
when(second.getPriority()).thenReturn(Path.LOWEST);
router.add(route);
router.add(second);
ControllerMethod found = router.parse("/clients/add", HttpMethod.POST, request);
assertThat(found, is(equalTo(method)));
}
示例10: intercept
import br.com.caelum.vraptor.controller.ControllerMethod; //导入依赖的package包/类
public void intercept(InterceptorStack stack, ControllerMethod method,
Object resourceInstance) throws InterceptionException {
LOG.debug("request for: " + req.getRequestURI());
viewObjects.include();
stack.next(method, resourceInstance);
}
示例11: intercept
import br.com.caelum.vraptor.controller.ControllerMethod; //导入依赖的package包/类
@Override
public void intercept(InterceptorStack stack, ControllerMethod method,
Object instance) throws InterceptionException {
try {
stack.next(method, instance);
}catch (Exception e) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
Throwable cause = e.getCause();
if(cause != null){
if (cause instanceof ConstraintViolationException) {
Set<ConstraintViolation<?>> constraintViolations = ((ConstraintViolationException) cause).getConstraintViolations();
pw.printf("\nConstraint Violations: \n");
for (ConstraintViolation<?> constraintViolation : constraintViolations) {
pw.printf("\t" +constraintViolation.getConstraintDescriptor().getAnnotation()+"\n");
}
pw.printf("\n");
log.error(sw.toString());
}
cause.printStackTrace(pw);
}else{
e.printStackTrace(pw);
}
pw.close();
result.include("stacktrace", sw.toString());
throw e;
}
}
示例12: intercept
import br.com.caelum.vraptor.controller.ControllerMethod; //导入依赖的package包/类
@Override
public void intercept(InterceptorStack stack, ControllerMethod method,
Object obj) throws InterceptionException {
try {
locals.reset().put(Result.class, result).put(MessageFactory.class, factory);
stack.next(method, obj);
} finally {
locals.clear();
}
}
示例13: intercept
import br.com.caelum.vraptor.controller.ControllerMethod; //导入依赖的package包/类
@Override
public void intercept(InterceptorStack stack, ControllerMethod method,
Object instance) {
response.addRedirectListener(new RedirectListener() {
@Override
public void beforeRedirect() {
Transaction transaction = session.getTransaction();
if (!validator.hasErrors() && transaction.isActive()) {
session.flush();
}
}
});
stack.next(method, instance);
}
示例14: intercept
import br.com.caelum.vraptor.controller.ControllerMethod; //导入依赖的package包/类
@Override
public void intercept(InterceptorStack interceptorStack, ControllerMethod controllerMethod, Object o) throws InterceptionException {
List<BlockedIp> ips = blockedIps.list();
Collection<IpMatcher> matchers = Collections2.transform(ips, extractIp);
boolean isBlocked = matches(matchers);
if (isBlocked) {
result.use(http()).sendError(503);
return;
}
interceptorStack.next(controllerMethod, o);
}
示例15: shouldFireTheControllerWasFound
import br.com.caelum.vraptor.controller.ControllerMethod; //导入依赖的package包/类
@Test
public void shouldFireTheControllerWasFound() throws Exception {
final ControllerMethod method = mock(ControllerMethod.class);
when(translator.translate(webRequest)).thenReturn(method);
observer.handle(requestStarted);
verify(controllerFoundEvent).fire(any(ControllerFound.class));
}