• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java InterceptionException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中br.com.caelum.vraptor.InterceptionException的典型用法代码示例。如果您正苦于以下问题:Java InterceptionException类的具体用法?Java InterceptionException怎么用?Java InterceptionException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



InterceptionException类属于br.com.caelum.vraptor包,在下文中一共展示了InterceptionException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: intercept

import br.com.caelum.vraptor.InterceptionException; //导入依赖的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.InterceptionException; //导入依赖的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: intercept

import br.com.caelum.vraptor.InterceptionException; //导入依赖的package包/类
@BeforeCall
public void intercept() throws InterceptionException {
	
	String origin = request.getHeader("origin") != null ? request.getHeader("origin") : "*";
	
	response.addHeader("Access-Control-Allow-Origin", origin);
	response.addHeader("Access-Control-Allow-Credentials", "true");
	response.addHeader("Access-Control-Expose-Headers", "Content-Type, Location");
}
 
开发者ID:pedro-hos,项目名称:aprendendo-vraptor,代码行数:10,代码来源:CORSInterceptor.java


示例4: intercept

import br.com.caelum.vraptor.InterceptionException; //导入依赖的package包/类
@Override
public void intercept(InterceptorStack stack, ResourceMethod method, Object resourceInstance) throws InterceptionException {
	sessionManager.refreshSession(userSession);
	request.setAttribute("userSession", userSession);
	request.setAttribute("roleManager", userSession.getRoleManager());
	stack.next(method, resourceInstance);
}
 
开发者ID:eclipse123,项目名称:JForum,代码行数:8,代码来源:SessionManagerInterceptor.java


示例5: intercept

import br.com.caelum.vraptor.InterceptionException; //导入依赖的package包/类
@Override
public void intercept(InterceptorStack stack, ResourceMethod method, Object resourceInstance) throws InterceptionException {
	RoleManager roleManager = userSession.getRoleManager();

	if (!roleManager.isAdministrator() && !roleManager.isModerator() && !roleManager.getCanEditPosts()) {
		int postId = Integer.parseInt(request.getParameter("postId"));

		Post post = this.postRepository.get(postId);
		Forum forum = post.getForum();

		long time = this.repository.getLimitedTime(forum);

		if (time > 0) {
			long duration = (System.currentTimeMillis() - post.getDate().getTime()) / 1000;

			if (duration > time) {
				// TODO: Decide to where redirect the user
				throw new RuntimeException("duration > time");
			}
		}

		if (roleManager.getPostOnlyWithModeratorOnline() && !sessionManager.isModeratorOnline()) {
			// TODO
			throw new RuntimeException("Posting is only allowed when moderators are online");
		}
	}

	stack.next(method, resourceInstance);
}
 
开发者ID:eclipse123,项目名称:JForum,代码行数:30,代码来源:PostEditInterceptor.java


示例6: intercept

import br.com.caelum.vraptor.InterceptionException; //导入依赖的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


示例7: intercept

import br.com.caelum.vraptor.InterceptionException; //导入依赖的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


示例8: intercept

import br.com.caelum.vraptor.InterceptionException; //导入依赖的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


示例9: intercept

import br.com.caelum.vraptor.InterceptionException; //导入依赖的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


示例10: intercept

import br.com.caelum.vraptor.InterceptionException; //导入依赖的package包/类
@Override
public void intercept(InterceptorStack stack, 
		ResourceMethod method, Object resourceInstance) throws InterceptionException {

	result.include("errors", Arrays.asList(new ValidationMessage("Usuário não está logado", "Login")));
	result.redirectTo(LoginController.class).login();
}
 
开发者ID:rponte,项目名称:spring-camel,代码行数:8,代码来源:AutenticacaoInterceptor.java


示例11: intercept

import br.com.caelum.vraptor.InterceptionException; //导入依赖的package包/类
@Override
public void intercept(InterceptorStack stack, ControllerMethod method, Object controllerInstance)
	throws InterceptionException {
	try {
		stack.next(method, controllerInstance);
	} catch (InterceptionException e) {
		if (!(e.getCause() instanceof Exception) || !replay((Exception) e.getCause())) {
			throw e;
		}
	}
}
 
开发者ID:caelum,项目名称:vraptor4,代码行数:12,代码来源:ExceptionHandlerInterceptor.java


示例12: invokeMethod

import br.com.caelum.vraptor.InterceptionException; //导入依赖的package包/类
private Object invokeMethod(Object interceptor, Method stepMethod, Object... params) {
	try {
		return reflectionProvider.invoke(interceptor, stepMethod, params);
	} catch (Exception e) {
		// we dont wanna wrap it if it is a simple controller business logic
		// exception
		propagateIfInstanceOf(e.getCause(), ApplicationLogicException.class);
		throw new InterceptionException(e.getCause());
	}
}
 
开发者ID:caelum,项目名称:vraptor4,代码行数:11,代码来源:StepInvoker.java


示例13: intercept

import br.com.caelum.vraptor.InterceptionException; //导入依赖的package包/类
@Override
public void intercept(InterceptorStack stack, ControllerMethod method, Object controllerInstance)
		throws InterceptionException {
	Map<String, Object> parameters = (Map<String, Object>) session.getAttribute(FLASH_INCLUDED_PARAMETERS);
	
	if (parameters != null) {
		parameters = new HashMap<>(parameters);
		
		session.removeAttribute(FLASH_INCLUDED_PARAMETERS);
		for (Entry<String, Object> parameter : parameters.entrySet()) {
			result.include(parameter.getKey(), parameter.getValue());
		}
	}
	response.addRedirectListener(new RedirectListener() {
		@Override
		public void beforeRedirect() {
			Map<String, Object> included = result.included();
			if (!included.isEmpty()) {
				try {
					session.setAttribute(FLASH_INCLUDED_PARAMETERS, new HashMap<>(included));
				} catch (IllegalStateException e) {
					LOGGER.warn("HTTP Session was invalidated. It is not possible to include " +
							"Result parameters on Flash Scope", e);
				}
			}
		}
	});
	stack.next(method, controllerInstance);

}
 
开发者ID:caelum,项目名称:vraptor4,代码行数:31,代码来源:FlashInterceptor.java


示例14: validate

import br.com.caelum.vraptor.InterceptionException; //导入依赖的package包/类
@Override
public void validate(Class<?> originalType, List<Method> methods) {
	Method accepts = invoker.findMethod(methods, Accepts.class, originalType);

	if (accepts != null && !isBooleanReturn(accepts.getReturnType())) {
		throw new InterceptionException(format("@%s method must return boolean", 
				Accepts.class.getSimpleName()));
	}
}
 
开发者ID:caelum,项目名称:vraptor4,代码行数:10,代码来源:AcceptsNeedReturnBooleanValidationRule.java


示例15: validate

import br.com.caelum.vraptor.InterceptionException; //导入依赖的package包/类
@Override
public void validate(Class<?> originalType, List<Method> methods) {

	boolean hasAfterMethod = hasAnnotatedMethod(AfterCall.class, originalType, methods);
	boolean hasAroundMethod = hasAnnotatedMethod(AroundCall.class, originalType, methods);
	boolean hasBeforeMethod = hasAnnotatedMethod(BeforeCall.class, originalType, methods);

	if (!hasAfterMethod && !hasAroundMethod && !hasBeforeMethod) {
		throw new InterceptionException(format("Interceptor %s must "
			+ "declare at least one method whith @AfterCall, @AroundCall "
			+ "or @BeforeCall annotation", originalType.getCanonicalName()));
	}
}
 
开发者ID:caelum,项目名称:vraptor4,代码行数:14,代码来源:NoInterceptMethodsValidationRule.java


示例16: couldntFind

import br.com.caelum.vraptor.InterceptionException; //导入依赖的package包/类
@Override
public void couldntFind(FilterChain chain, MutableRequest request, MutableResponse response) {
	event.fire(new ControllerNotFound());
	try {
		chain.doFilter(request, response);
	} catch (IOException | ServletException e) {
		throw new InterceptionException(e);
	}
}
 
开发者ID:caelum,项目名称:vraptor4,代码行数:10,代码来源:DefaultControllerNotFoundHandler.java


示例17: deny

import br.com.caelum.vraptor.InterceptionException; //导入依赖的package包/类
@Override
public void deny(MutableRequest request, MutableResponse response, Set<HttpMethod> allowedMethods) {
	response.addHeader("Allow", Joiner.on(", ").join(allowedMethods));
	try {
		if (!"OPTIONS".equalsIgnoreCase(request.getMethod())) {
			response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
		}
	} catch (IOException e) {
		throw new InterceptionException(e);
	}
}
 
开发者ID:caelum,项目名称:vraptor4,代码行数:12,代码来源:DefaultMethodNotAllowedHandler.java


示例18: next

import br.com.caelum.vraptor.InterceptionException; //导入依赖的package包/类
@Override
public void next(ControllerMethod method, Object controllerInstance) throws InterceptionException {
	Iterator<InterceptorHandler> iterator = internalStack.peek();

	if (!iterator.hasNext()) {
		interceptorsExecutedEvent.fire(new InterceptorsExecuted(controllerMethod.get(), controllerInstance));
		logger.debug("All registered interceptors have been called. End of VRaptor Request Execution.");
		return;
	}
	InterceptorHandler handler = iterator.next();
	handler.execute(this, method, controllerInstance);

}
 
开发者ID:caelum,项目名称:vraptor4,代码行数:14,代码来源:DefaultInterceptorStack.java


示例19: execute

import br.com.caelum.vraptor.InterceptionException; //导入依赖的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);
	}
}
 
开发者ID:caelum,项目名称:vraptor4,代码行数:16,代码来源:ToInstantiateInterceptorHandler.java


示例20: shouldVerifyIfAcceptsMethodReturnsVoid

import br.com.caelum.vraptor.InterceptionException; //导入依赖的package包/类
@Test
public void shouldVerifyIfAcceptsMethodReturnsVoid() {
	exception.expect(InterceptionException.class);
	exception.expectMessage("@Accepts method must return boolean");

	Class<VoidAcceptsInterceptor> type = VoidAcceptsInterceptor.class;
	List<Method> allMethods = stepInvoker.findAllMethods(type);
	validationRule.validate(type, allMethods);
}
 
开发者ID:caelum,项目名称:vraptor4,代码行数:10,代码来源:AcceptsNeedReturnBooleanValidationRuleTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Cas10ProxyHandler类代码示例发布时间:2022-05-23
下一篇:
Java PutRet类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap