当前位置: 首页>>代码示例>>Java>>正文


Java ControllerMethod类代码示例

本文整理汇总了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();
	}
}
 
开发者ID:progolden,项目名称:vraptor-boilerplate,代码行数:25,代码来源:PermissionInterceptor.java

示例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);
}
 
开发者ID:caelum,项目名称:mamute,代码行数:19,代码来源:RulesInterceptor.java

示例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);
		}
	}
}
 
开发者ID:caelum,项目名称:vraptor4,代码行数:19,代码来源:MethodValidator.java

示例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));
}
 
开发者ID:caelum,项目名称:vraptor4,代码行数:26,代码来源:DefaultRouterTest.java

示例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);
	}
}
 
开发者ID:caelum,项目名称:vraptor4,代码行数:26,代码来源:ExecuteMethod.java

示例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");
}
 
开发者ID:caelum,项目名称:vraptor4,代码行数:19,代码来源:DeserializingObserverTest.java

示例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();
}
 
开发者ID:caelum,项目名称:vraptor4,代码行数:20,代码来源:DefaultRefererResultTest.java

示例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();
}
 
开发者ID:caelum,项目名称:vraptor4,代码行数:20,代码来源:DefaultRefererResultTest.java

示例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)));
}
 
开发者ID:caelum,项目名称:vraptor4,代码行数:26,代码来源:DefaultRouterTest.java

示例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);
}
 
开发者ID:caelum,项目名称:mamute,代码行数:8,代码来源:GlobalInterceptor.java

示例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;
	}
}
 
开发者ID:caelum,项目名称:mamute,代码行数:32,代码来源:InternalErrorInterceptor.java

示例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();
	}
}
 
开发者ID:caelum,项目名称:mamute,代码行数:11,代码来源:PimpMyControllerInterceptor.java

示例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);
}
 
开发者ID:caelum,项目名称:mamute,代码行数:15,代码来源:RedirectCommitInterceptor.java

示例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);
}
 
开发者ID:caelum,项目名称:mamute,代码行数:12,代码来源:BlockedIpInterceptor.java

示例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));
}
 
开发者ID:caelum,项目名称:vraptor4,代码行数:8,代码来源:RequestHandlerObserverTest.java


注:本文中的br.com.caelum.vraptor.controller.ControllerMethod类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。