コード例 #1
0
 @Override
 public void execute() {
   HttpServletRequest request = this.httpServletRequestManager.getThreadLocal();
   String[] parameterValues = request.getParameterValues(this.paraName);
   String errorMsg = "";
   String paraValue = "";
   if (parameterValues == null) {
     errorMsg = WorkHandler.NULL_MESSAGE;
   } else {
     for (int index = 0; index < parameterValues.length; index++) {
       paraValue = parameterValues[index];
       paraValue = HttpUtils.trim(paraValue);
       if (!paraValue.isEmpty()) {
         errorMsg = this.fieldHandler.validate(paraValue);
         if (errorMsg.isEmpty()) {
           parameterValues[index] = paraValue;
         } else {
           break;
         }
       } else {
         errorMsg = WorkHandler.EMPTY_MESSAGE;
         break;
       }
     }
   }
   if (errorMsg.isEmpty()) {
     this.insertAccessActionLog(parameterValues);
     this.BatchParaManager.openThreadLocal(parameterValues);
     this.nextWorkHandler.execute();
     this.BatchParaManager.closeThreadLocal();
   } else {
     errorMsg = this.paraName.concat(errorMsg);
     this.logger.debug("get parameter failure. Cause: {},value:{}", errorMsg, paraValue);
     ResponseWriter responseWriter = this.responseWriterManager.getThreadLocal();
     responseWriter.invalid();
     responseWriter.setInfo(errorMsg);
     HttpServletResponse response = this.httpServletResponseManager.getThreadLocal();
     responseWriter.writeJson(request, response);
   }
 }
 @Override
 public void execute() {
   HttpServletRequest request = this.httpServletRequestManager.getThreadLocal();
   String cacheId = request.getParameter("cacheId");
   if (cacheId == null || cacheId.isEmpty()) {
     // 没有缓存
     this.simpleMapWorkHandler.execute();
   } else {
     // 获取缓存信息
     ResponseFlagType flag = DefaultResponseFlagEnum.SUCCESS;
     Element element = this.parameterCache.getQuiet(cacheId);
     String paraValue = "";
     String errorParaName = "";
     String errorMsg = "";
     FieldHandler fieldHandler;
     Map<String, String> parameterMap =
         new HashMap<String, String>(importantParameter.length + minorParameter.length, 1);
     if (element == null) {
       // 超时
       flag = DefaultResponseFlagEnum.TIMEOUT;
     } else {
       // 有缓存
       ParameterCache paraCache = (ParameterCache) element.getObjectValue();
       for (String parameter : this.importantParameter) {
         paraValue = paraCache.getParameter(parameter);
         if (paraValue == null) {
           flag = DefaultResponseFlagEnum.TIMEOUT;
           break;
         } else {
           parameterMap.put(parameter, paraValue);
         }
       }
       for (String parameter : this.minorParameter) {
         paraValue = paraCache.getParameter(parameter);
         if (paraValue != null) {
           parameterMap.put(parameter, paraValue);
         }
       }
       if (flag == DefaultResponseFlagEnum.SUCCESS) {
         for (String parameter : this.minorParameter) {
           paraValue = request.getParameter(parameter);
           if (paraValue != null) {
             paraValue = HttpUtils.trim(paraValue);
             fieldHandler = this.fieldHandlerMap.get(parameter);
             errorMsg = fieldHandler.validate(paraValue);
             if (errorMsg.isEmpty()) {
               parameterMap.put(parameter, paraValue);
             } else {
               errorParaName = parameter;
               break;
             }
           }
         }
       }
     }
     if (errorMsg.isEmpty() && flag == DefaultResponseFlagEnum.SUCCESS) {
       this.simpleMapManager.openThreadLocal(parameterMap);
       this.nextWorkHandler.execute();
       this.simpleMapManager.closeThreadLocal();
     } else {
       ResponseWriter responseWriter = this.responseWriterManager.getThreadLocal();
       HttpServletResponse response = this.httpServletResponseManager.getThreadLocal();
       if (flag == DefaultResponseFlagEnum.TIMEOUT) {
         responseWriter.timeOut();
       } else {
         errorMsg = errorParaName.concat(errorMsg);
         this.logger.debug("get parameter failure. Cause: {},value:{}", errorMsg, paraValue);
         responseWriter.invalid();
         responseWriter.setInfo(errorMsg);
       }
       responseWriter.writeJson(request, response);
     }
   }
 }