/** * 返回响应结果 * * @param response * @return */ public static RestResponse returnResponse( BaseRestRequest request, RestResponse response, RestServiceMapping serviceMapping, RestServiceConfiguration configuration) { String cmd = request.getRestRequest().getCmd(); // 调用后置拦截器 List<RestRequestAfterInterceptor> requestAfterInterceptors = configuration.getRequestAfterInterceptors(); for (RestRequestAfterInterceptor requestInterceptor : requestAfterInterceptors) { String requestInterceptorName = requestInterceptor.getName(); logger.debug( "REST_AFTER_INTERCEPTOR_START, cmd: {}, name: {}", cmd, requestInterceptorName + "|" + requestInterceptor.getClass().getName()); try { requestInterceptor.setConfiguration(configuration); requestInterceptor.execute(serviceMapping, request, response); } catch (Exception e) { response.setException(e); logger.warn("执行拦截器 {} 失败", requestInterceptorName, e); } logger.debug( "REST_AFTER_INTERCEPTOR_COMPLETE, cmd: {}, name: {}", cmd, requestInterceptorName + "|" + requestInterceptor.getClass().getName()); } return response; }
protected static void recordToErrorCounter(String cmd) { String today = DateUtil.format(new Date(), "yyyyMMdd"); try { RedisUtil.incr(ERROR_COUNT_KEY + today); } catch (Exception e) { logger.warn("记录api返回错误请求的次数失败, today: {}", today, e); } try { RedisUtil.incr(ERROR_COUNT_KEY + today + ":cmd:" + cmd); } catch (Exception e) { logger.warn("记录cmd: {}, today: {} 返回错误请求的次数失败", cmd, today, e); } }