| | |
| | | } |
| | | Object reqCache = request.getAttribute("cache"); |
| | | boolean success = String.valueOf(((R) o).get("code")).equalsIgnoreCase("200"); |
| | | if (success) { |
| | | apiLogService.save( |
| | | String.valueOf(appAuth), |
| | | request.getRequestURI(), |
| | | appkey, |
| | | IpTools.gainRealIp(request), |
| | | reqCache == null ? "" : JSON.toJSONString(reqCache), |
| | | JSON.toJSONString(o), |
| | | success |
| | | ); |
| | | } else { |
| | | beforeBodyWriteCallApiLogSave( |
| | | String.valueOf(appAuth), |
| | | request.getRequestURI(), |
| | | appkey, |
| | | IpTools.gainRealIp(request), |
| | | reqCache == null ? "" : JSON.toJSONString(reqCache), |
| | | JSON.toJSONString(o), |
| | | success); |
| | | String uri = request.getRequestURI(); |
| | | if (!skipOpenAsrsHighFrequencyApiLog(uri)) { |
| | | if (success) { |
| | | apiLogService.save( |
| | | String.valueOf(appAuth), |
| | | uri, |
| | | appkey, |
| | | IpTools.gainRealIp(request), |
| | | reqCache == null ? "" : JSON.toJSONString(reqCache), |
| | | JSON.toJSONString(o), |
| | | success |
| | | ); |
| | | } else { |
| | | beforeBodyWriteCallApiLogSave( |
| | | String.valueOf(appAuth), |
| | | uri, |
| | | appkey, |
| | | IpTools.gainRealIp(request), |
| | | reqCache == null ? "" : JSON.toJSONString(reqCache), |
| | | JSON.toJSONString(o), |
| | | success); |
| | | } |
| | | } |
| | | } else if (o instanceof R && isInboundThirdPartyUri(request.getRequestURI())) { |
| | | String appkey = request.getHeader("appkey"); |
| | |
| | | } |
| | | Object reqCache = request.getAttribute("cache"); |
| | | boolean success = String.valueOf(((R) o).get("code")).equalsIgnoreCase("200"); |
| | | String ns = inboundNamespace(request.getRequestURI()); |
| | | if (success) { |
| | | apiLogService.save( |
| | | ns, |
| | | request.getRequestURI(), |
| | | appkey, |
| | | IpTools.gainRealIp(request), |
| | | reqCache == null ? "" : JSON.toJSONString(reqCache), |
| | | JSON.toJSONString(o), |
| | | success |
| | | ); |
| | | } else { |
| | | beforeBodyWriteCallApiLogSave( |
| | | ns, |
| | | request.getRequestURI(), |
| | | appkey, |
| | | IpTools.gainRealIp(request), |
| | | reqCache == null ? "" : JSON.toJSONString(reqCache), |
| | | JSON.toJSONString(o), |
| | | success); |
| | | String uri = request.getRequestURI(); |
| | | String ns = inboundNamespace(uri); |
| | | if (!skipOpenAsrsHighFrequencyApiLog(uri)) { |
| | | if (success) { |
| | | apiLogService.save( |
| | | ns, |
| | | uri, |
| | | appkey, |
| | | IpTools.gainRealIp(request), |
| | | reqCache == null ? "" : JSON.toJSONString(reqCache), |
| | | JSON.toJSONString(o), |
| | | success |
| | | ); |
| | | } else { |
| | | beforeBodyWriteCallApiLogSave( |
| | | ns, |
| | | uri, |
| | | appkey, |
| | | IpTools.gainRealIp(request), |
| | | reqCache == null ? "" : JSON.toJSONString(reqCache), |
| | | JSON.toJSONString(o), |
| | | success); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return o; |
| | | } |
| | | |
| | | /** 电视机/看板等高频查询,不落 api_log(context-path 前缀任意,只匹配路径后缀) */ |
| | | private static final String[] OPEN_ASRS_SKIP_LOG_URI_SUFFIXES = { |
| | | "/open/asrs/queryTask", |
| | | "/open/asrs/queryLoc", |
| | | "/open/asrs/line/charts/hourly", |
| | | "/open/asrs/line/charts", |
| | | "/open/asrs/locDetl/statistics", |
| | | }; |
| | | |
| | | private static boolean skipOpenAsrsHighFrequencyApiLog(String uri) { |
| | | if (uri == null) { |
| | | return false; |
| | | } |
| | | int cut = uri.indexOf(';'); |
| | | String path = cut > 0 ? uri.substring(0, cut) : uri; |
| | | for (String suffix : OPEN_ASRS_SKIP_LOG_URI_SUFFIXES) { |
| | | if (path.endsWith(suffix)) { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | private static boolean isInboundThirdPartyUri(String uri) { |
| | |
| | | } |
| | | |
| | | public void beforeBodyWriteCallApiLogSave(String name, String url, String appkey, String ip, String request, String response, boolean success) { |
| | | if (skipOpenAsrsHighFrequencyApiLog(url)) { |
| | | return; |
| | | } |
| | | ApiLogService apiLogService = SpringUtils.getBean(ApiLogService.class); |
| | | String memo = response; |
| | | try{ |