Browse Source

临时去掉exam模块接口签名强验证;修改redis删除lock的失效时间;修改GlobalExceptionHandler的日志打印位置

luoshi 4 năm trước cách đây
mục cha
commit
aaf1223c60

+ 13 - 8
themis-business/src/main/java/com/qmth/themis/business/util/RedisUtil.java

@@ -41,7 +41,8 @@ public class RedisUtil {
      * @param o
      */
     public void setOrg(Long orgId, Object o) {
-        redisTemplate.opsForValue().set(SystemConstant.ORG + orgId, o, SystemConstant.REDIS_EXPIRE_TIME, TimeUnit.SECONDS);
+        redisTemplate.opsForValue()
+                .set(SystemConstant.ORG + orgId, o, SystemConstant.REDIS_EXPIRE_TIME, TimeUnit.SECONDS);
     }
 
     /**
@@ -80,7 +81,8 @@ public class RedisUtil {
      * @param o
      */
     public void setOrgCode(String orgCode, Object o) {
-        redisTemplate.opsForValue().set(SystemConstant.ORG + orgCode, o, SystemConstant.REDIS_EXPIRE_TIME, TimeUnit.SECONDS);
+        redisTemplate.opsForValue()
+                .set(SystemConstant.ORG + orgCode, o, SystemConstant.REDIS_EXPIRE_TIME, TimeUnit.SECONDS);
     }
 
     /**
@@ -146,7 +148,8 @@ public class RedisUtil {
      * @param o
      */
     public void setUser(Long userId, Object o) {
-        redisTemplate.opsForValue().set(SystemConstant.USER + userId, o, SystemConstant.REDIS_EXPIRE_TIME, TimeUnit.SECONDS);
+        redisTemplate.opsForValue()
+                .set(SystemConstant.USER + userId, o, SystemConstant.REDIS_EXPIRE_TIME, TimeUnit.SECONDS);
     }
 
     /**
@@ -225,7 +228,6 @@ public class RedisUtil {
         }
     }
 
-
     /**
      * 设置hash
      *
@@ -297,7 +299,7 @@ public class RedisUtil {
      * @return
      */
     public void releaseLock(String key) {
-        redisTemplate.expire(key, 100, TimeUnit.MILLISECONDS);
+        redisTemplate.expire(key, 0, TimeUnit.MILLISECONDS);
     }
 
     /**
@@ -379,7 +381,8 @@ public class RedisUtil {
      * @return
      */
     public Integer getRedisSequence() {
-        RedisAtomicInteger entityIdCounter = new RedisAtomicInteger(SystemConstant.REDIS_MONITOR_SEQUENCE, redisTemplate.getConnectionFactory());
+        RedisAtomicInteger entityIdCounter = new RedisAtomicInteger(SystemConstant.REDIS_MONITOR_SEQUENCE,
+                redisTemplate.getConnectionFactory());
         return entityIdCounter.incrementAndGet();
     }
 
@@ -390,7 +393,8 @@ public class RedisUtil {
      * @return
      */
     public Integer getRedisActivityCodeSequence(Long key) {
-        RedisAtomicInteger entityIdCounter = new RedisAtomicInteger(SystemConstant.REDIS_ACTIVITY_CODE_SEQUENCE + key, redisTemplate.getConnectionFactory());
+        RedisAtomicInteger entityIdCounter = new RedisAtomicInteger(SystemConstant.REDIS_ACTIVITY_CODE_SEQUENCE + key,
+                redisTemplate.getConnectionFactory());
         return entityIdCounter.incrementAndGet();
     }
 
@@ -402,7 +406,8 @@ public class RedisUtil {
      * @return
      */
     public Integer setRedisActivityCodeSequence(Long key, int initialValue) {
-        RedisAtomicInteger entityIdCounter = new RedisAtomicInteger(SystemConstant.REDIS_ACTIVITY_CODE_SEQUENCE + key, redisTemplate.getConnectionFactory(), initialValue);
+        RedisAtomicInteger entityIdCounter = new RedisAtomicInteger(SystemConstant.REDIS_ACTIVITY_CODE_SEQUENCE + key,
+                redisTemplate.getConnectionFactory(), initialValue);
         return entityIdCounter.get();
     }
 

+ 4 - 3
themis-common/src/main/java/com/qmth/themis/common/exception/GlobalDefultExceptionHandler.java

@@ -22,6 +22,7 @@ import java.sql.SQLException;
  */
 @ControllerAdvice
 public class GlobalDefultExceptionHandler {
+
     private final static Logger log = LoggerFactory.getLogger(GlobalDefultExceptionHandler.class);
 
     /**
@@ -35,6 +36,7 @@ public class GlobalDefultExceptionHandler {
     @ExceptionHandler(Exception.class)
     @ResponseBody
     public <T> Result defultExcepitonHandler(Exception e, HttpServletResponse response) {
+        log.error("Global exception", e);
         if (e instanceof BusinessException) {
             BusinessException businessException = (BusinessException) e;
             response.setStatus(businessException.getCode());
@@ -46,8 +48,6 @@ public class GlobalDefultExceptionHandler {
             }
         }
         response.setStatus(ExceptionResultEnum.EXCEPTION_ERROR.getCode());
-        //Exception错误
-        log.error("Exception 请求出错", e);
         return ResultUtil.error(ExceptionResultEnum.EXCEPTION_ERROR.getStatusCode(), e.getMessage());
     }
 
@@ -80,6 +80,7 @@ public class GlobalDefultExceptionHandler {
     public <T> Result invocationTargetExceptionHandler(InvocationTargetException e, HttpServletResponse response) {
         response.setStatus(ExceptionResultEnum.INVOCATIONTARGET_ERROR.getCode());
         log.error("invocationTargetExceptionHandler 请求出错", e);
-        return ResultUtil.error(ExceptionResultEnum.INVOCATIONTARGET_ERROR.getStatusCode(), ExceptionResultEnum.INVOCATIONTARGET_ERROR.name() + e.getTargetException());
+        return ResultUtil.error(ExceptionResultEnum.INVOCATIONTARGET_ERROR.getStatusCode(),
+                ExceptionResultEnum.INVOCATIONTARGET_ERROR.name() + e.getTargetException());
     }
 }

+ 2 - 2
themis-exam/src/main/java/com/qmth/themis/exam/interceptor/AuthInterceptor.java

@@ -69,7 +69,7 @@ public class AuthInterceptor implements HandlerInterceptor {
         long timestamp = StringUtils.isNumeric(time) ? Long.parseLong(time) : 0L;
         if (SystemConstant.expire(timestamp)) {
             log.warn("Authorization faile: time expired, server time=" + System.currentTimeMillis());
-            throw new BusinessException(ExceptionResultEnum.AUTHORIZATION_ERROR);
+            //throw new BusinessException(ExceptionResultEnum.AUTHORIZATION_ERROR);
         }
         //校验签名信息
         final SignatureInfo info = SignatureInfo.parse(method.toLowerCase(), url, timestamp, authorization);
@@ -94,7 +94,7 @@ public class AuthInterceptor implements HandlerInterceptor {
         }
         if (!info.validate(tbSession.getAccessToken())) {
             log.warn("Authorization faile: access token invalid, session token is " + tbSession.getAccessToken());
-            throw new BusinessException(ExceptionResultEnum.AUTHORIZATION_ERROR);
+            //throw new BusinessException(ExceptionResultEnum.AUTHORIZATION_ERROR);
         }
         if (!tbSession.getPlatform().equalsIgnoreCase(platform.name())) {
             log.warn("Authorization faile: platform invalid, session platform is " + tbSession.getPlatform());