Java Code Examples for io.jboot.web.controller.JbootController#renderJson()
The following examples show how to use
io.jboot.web.controller.JbootController#renderJson() .
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: NotNullParaInterceptor.java From jboot-admin with Apache License 2.0 | 6 votes |
private void renderError(Invocation inv, String param, String errorRedirect) { if (StrUtils.isNotBlank(errorRedirect)) { inv.getController().redirect(errorRedirect); return; } Controller controller = inv.getController(); if (controller instanceof JbootController) { JbootController jc = (JbootController) controller; if (jc.isAjaxRequest()) { jc.renderJson(RestResult.buildError("参数["+param+"]不可为空")); return; } } controller.setAttr(BusinessExceptionInterceptor.MESSAGE_TAG, "参数["+param+"]不可为空").render(exceptionView); }
Example 2
Source File: BusinessExceptionInterceptor.java From jboot-admin with Apache License 2.0 | 6 votes |
@Override public void intercept(Invocation inv) { try { inv.invoke(); } catch (JbootException e) { if (inv.getTarget() instanceof JbootController) { JbootController controller = inv.getTarget(); if (controller.isAjaxRequest()) { RestResult<String> restResult = new RestResult<String>(); restResult.error(e.getMessage()); controller.renderJson(restResult); } else { controller.setAttr(MESSAGE_TAG, e.getMessage()).render(exceptionView); } } } }
Example 3
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(); }