Commit 6d59c1dd0fdc6b94360f880250cfda6a830cc45d

Authored by rui.zhang

Merge remote-tracking branch 'origin/master'

Showing 2 changed files

platform-common/src/main/java/com/lyms/platform/common/base/ExceptionHandlerController.java View file @ 6d59c1d
... ... @@ -7,7 +7,6 @@
7 7 import com.lyms.platform.common.exception.TokenException;
8 8 import com.lyms.platform.common.result.BaseResponse;
9 9 import com.lyms.platform.common.utils.ExceptionUtils;
10   -import com.lyms.platform.common.utils.JsonUtil;
11 10 import org.springframework.aop.AopInvocationException;
12 11 import org.springframework.beans.factory.annotation.Autowired;
13 12 import org.springframework.dao.DataAccessResourceFailureException;
... ... @@ -56,6 +55,7 @@
56 55 error.setErrormsg("错误");
57 56 return error;
58 57 }
  58 +
59 59 @ExceptionHandler(org.springframework.aop.AopInvocationException.class)
60 60 @ResponseBody
61 61 @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
62 62  
63 63  
64 64  
65 65  
66 66  
67 67  
68 68  
69 69  
70 70  
... ... @@ -70,102 +70,82 @@
70 70  
71 71 @ExceptionHandler(MethodArgumentNotValidException.class)
72 72 @ResponseStatus(HttpStatus.OK)
73   - public void validationError(MethodArgumentNotValidException e, HttpServletResponse httpServletResponse) {
74   - try {
75   - setHttpResponseHeader(httpServletResponse);
  73 + public Map validationError(MethodArgumentNotValidException e, HttpServletResponse httpServletResponse) {
  74 + setHttpResponseHeader(httpServletResponse);
76 75  
77   - httpServletResponse.getWriter().print(JsonUtil.obj2JsonString(createValidationResponse(e.getBindingResult())));
78   - } catch (Exception ex) {
79   - }
  76 + return createValidationResponse(e.getBindingResult());
  77 +
80 78 }
81 79  
82 80 @ExceptionHandler(BindException.class)
83 81 @ResponseStatus(HttpStatus.OK)
84   - public void validationError(BindException e, HttpServletResponse httpServletResponse) {
85   - try {
86   - setHttpResponseHeader(httpServletResponse);
  82 + public Map validationError(BindException e, HttpServletResponse httpServletResponse) {
  83 + setHttpResponseHeader(httpServletResponse);
87 84  
88   - httpServletResponse.getWriter().print(JsonUtil.obj2JsonString(createValidationResponse(e.getBindingResult())));
89   - } catch (Exception ex) {
90   - }
  85 + return createValidationResponse(e.getBindingResult());
  86 +
91 87 }
92 88  
93 89 @ResponseStatus(HttpStatus.OK)
94 90 @ExceptionHandler(ParameterException.class)
95   - public void validationError(HttpServletResponse httpServletResponse) {
96   - try {
97   - setHttpResponseHeader(httpServletResponse);
98   - Map<String, Object> resultMap = new HashMap<>();
99   - resultMap.put("errorcode", ErrorCodeConstants.PARAMETER_ERROR);
100   - resultMap.put("errormsg", "参数错误.");
101   - httpServletResponse.getWriter().print(JsonUtil.obj2JsonString(resultMap));
102   - } catch (Exception ex) {
103   - ExceptionUtils.catchException(ex, "ExceptionHandlerController validationError.");
104   - }
  91 + @ResponseBody
  92 + public Map validationError(HttpServletResponse httpServletResponse) {
  93 + setHttpResponseHeader(httpServletResponse);
  94 + Map<String, Object> resultMap = new HashMap<>();
  95 + resultMap.put("errorcode", ErrorCodeConstants.PARAMETER_ERROR);
  96 + resultMap.put("errormsg", "参数错误.");
  97 + return resultMap;
105 98 }
106 99  
107 100 @ResponseStatus(HttpStatus.OK)
108 101 @ExceptionHandler(TokenException.class)
109   - public void buildTokenExpire(HttpServletResponse httpServletResponse) {
110   - try {
111   - setHttpResponseHeader(httpServletResponse);
112   - Map<String, Object> resultMap = new HashMap<>();
113   - resultMap.put("errorcode", ErrorCodeConstants.TOKEN_EXPIRE);
114   - resultMap.put("errormsg", "您当前用户登录状态异常,暂时无法访问,请重新登录");
115   - httpServletResponse.getWriter().print(JsonUtil.obj2JsonString(resultMap));
116   - } catch (Exception ex) {
117   - ExceptionUtils.catchException(ex, "ExceptionHandlerController buildTokenExpire.");
118   - }
  102 + public Map buildTokenExpire(HttpServletResponse httpServletResponse) {
  103 + setHttpResponseHeader(httpServletResponse);
  104 + Map<String, Object> resultMap = new HashMap<>();
  105 + resultMap.put("errorcode", ErrorCodeConstants.TOKEN_EXPIRE);
  106 + resultMap.put("errormsg", "您当前用户登录状态异常,暂时无法访问,请重新登录");
  107 + return resultMap;
119 108 }
120 109  
121 110 /**
122 111 * 处理spring mvc 缺少请求参数的异常提示
123   - *
  112 + *
124 113 * @param httpServletResponse
125 114 * @param missRequestParameter
126 115 */
127 116 @ResponseStatus(HttpStatus.OK)
128 117 @ExceptionHandler(org.springframework.web.bind.MissingServletRequestParameterException.class)
129   - public void handlMissingServletRequestParameter(HttpServletResponse httpServletResponse,
130   - MissingServletRequestParameterException missRequestParameter) {
131   - try {
132   - setHttpResponseHeader(httpServletResponse);
133   - Map<String, Object> resultMap = new HashMap<>();
134   - resultMap.put("errorcode", ErrorCodeConstants.PARAMETER_ERROR);
135   - resultMap.put("errormsg", missRequestParameter.getMessage());
136   - httpServletResponse.getWriter().print(JsonUtil.obj2JsonString(resultMap));
137   - } catch (Exception ex) {
138   - ExceptionUtils.catchException(ex, "ExceptionHandlerController handlMissingServletRequestParameter.");
139   - }
  118 + public Map handlMissingServletRequestParameter(HttpServletResponse httpServletResponse,
  119 + MissingServletRequestParameterException missRequestParameter) {
  120 + setHttpResponseHeader(httpServletResponse);
  121 + Map<String, Object> resultMap = new HashMap<>();
  122 + resultMap.put("errorcode", ErrorCodeConstants.PARAMETER_ERROR);
  123 + resultMap.put("errormsg", missRequestParameter.getMessage());
  124 + ExceptionUtils.catchException(missRequestParameter, "ExceptionHandlerController handlMissingServletRequestParameter.");
  125 + return resultMap;
140 126 }
141 127  
142 128 @ResponseStatus(HttpStatus.OK)
143 129 @ExceptionHandler(BusinessException.class)
144   - public void handlBusinessException(HttpServletResponse httpServletResponse, BusinessException busExc) {
145   - try {
146   - setHttpResponseHeader(httpServletResponse);
147   - Map<String, Object> resultMap = new HashMap<>();
148   - resultMap.put("errorcode", ErrorCodeConstants.BUSINESS_ERROR);
149   - resultMap.put("errormsg", busExc.getMessage());
150   - httpServletResponse.getWriter().print(JsonUtil.obj2JsonString(resultMap));
151   - } catch (Exception ex) {
152   - ExceptionUtils.catchException(ex, "ExceptionHandlerController Write response With handException.");
153   - }
  130 + public Map handlBusinessException(HttpServletResponse httpServletResponse, BusinessException busExc) {
  131 + setHttpResponseHeader(httpServletResponse);
  132 + Map<String, Object> resultMap = new HashMap<>();
  133 + resultMap.put("errorcode", ErrorCodeConstants.BUSINESS_ERROR);
  134 + resultMap.put("errormsg", busExc.getMessage());
  135 + ExceptionUtils.catchException(busExc, "ExceptionHandlerController Write response With handException.");
  136 + return resultMap;
154 137 }
155 138  
156 139 @ResponseStatus(HttpStatus.OK)
157 140 @ExceptionHandler(Exception.class)
158   - public void buildException(HttpServletResponse httpServletResponse, Exception e,HttpServletRequest httpServletRequest) {
159   - try {
160   - setHttpResponseHeader(httpServletResponse);
161   - Map<String, Object> resultMap = new HashMap<>();
162   - resultMap.put("errorcode", ErrorCodeConstants.SYSTEM_ERROR);
163   - resultMap.put("errormsg", "服务器异常.");
164   - httpServletResponse.getWriter().print(JsonUtil.obj2JsonString(resultMap));
165   - ExceptionUtils.catchException(e, "ExceptionHandlerController Exception. queryStr: "+httpServletRequest.getQueryString());
166   - } catch (Exception ex) {
167   - ExceptionUtils.catchException(ex, "ExceptionHandlerController Write response With handException.");
168   - }
  141 + public Map<String, Object> buildException(HttpServletResponse httpServletResponse, Exception e, HttpServletRequest httpServletRequest) {
  142 + setHttpResponseHeader(httpServletResponse);
  143 + Map<String, Object> resultMap = new HashMap<>();
  144 + resultMap.put("errorcode", ErrorCodeConstants.SYSTEM_ERROR);
  145 + resultMap.put("errormsg", "服务器异常.");
  146 + ExceptionUtils.catchException(e, "ExceptionHandlerController Exception. queryStr: " + httpServletRequest.getQueryString());
  147 +
  148 + return resultMap;
169 149 }
170 150  
171 151 private Map<String, Object> createValidationResponse(BindingResult bindingResult) {
... ... @@ -173,7 +153,7 @@
173 153 List<org.springframework.validation.FieldError> fieldErrors = bindingResult.getFieldErrors();
174 154 for (org.springframework.validation.FieldError fieldError : fieldErrors) {
175 155 map.put("errorcode", ErrorCodeConstants.PARAMETER_ERROR);
176   - map.put("errormsg",messageResolver.getErrorMessage(fieldError
  156 + map.put("errormsg", messageResolver.getErrorMessage(fieldError
177 157 .getDefaultMessage()));
178 158 break;
179 159 }
platform-common/src/main/java/com/lyms/platform/common/utils/LoginUtil.java View file @ 6d59c1d
... ... @@ -40,7 +40,7 @@
40 40 PostMethod post = new MessageUtil.UTF8PostMethod("http://passport.healthbaby.com.cn/v1/checkUser.action");
41 41 NameValuePair[] data = {
42 42 new NameValuePair("account", account),
43   - new NameValuePair("pwd", pwd),
  43 + new NameValuePair("password", pwd),
44 44 new NameValuePair("typeId", typeId)
45 45 };
46 46 post.setRequestBody(data);