Java Code Examples for com.jfinal.aop.Invocation#invoke()
The following examples show how to use
com.jfinal.aop.Invocation#invoke() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VisitorInterceptor.java From zrlog with Apache License 2.0 | 6 votes |
private void installPermission(Invocation ai) { String template = null; if (!ZrLogConfig.isInstalled()) { ai.invoke(); if (ai.getReturnValue() != null) { template = ai.getReturnValue(); } } else { ai.getController().getRequest().setAttribute("errorMsg", ((Map) ai.getController().getRequest().getAttribute("_res")).get("installed")); } if (template == null) { template = "/install/forbidden"; } ai.getController().setAttr("currentViewName", template.substring("/install/".length())); ai.getController().render(new FreeMarkerRender(template + ".ftl")); }
Example 2
Source File: ParaValidateInterceptor.java From jboot with Apache License 2.0 | 6 votes |
@Override public void intercept(Invocation inv) { Method method = inv.getMethod(); EmptyValidate emptyParaValidate = method.getAnnotation(EmptyValidate.class); if (emptyParaValidate != null && !validateEmpty(inv, emptyParaValidate)) { return; } CaptchaValidate captchaValidate = method.getAnnotation(CaptchaValidate.class); if (captchaValidate != null && !validateCaptache(inv, captchaValidate)) { return; } inv.invoke(); }
Example 3
Source File: InstallInterceptor.java From jpress with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void intercept(Invocation inv) { if (Installer.isInstalled()) { inv.getController().renderError(404); return; } inv.invoke(); }
Example 4
Source File: UserInterceptor.java From jpress with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void intercept(Invocation inv) { Controller c = inv.getController(); User user = c.getAttr(JPressConsts.ATTR_LOGINED_USER); if (user != null) { //购物车的相关信息 setUserCartInfoAttrs(inv, user); inv.invoke(); return; } String uid = CookieUtil.get(c, JPressConsts.COOKIE_UID); if (StrUtil.isBlank(uid)) { inv.invoke(); return; } user = userService.findById(uid); if (user != null) { c.setAttr(JPressConsts.ATTR_LOGINED_USER, user); setUserCartInfoAttrs(inv, user); } inv.invoke(); }
Example 5
Source File: UserCenterInterceptor.java From jpress with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void intercept(Invocation inv) { List<MenuGroup> ucenterMenus = MenuManager.me().getUcenterMenus(); inv.getController().setAttr("ucenterMenus", ucenterMenus); inv.getController().setAttr("user", UserInterceptor.getThreadLocalUser()); inv.invoke(); }
Example 6
Source File: ApiInterceptor.java From jfinal-weixin with Apache License 2.0 | 5 votes |
public void intercept(Invocation inv) { Controller controller = inv.getController(); if (controller instanceof ApiController == false) throw new RuntimeException("控制器需要继承 ApiController"); try { ApiConfigKit.setThreadLocalApiConfig(((ApiController)controller).getApiConfig()); inv.invoke(); } finally { ApiConfigKit.removeThreadLocalApiConfig(); } }
Example 7
Source File: JbootCachesEvictInterceptor.java From jboot with Apache License 2.0 | 5 votes |
@Override public void intercept(Invocation inv) { Method method = inv.getMethod(); CachesEvict cachesEvict = method.getAnnotation(CachesEvict.class); if (cachesEvict == null) { inv.invoke(); return; } CacheEvict[] evicts = cachesEvict.value(); List<CacheEvict> beforeInvocations = null; List<CacheEvict> afterInvocations = null; for (CacheEvict evict : evicts) { if (evict.beforeInvocation()) { if (beforeInvocations == null) { beforeInvocations = new ArrayList<>(); } beforeInvocations.add(evict); } else { if (afterInvocations == null) { afterInvocations = new ArrayList<>(); } afterInvocations.add(evict); } } Class targetClass = inv.getTarget().getClass(); try { doCachesEvict(inv.getArgs(), targetClass, method, beforeInvocations); inv.invoke(); } finally { doCachesEvict(inv.getArgs(), targetClass, method, afterInvocations); } }
Example 8
Source File: ProductValidate.java From jpress with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void intercept(Invocation inv) { Controller c = inv.getController(); Long productId = inv.getController().getLong("id"); Product product = productService.findById(productId); if (product == null || !product.isNormal()) { if (RequestUtil.isAjaxRequest(c.getRequest())) { c.renderJson(Ret.fail().set("code", "2").set("message", "商品不存在或已下架。")); } else { c.renderError(404); } return; } User user = UserInterceptor.getThreadLocalUser(); if (user == null) { if (RequestUtil.isAjaxRequest(c.getRequest())) { c.renderJson(Ret.fail() .set("code", 1) .set("message", "用户未登录") .set("gotoUrl", JFinal.me().getContextPath() + "/user/login?gotoUrl=" + product.getUrl())); } else { c.redirect("/user/login?gotoUrl=" + product.getUrl()); } return; } c.setAttr(ATTR_PRODUCT,product); inv.invoke(); }
Example 9
Source File: UTMInterceptor.java From jpress with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void intercept(Invocation inv) { try { doRecordUTM(inv); } finally { inv.invoke(); } }
Example 10
Source File: LimiterInterceptor.java From jboot with Apache License 2.0 | 5 votes |
private void doInterceptForTokenBucket(int rate, String resource, String fallback, Invocation inv) { RateLimiter limiter = LimiterManager.me().getOrCreateRateLimiter(resource, rate); //允许通行 if (limiter.tryAcquire()) { inv.invoke(); } //不允许通行 else { doExecFallback(resource, fallback, inv); } }
Example 11
Source File: JwtInterceptor.java From jboot with Apache License 2.0 | 5 votes |
@Override public void intercept(Invocation inv) { if (!JwtManager.me().getConfig().isConfigOk()) { inv.invoke(); return; } HttpServletRequest request = inv.getController().getRequest(); String token = request.getHeader(JwtManager.me().getHttpHeaderName()); if (StrUtil.isBlank(token) && StrUtil.isNotBlank(JwtManager.me().getHttpParameterKey())) { token = request.getParameter(JwtManager.me().getHttpParameterKey()); } if (StrUtil.isBlank(token)) { processInvoke(inv, null); return; } Map map = JwtManager.me().parseJwtToken(token); if (map == null) { processInvoke(inv, null); return; } try { JwtManager.me().holdJwts(map); processInvoke(inv, map); } finally { JwtManager.me().releaseJwts(); } }
Example 12
Source File: SentinelInterceptor.java From jboot with Apache License 2.0 | 5 votes |
@Override public void intercept(Invocation inv) { SentinelProcesser processer = SentinelManager.me().getProcesser(); if (processer != null){ processer.doProcess(inv); }else { inv.invoke(); } }
Example 13
Source File: PermissionInterceptor.java From my_curd with Apache License 2.0 | 5 votes |
@Override public void intercept(Invocation inv) { boolean flag = true; Controller controller = inv.getController(); // 验证菜单权限 RequirePermission requirePermission = inv.getClass().getAnnotation(RequirePermission.class); List<String> codes; if (requirePermission != null ) { codes = requirePermission.isPermission() ? controller.getSessionAttr("menuCodes") : controller.getSessionAttr("roleCodes"); flag = codes.contains(requirePermission.value()); } if (flag) { // 菜单权限通后 再验证按钮权限 requirePermission = inv.getMethod().getAnnotation(RequirePermission.class); if (requirePermission != null) { codes = requirePermission.isPermission() ? controller.getSessionAttr("buttonCodes") : controller.getSessionAttr("roleCodes"); flag = codes.contains(requirePermission.value()); } } if (flag) { // 菜单权限、按钮权限 都具备 放行 inv.invoke(); return; } // 无权限响应 String requestType = inv.getController().getHeader("X-Requested-With"); if ("XMLHttpRequest".equals(requestType) || StringUtils.notEmpty(inv.getController().getPara("xmlHttpRequest"))) { Ret ret = Ret.create().setFail().set("msg", "无权限操作!您的行为已被记录到日志。"); // 其实并没有,可以自行扩展 controller.renderJson(ret); } else { controller.render("/WEB-INF/views/common/no_permission.ftl"); } }
Example 14
Source File: InitDataInterceptor.java From zrlog with Apache License 2.0 | 5 votes |
private void doIntercept(Invocation invocation) { //未安装情况下,尝试跳转去安装 if (!ZrLogConfig.isInstalled() && !invocation.getActionKey().startsWith(INSTALL_ROUTER_PATH)) { invocation.getController().redirect(INSTALL_ROUTER_PATH); return; } if (invocation.getController() instanceof BaseController) { HttpServletRequest request = invocation.getController().getRequest(); BaseController baseController = (BaseController) invocation.getController(); baseController.setAttr("requrl", ZrLogUtil.getFullUrl(request)); cacheService.refreshInitDataCache(GlobalResourceHandler.CACHE_HTML_PATH, baseController, false); lastAccessTime = System.currentTimeMillis(); } invocation.invoke(); }
Example 15
Source File: AdminInterceptor.java From zrlog with Apache License 2.0 | 5 votes |
/** * 为了规范代码,这里做了一点类是Spring的ResponseEntity的东西,及通过方法的返回值来判断是应该返回页面还会对应JSON数据 * 具体方式看 AdminRouters,这里用到了 ThreadLocal * * @param ai */ private void adminPermission(Invocation ai) { Controller controller = ai.getController(); AdminTokenVO adminTokenVO = adminTokenService.getAdminTokenVO(controller.getRequest()); if (adminTokenVO != null) { try { User user = new User().findById(adminTokenVO.getUserId()); if (StringUtils.isEmpty(user.getStr("header"))) { user.set("header", Constants.DEFAULT_HEADER); } controller.setAttr("user", user); controller.setAttr("protocol", adminTokenVO.getProtocol()); TemplateHelper.fullTemplateInfo(controller, false); if (!"/admin/logout".equals(ai.getActionKey())) { adminTokenService.setAdminToken(user, adminTokenVO.getSessionId(), adminTokenVO.getProtocol(), controller.getRequest(), controller.getResponse()); } ai.invoke(); // 存在消息提示 if (controller.getAttr("message") != null) { initIndex(controller.getRequest()); controller.render(new FreeMarkerRender("/admin/index.ftl")); } else { if (!tryDoRender(ai, controller)) { controller.renderHtml(IOUtil.getStringInputStream(new FileInputStream(PathKit.getWebRootPath() + Constants.NOT_FOUND_PAGE))); } } } catch (Exception e) { LOGGER.error("", e); exceptionHandler(ai, e); } finally { AdminTokenThreadLocal.remove(); } } else if ("/admin/login".equals(ai.getActionKey()) || "/api/admin/login".equals(ai.getActionKey())) { ai.invoke(); tryDoRender(ai, controller); } else { blockUnLoginRequestHandler(ai); } }
Example 16
Source File: ApiInterceptor.java From jpress with GNU Lesser General Public License v3.0 | 4 votes |
@Override public void intercept(Invocation inv) { // API 功能未启用 if (apiEnable == false) { inv.getController().renderJson(Ret.fail().set("message", "API功能已经关闭,请管理员在后台进行开启")); return; } if (StrUtil.isBlank(apiAppId)) { inv.getController().renderJson(Ret.fail().set("message", "后台配置的 APP ID 不能为空,请先进入后台的接口管理进行配置。")); return; } if (StrUtil.isBlank(apiSecret)) { inv.getController().renderJson(Ret.fail().set("message", "后台配置的 API 密钥不能为空,请先进入后台的接口管理进行配置。")); return; } JbootController controller = (JbootController) inv.getController(); String queryString = controller.getRequest().getQueryString(); if (StrUtil.isBlank(queryString)) { inv.getController().renderJson(Ret.fail().set("message", "请求参数错误。")); return; } Map<String, String> parasMap = paramToMap(queryString); String appId = parasMap.get("appId"); if (StrUtil.isBlank(appId)) { inv.getController().renderJson(Ret.fail().set("message", "在Url中未获取到appId内容,请注意Url是否正确。")); return; } if (!appId.equals(apiAppId)) { inv.getController().renderJson(Ret.fail().set("message", "客户端配置的AppId和服务端配置的不一致。")); return; } String sign = parasMap.get("sign"); if (StrUtil.isBlank(sign)) { controller.renderJson(Ret.fail("message", "签名数据不能为空,请提交 sign 数据。")); return; } String timeStr = parasMap.get("t"); Long time = timeStr == null ? null : Long.valueOf(timeStr); if (time == null) { controller.renderJson(Ret.fail("message", "时间参数不能为空,请提交 t 参数数据。")); return; } // 时间验证,可以防止重放攻击 if (Math.abs(System.currentTimeMillis() - time) > TIMEOUT) { controller.renderJson(Ret.fail("message", "请求超时,请重新请求。")); return; } String localSign = createLocalSign(controller); if (sign.equals(localSign) == false) { inv.getController().renderJson(Ret.fail().set("message", "数据签名错误。")); return; } Object userId = controller.getJwtPara(JPressConsts.JWT_USERID); if (userId != null) { controller.setAttr(JPressConsts.ATTR_LOGINED_USER, userService.findById(userId)); } inv.invoke(); }
Example 17
Source File: JbootCacheInterceptor.java From jboot with Apache License 2.0 | 4 votes |
@Override public void intercept(Invocation inv) { Method method = inv.getMethod(); Cacheable cacheable = method.getAnnotation(Cacheable.class); if (cacheable == null) { inv.invoke(); return; } String unlessString = AnnotationUtil.get(cacheable.unless()); if (Utils.isUnless(unlessString, method, inv.getArgs())) { inv.invoke(); return; } Class targetClass = inv.getTarget().getClass(); String cacheName = AnnotationUtil.get(cacheable.name()); Utils.ensureCachenameAvailable(method, targetClass, cacheName); String cacheKey = Utils.buildCacheKey(AnnotationUtil.get(cacheable.key()), targetClass, method, inv.getArgs()); Object data = AopCache.get(cacheName, cacheKey); if (data != null) { if (NULL_VALUE.equals(data)) { inv.setReturnValue(null); } else if (cacheable.returnCopyEnable()) { inv.setReturnValue(getCopyObject(inv, data)); } else { inv.setReturnValue(data); } } else { inv.invoke(); data = inv.getReturnValue(); if (data != null) { Utils.putDataToCache(cacheable.liveSeconds(), cacheName, cacheKey, data); //当启用返回 copy 值的时候,返回的内容应该是一个进行copy之后的值 if (cacheable.returnCopyEnable()) { inv.setReturnValue(getCopyObject(inv, data)); } } else if (cacheable.nullCacheEnable()) { Utils.putDataToCache(cacheable.liveSeconds(), cacheName, cacheKey, NULL_VALUE); } } }
Example 18
Source File: BlogInterceptor.java From sqlhelper with GNU Lesser General Public License v3.0 | 4 votes |
public void intercept(Invocation inv) { System.out.println("Before invoking " + inv.getActionKey()); inv.invoke(); System.out.println("After invoking " + inv.getActionKey()); }
Example 19
Source File: HelloWorldAddonInterceptor.java From jpress with GNU Lesser General Public License v3.0 | 3 votes |
@Override public void intercept(Invocation inv) { System.out.println("HelloWorldAddonInterceptor invoke"); inv.invoke(); }
Example 20
Source File: DubboInterceptor.java From jboot with Apache License 2.0 | 3 votes |
@Override public void intercept(Invocation inv) { System.out.println("intercept : " + blogService); inv.invoke(); }