Commit edda4758 by cjh

返回信息添加版本号,配置在spring-mvc.xml文件中

parent a8343c57
package org.sss.presentation.noui.api.response;
public class NoUiVersion {
private String version;
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
}
...@@ -9,19 +9,30 @@ public class Result { ...@@ -9,19 +9,30 @@ public class Result {
private Map<String, Object> error;// 错误信息 private Map<String, Object> error;// 错误信息
private Map<String, Object> codetable; private Map<String, Object> codetable;
private Object data; private Object data;
private String verison;
public Result(String retcod, String retmsg, Object data) { public String getVerison() {
return verison;
}
public void setVerison(String verison) {
this.verison = verison;
}
public Result(String retcod, String retmsg, Object data,String verison) {
this.retcod = retcod; this.retcod = retcod;
this.retmsg = retmsg; this.retmsg = retmsg;
this.data = data; this.data = data;
this.verison = verison;
} }
public Result(String retcod, String retmsg, Map<String, Object> error, Map<String, Object> codetable, Object data) { public Result(String retcod, String retmsg, Map<String, Object> error, Map<String, Object> codetable, Object data,String verison) {
this.retcod = retcod; this.retcod = retcod;
this.retmsg = retmsg; this.retmsg = retmsg;
this.error = error; this.error = error;
this.codetable = codetable; this.codetable = codetable;
this.data = data; this.data = data;
this.verison = verison;
} }
public String getRetcod() { public String getRetcod() {
......
...@@ -4,11 +4,11 @@ import java.util.Map; ...@@ -4,11 +4,11 @@ import java.util.Map;
public class ResultUtil { public class ResultUtil {
public static Result result(String retcod, String retmsg, Object data) { public static Result result(String retcod, String retmsg, Object data,String version) {
return new Result(retcod, retmsg, data); return new Result(retcod, retmsg, data,version);
} }
public static Result result(String retcod, String retmsg, Map<String, Object> data, Map<String, Object> error, Map<String, Object> codetable) { public static Result result(String retcod, String retmsg, Map<String, Object> data, Map<String, Object> error, Map<String, Object> codetable,String version) {
return new Result(retcod, retmsg, error, codetable, data); return new Result(retcod, retmsg, error, codetable, data,version);
} }
} }
...@@ -10,6 +10,7 @@ import javax.servlet.http.HttpServletResponse; ...@@ -10,6 +10,7 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import org.sss.common.model.EventType; import org.sss.common.model.EventType;
import org.sss.common.model.IBaseObject; import org.sss.common.model.IBaseObject;
...@@ -22,6 +23,7 @@ import org.sss.presentation.noui.api.exception.NoUiException; ...@@ -22,6 +23,7 @@ import org.sss.presentation.noui.api.exception.NoUiException;
import org.sss.presentation.noui.api.model.Alias; import org.sss.presentation.noui.api.model.Alias;
import org.sss.presentation.noui.api.request.NoUiRequest; import org.sss.presentation.noui.api.request.NoUiRequest;
import org.sss.presentation.noui.api.response.ErrorCodes; import org.sss.presentation.noui.api.response.ErrorCodes;
import org.sss.presentation.noui.api.response.NoUiVersion;
import org.sss.presentation.noui.api.response.Result; import org.sss.presentation.noui.api.response.Result;
import org.sss.presentation.noui.api.response.ResultUtil; import org.sss.presentation.noui.api.response.ResultUtil;
import org.sss.presentation.noui.common.Constants; import org.sss.presentation.noui.common.Constants;
...@@ -45,6 +47,9 @@ public abstract class AbstractCommonController { ...@@ -45,6 +47,9 @@ public abstract class AbstractCommonController {
protected static String ON_STREAM_UPLOAD = "ON_STREAM_UPLOAD"; protected static String ON_STREAM_UPLOAD = "ON_STREAM_UPLOAD";
protected static String ON_STREAM_DOWNLOAD = "ON_STREAM_DOWNLOAD"; protected static String ON_STREAM_DOWNLOAD = "ON_STREAM_DOWNLOAD";
@Autowired
private NoUiVersion noUiVersion;
public String getMainPanel(){ public String getMainPanel(){
return ""; return "";
} }
...@@ -134,10 +139,10 @@ public abstract class AbstractCommonController { ...@@ -134,10 +139,10 @@ public abstract class AbstractCommonController {
Map<String, Object> afterReturnData = handleReturnData(eventType, context, noUiRequest, alias); Map<String, Object> afterReturnData = handleReturnData(eventType, context, noUiRequest, alias);
ret = ResultUtil.result(NoUiPresentationUtil.retCode(context), NoUiPresentationUtil.retMsg(context), afterReturnData, ret = ResultUtil.result(NoUiPresentationUtil.retCode(context), NoUiPresentationUtil.retMsg(context), afterReturnData,
NoUiPresentationUtil.handleErrorReturnData(context, alias), NoUiPresentationUtil.handleCodeTableReturnData(context, alias)); NoUiPresentationUtil.handleErrorReturnData(context, alias), NoUiPresentationUtil.handleCodeTableReturnData(context, alias),noUiVersion.getVersion());
} catch (Exception e) { } catch (Exception e) {
log.error("OnClick command error", e); log.error("OnClick command error", e);
ret = ResultUtil.result(ErrorCodes.ERROR, "hander error", e.getMessage()); ret = ResultUtil.result(ErrorCodes.ERROR, "hander error", e.getMessage(),noUiVersion.getVersion());
} finally { } finally {
if (context != null) if (context != null)
{ {
......
...@@ -8,6 +8,7 @@ import javax.servlet.http.HttpSession; ...@@ -8,6 +8,7 @@ import javax.servlet.http.HttpSession;
import log.Log; import log.Log;
import log.LogFactory; import log.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
...@@ -20,6 +21,7 @@ import org.sss.presentation.noui.api.model.Menu; ...@@ -20,6 +21,7 @@ import org.sss.presentation.noui.api.model.Menu;
import org.sss.presentation.noui.api.request.NoUiRequest; import org.sss.presentation.noui.api.request.NoUiRequest;
import org.sss.presentation.noui.api.response.ErrorCode; import org.sss.presentation.noui.api.response.ErrorCode;
import org.sss.presentation.noui.api.response.ErrorCodes; import org.sss.presentation.noui.api.response.ErrorCodes;
import org.sss.presentation.noui.api.response.NoUiVersion;
import org.sss.presentation.noui.api.response.ResultUtil; import org.sss.presentation.noui.api.response.ResultUtil;
import org.sss.presentation.noui.common.Constants; import org.sss.presentation.noui.common.Constants;
import org.sss.presentation.noui.context.NoUiContext; import org.sss.presentation.noui.context.NoUiContext;
...@@ -37,6 +39,9 @@ public class LoginController { ...@@ -37,6 +39,9 @@ public class LoginController {
private static final Log log = LogFactory.getLog(LoginController.class); private static final Log log = LogFactory.getLog(LoginController.class);
public static final String ERROR="error"; public static final String ERROR="error";
@Autowired
private NoUiVersion noUiVersion;
@ResponseBody @ResponseBody
@RequestMapping(value = "/login", method = RequestMethod.POST) @RequestMapping(value = "/login", method = RequestMethod.POST)
public Object login(@RequestBody Map<String, Object> dataMap, HttpServletRequest request, HttpSession session) { public Object login(@RequestBody Map<String, Object> dataMap, HttpServletRequest request, HttpSession session) {
...@@ -84,22 +89,22 @@ public class LoginController { ...@@ -84,22 +89,22 @@ public class LoginController {
//解决初次登陆,超期限登陆 //解决初次登陆,超期限登陆
final Object o = map.get(ERROR); final Object o = map.get(ERROR);
if (Objects.isNull(o)) { if (Objects.isNull(o)) {
return ResultUtil.result(ErrorCodes.SUCCESS, ErrorCodes.SUCCESS_INFO, retDatamap); return ResultUtil.result(ErrorCodes.SUCCESS, ErrorCodes.SUCCESS_INFO, retDatamap,noUiVersion.getVersion());
}else { }else {
ErrorCode errorCode = (ErrorCode) o; ErrorCode errorCode = (ErrorCode) o;
log.error(errorCode); log.error(errorCode);
return ResultUtil.result(errorCode.getCode(), errorCode.getMessage(), retDatamap); return ResultUtil.result(errorCode.getCode(), errorCode.getMessage(), retDatamap,noUiVersion.getVersion());
} }
}else { }else {
final ErrorCode errorCode = (ErrorCode) map.get(ERROR); final ErrorCode errorCode = (ErrorCode) map.get(ERROR);
log.error(errorCode); log.error(errorCode);
return ResultUtil.result(errorCode.getCode(), errorCode.getMessage(), null); return ResultUtil.result(errorCode.getCode(), errorCode.getMessage(), null,noUiVersion.getVersion());
} }
} catch (Exception e) { } catch (Exception e) {
log.error("Login command error", e); log.error("Login command error", e);
//throw new NoUiException("Login command error", e); //throw new NoUiException("Login command error", e);
// return ResultUtil.result(ErrorCodes.ERROR, "login failed with exception", null); // return ResultUtil.result(ErrorCodes.ERROR, "login failed with exception", null);
return ResultUtil.result(ErrorCode.SYSTEM_ERROR.getCode(), ErrorCode.SYSTEM_ERROR.getMessage(), null); return ResultUtil.result(ErrorCode.SYSTEM_ERROR.getCode(), ErrorCode.SYSTEM_ERROR.getMessage(), null,noUiVersion.getVersion());
} }
finally{ finally{
if (context != null) if (context != null)
......
...@@ -2,10 +2,12 @@ package org.sss.presentation.noui.filter; ...@@ -2,10 +2,12 @@ package org.sss.presentation.noui.filter;
import com.google.gson.Gson; import com.google.gson.Gson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest; import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import org.sss.presentation.noui.api.response.ErrorCodes; import org.sss.presentation.noui.api.response.ErrorCodes;
import org.sss.presentation.noui.api.response.NoUiVersion;
import org.sss.presentation.noui.api.response.Result; import org.sss.presentation.noui.api.response.Result;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
...@@ -19,6 +21,9 @@ import java.util.Map; ...@@ -19,6 +21,9 @@ import java.util.Map;
*/ */
public class FileTypeInterceptor extends HandlerInterceptorAdapter { public class FileTypeInterceptor extends HandlerInterceptorAdapter {
@Autowired
private NoUiVersion noUiVersion;
private String type_list; private String type_list;
@Override @Override
...@@ -39,7 +44,7 @@ public class FileTypeInterceptor extends HandlerInterceptorAdapter { ...@@ -39,7 +44,7 @@ public class FileTypeInterceptor extends HandlerInterceptorAdapter {
//限制文件类型,请求转发到原始请求页面,并携带错误提示信息 //限制文件类型,请求转发到原始请求页面,并携带错误提示信息
flag = false; flag = false;
response.setContentType("application/json; charset=utf-8"); response.setContentType("application/json; charset=utf-8");
Result result = new Result(ErrorCodes.ERROR, "不支持的文件类型!", null); Result result = new Result(ErrorCodes.ERROR, "不支持的文件类型!", null,noUiVersion.getVersion());
PrintWriter out = response.getWriter(); PrintWriter out = response.getWriter();
String json = new Gson().toJson(result); String json = new Gson().toJson(result);
out.print(json); out.print(json);
......
...@@ -6,10 +6,12 @@ import javax.servlet.http.HttpServletRequest; ...@@ -6,10 +6,12 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.HandlerInterceptor; import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import org.sss.presentation.noui.api.request.NoUiRequest; import org.sss.presentation.noui.api.request.NoUiRequest;
import org.sss.presentation.noui.api.response.ErrorCodes; import org.sss.presentation.noui.api.response.ErrorCodes;
import org.sss.presentation.noui.api.response.NoUiVersion;
import org.sss.presentation.noui.api.response.Result; import org.sss.presentation.noui.api.response.Result;
import org.sss.presentation.noui.common.Constants; import org.sss.presentation.noui.common.Constants;
import org.sss.presentation.noui.context.NoUiContextManager; import org.sss.presentation.noui.context.NoUiContextManager;
...@@ -26,6 +28,9 @@ import log.LogFactory; ...@@ -26,6 +28,9 @@ import log.LogFactory;
public class OpenTransInterceptor implements HandlerInterceptor { public class OpenTransInterceptor implements HandlerInterceptor {
protected static final Log log = LogFactory.getLog(OpenTransInterceptor.class); protected static final Log log = LogFactory.getLog(OpenTransInterceptor.class);
@Autowired
private NoUiVersion noUiVersion;
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception arg3) throws Exception { public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception arg3) throws Exception {
...@@ -62,7 +67,7 @@ public class OpenTransInterceptor implements HandlerInterceptor { ...@@ -62,7 +67,7 @@ public class OpenTransInterceptor implements HandlerInterceptor {
trnnam = url.substring(begpos, idx2); trnnam = url.substring(begpos, idx2);
if(trnnam==null) if(trnnam==null)
{ {
Result rt = new Result(ErrorCodes.UNKNOEW_TRANS, "未知的交易", null); Result rt = new Result(ErrorCodes.UNKNOEW_TRANS, "未知的交易", null,noUiVersion.getVersion());
responseMessage(response, response.getWriter(), rt); responseMessage(response, response.getWriter(), rt);
return false; return false;
} }
...@@ -70,7 +75,7 @@ public class OpenTransInterceptor implements HandlerInterceptor { ...@@ -70,7 +75,7 @@ public class OpenTransInterceptor implements HandlerInterceptor {
log.debug("开放访问交易名:"+trnnam); log.debug("开放访问交易名:"+trnnam);
if(!NoUiContextManager.openTransactions.contains(trnnam)) if(!NoUiContextManager.openTransactions.contains(trnnam))
{ {
Result rt = new Result(ErrorCodes.FORBIDDEN_TRANS, "非法访问", null); Result rt = new Result(ErrorCodes.FORBIDDEN_TRANS, "非法访问", null,noUiVersion.getVersion());
responseMessage(response, response.getWriter(), rt); responseMessage(response, response.getWriter(), rt);
return false; return false;
} }
......
...@@ -5,10 +5,12 @@ import java.io.PrintWriter; ...@@ -5,10 +5,12 @@ import java.io.PrintWriter;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.HandlerInterceptor; import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import org.sss.presentation.noui.api.request.NoUiRequest; import org.sss.presentation.noui.api.request.NoUiRequest;
import org.sss.presentation.noui.api.response.ErrorCodes; import org.sss.presentation.noui.api.response.ErrorCodes;
import org.sss.presentation.noui.api.response.NoUiVersion;
import org.sss.presentation.noui.api.response.Result; import org.sss.presentation.noui.api.response.Result;
import org.sss.presentation.noui.common.Constants; import org.sss.presentation.noui.common.Constants;
import org.sss.presentation.noui.util.NumericUtil; import org.sss.presentation.noui.util.NumericUtil;
...@@ -19,6 +21,9 @@ import com.google.gson.Gson; ...@@ -19,6 +21,9 @@ import com.google.gson.Gson;
public class TokenInterceptor implements HandlerInterceptor { public class TokenInterceptor implements HandlerInterceptor {
@Autowired
private NoUiVersion noUiVersion;
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception arg3) throws Exception { public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception arg3) throws Exception {
} }
...@@ -35,14 +40,14 @@ public class TokenInterceptor implements HandlerInterceptor { ...@@ -35,14 +40,14 @@ public class TokenInterceptor implements HandlerInterceptor {
String terminalType = noUiRequest.getTerminalType(); // APP WEB String terminalType = noUiRequest.getTerminalType(); // APP WEB
// token不存在 // token不存在
if (StringUtil.isEmpty(token)) { if (StringUtil.isEmpty(token)) {
Result rt = new Result(ErrorCodes.LOGIN_TOKEN_ISNULL, "登录token不能为空", null); Result rt = new Result(ErrorCodes.LOGIN_TOKEN_ISNULL, "登录token不能为空", null,noUiVersion.getVersion());
responseMessage(response, response.getWriter(), rt); responseMessage(response, response.getWriter(), rt);
return false; return false;
} }
// userId不存在 // userId不存在
if (StringUtil.isEmpty(userId)) { if (StringUtil.isEmpty(userId)) {
Result rt = new Result(ErrorCodes.LOGIN_ID_ISNULL, "用户id不能为空", null); Result rt = new Result(ErrorCodes.LOGIN_ID_ISNULL, "用户id不能为空", null,noUiVersion.getVersion());
responseMessage(response, response.getWriter(), rt); responseMessage(response, response.getWriter(), rt);
return false; return false;
} }
...@@ -55,20 +60,20 @@ public class TokenInterceptor implements HandlerInterceptor { ...@@ -55,20 +60,20 @@ public class TokenInterceptor implements HandlerInterceptor {
JwtLogin login = JWT.unsign(token, JwtLogin.class); JwtLogin login = JWT.unsign(token, JwtLogin.class);
if (login == null || (!userId.equals((login.getUserId())))) { if (login == null || (!userId.equals((login.getUserId())))) {
Result rt = new Result(ErrorCodes.LOGIN_TOKEN_CHECKERROR, "用户token或ID验证不通过", null); Result rt = new Result(ErrorCodes.LOGIN_TOKEN_CHECKERROR, "用户token或ID验证不通过", null,noUiVersion.getVersion());
responseMessage(response, response.getWriter(), rt); responseMessage(response, response.getWriter(), rt);
return false; return false;
} }
RedisLoginInfo redisLoginInfo = (RedisLoginInfo) RedisUtil.get(StringUtil.userUniqueId(noUiRequest)); RedisLoginInfo redisLoginInfo = (RedisLoginInfo) RedisUtil.get(StringUtil.userUniqueId(noUiRequest));
if (redisLoginInfo == null) { if (redisLoginInfo == null) {
Result rt = new Result(ErrorCodes.LOGIN_ERROR, "登陆异常", null); Result rt = new Result(ErrorCodes.LOGIN_ERROR, "登陆异常", null,noUiVersion.getVersion());
responseMessage(response, response.getWriter(), rt); responseMessage(response, response.getWriter(), rt);
return false; return false;
} }
//验证token是否一致 //验证token是否一致
if(!token.equals(redisLoginInfo.getToken())){ if(!token.equals(redisLoginInfo.getToken())){
Result rt = new Result(ErrorCodes.LOGIN_TOKEN_CHECKERROR, "token失效,该用户被强迫下线", null); Result rt = new Result(ErrorCodes.LOGIN_TOKEN_CHECKERROR, "token失效,该用户被强迫下线", null,noUiVersion.getVersion());
responseMessage(response, response.getWriter(), rt); responseMessage(response, response.getWriter(), rt);
return false; return false;
} }
...@@ -76,7 +81,7 @@ public class TokenInterceptor implements HandlerInterceptor { ...@@ -76,7 +81,7 @@ public class TokenInterceptor implements HandlerInterceptor {
if (System.currentTimeMillis() > redisLoginInfo.getExpiredTime()) { if (System.currentTimeMillis() > redisLoginInfo.getExpiredTime()) {
Result rt = new Result(ErrorCodes.LOGIN_TIMEOUT, "会话超时,请重新登录。超时时间戳:"+redisLoginInfo.getExpiredTime()+ Result rt = new Result(ErrorCodes.LOGIN_TIMEOUT, "会话超时,请重新登录。超时时间戳:"+redisLoginInfo.getExpiredTime()+
",当前时间戳:"+System.currentTimeMillis(), null); ",当前时间戳:"+System.currentTimeMillis(), null,noUiVersion.getVersion());
responseMessage(response, response.getWriter(), rt); responseMessage(response, response.getWriter(), rt);
return false; return false;
} }
......
...@@ -41,6 +41,10 @@ ...@@ -41,6 +41,10 @@
<property name="maxInMemorySize" value="200000" /> <property name="maxInMemorySize" value="200000" />
</bean> </bean>
<bean id="nouiVersion" class="org.sss.presentation.noui.api.response.NoUiVersion">
<property name="version" value="V1.0.0" />
</bean>
<!-- 配置自动扫描的包 --> <!-- 配置自动扫描的包 -->
<context:component-scan base-package="org.sss.presentation.noui.controller"></context:component-scan> <context:component-scan base-package="org.sss.presentation.noui.controller"></context:component-scan>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment