Commit 0f65af0234e40aa76ac8b3647a8b18721cbe0abf

Authored by Liu Haoyu
1 parent 7a6dd2db

返回内容优化;

潜在空指针问题处理;
异常信息统一处理类型处理;
src/main/java/com/objecteye/config/AuthenticationHeadFilter.java
... ... @@ -58,13 +58,13 @@ public class AuthenticationHeadFilter extends OncePerRequestFilter {
58 58 // 是否超时(默认1小时)
59 59 if (System.currentTimeMillis() > createTime + 1000 * 60 * 60) {
60 60 httpServletResponse.setContentType("application/json;charset=UTF-8");
61   - httpServletResponse.getWriter().write("Token已过期请重新登录");
  61 + httpServletResponse.getWriter().write("登录已过期请重新登录");
62 62 return;
63 63 }
64 64 } catch (Exception e) {
65 65 e.printStackTrace();
66 66 httpServletResponse.setContentType("application/json;charset=UTF-8");
67   - httpServletResponse.getWriter().write("Useless token...");
  67 + httpServletResponse.getWriter().write("登录信息异常");
68 68 return;
69 69 }
70 70 AuthenticationToken authenticationToken = new AuthenticationToken(user, "", user.getAuthorities());
... ...
src/main/java/com/objecteye/config/AuthenticationProviderConfig.java
... ... @@ -27,15 +27,15 @@ public class AuthenticationProviderConfig implements AuthenticationProvider {
27 27 */
28 28 private void defaultCheck(UserDetails user) {
29 29 if (!user.isAccountNonLocked()) {
30   - throw new LockedException("User account is locked");
  30 + throw new LockedException("用户已被锁定");
31 31 }
32 32  
33 33 if (!user.isEnabled()) {
34   - throw new DisabledException("User is disabled");
  34 + throw new DisabledException("当前用户不可用");
35 35 }
36 36  
37 37 if (!user.isAccountNonExpired()) {
38   - throw new AccountExpiredException("User account has expired");
  38 + throw new AccountExpiredException("账号已被注销");
39 39 }
40 40 }
41 41  
... ... @@ -45,11 +45,11 @@ public class AuthenticationProviderConfig implements AuthenticationProvider {
45 45 private void additionalAuthenticationChecks(UserDetails userDetails,
46 46 AuthenticationToken authenticationToken) throws AuthenticationException {
47 47 if (authenticationToken.getCredentials() == null) {
48   - throw new BadCredentialsException("username or password is wrong!");
  48 + throw new BadCredentialsException("登录信息错误");
49 49 }
50 50 String presentedPassword = authenticationToken.getCredentials().toString();
51 51 if (!passwordEncoder.matches(presentedPassword, userDetails.getPassword())) {
52   - throw new BadCredentialsException("username or password is wrong!");
  52 + throw new BadCredentialsException("登录信息错误");
53 53 }
54 54 }
55 55  
... ...
src/main/java/com/objecteye/handle/GlobalExceptionHandler.java
1 1 package com.objecteye.handle;
2 2  
3 3 import com.objecteye.common.CommonResult;
  4 +import com.objecteye.exception.CustomXException;
4 5 import org.springframework.web.bind.annotation.ExceptionHandler;
5 6 import org.springframework.web.bind.annotation.RestControllerAdvice;
6 7  
... ... @@ -10,6 +11,9 @@ import javax.servlet.http.HttpServletRequest;
10 11 public class GlobalExceptionHandler {
11 12 @ExceptionHandler(value = Exception.class)
12 13 public CommonResult globalExceptionHandler(HttpServletRequest httpServletRequest, Exception e) {
  14 + if (e instanceof CustomXException) {
  15 + return CommonResult.success(Integer.parseInt(((CustomXException) e).getCode()), ((CustomXException) e).getMsg(), null);
  16 + }
13 17 return CommonResult.success(504, e.getMessage(), "");
14 18 }
15 19 }
... ...
src/main/java/com/objecteye/utils/RabbitMQVehicleTools.java
... ... @@ -429,14 +429,13 @@ public class RabbitMQVehicleTools {
429 429 // vehicle_plate_status;
430 430 double vehicle_plate_numScore1 = rabbitMQVehicle.getVehicle_plate_numScore();
431 431 String vehiclePlateStatus = null;
432   - if (vehicle_plate_numScore1 == 0) {
  432 + PlatePlateNumParams[] vehicle_plate_plateNumParams = rabbitMQVehicle.getVehicle_plate_plateNumParams();
  433 + if (vehicle_plate_numScore1 == 0 || vehicle_plate_plateNumParams == null) {
433 434 //无号牌
434 435 vehiclePlateStatus = "无号牌";
435 436 } else {
436   - PlatePlateNumParams[] vehicle_plate_plateNumParams = rabbitMQVehicle.getVehicle_plate_plateNumParams();
437 437 String chara = null;
438   - for (int i = 0; i < 7; i++) {
439   - PlatePlateNumParams ppnp = vehicle_plate_plateNumParams[i];
  438 + for (PlatePlateNumParams ppnp : vehicle_plate_plateNumParams) {
440 439 double maxprob = ppnp.getMaxprob();
441 440 if (maxprob == 0) {
442 441 chara = "污损号牌";
... ...