Commit 15e4af32 by WeiCong

Merge remote-tracking branch 'origin/master'

parents 0131a50b a2939fb5
...@@ -29,6 +29,12 @@ ...@@ -29,6 +29,12 @@
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.9.6</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId> <groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId> <artifactId>jackson-databind</artifactId>
<version>2.9.4</version> <version>2.9.4</version>
...@@ -140,11 +146,6 @@ ...@@ -140,11 +146,6 @@
<version>2.5</version> <version>2.5</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>commons-io</groupId> <groupId>commons-io</groupId>
<artifactId>commons-io</artifactId> <artifactId>commons-io</artifactId>
<version>2.5</version> <version>2.5</version>
......
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;
...@@ -27,6 +29,7 @@ import org.sss.presentation.noui.context.NoUiContextManager; ...@@ -27,6 +29,7 @@ import org.sss.presentation.noui.context.NoUiContextManager;
import org.sss.presentation.noui.jwt.JWT; import org.sss.presentation.noui.jwt.JWT;
import org.sss.presentation.noui.jwt.JwtLogin; import org.sss.presentation.noui.jwt.JwtLogin;
import org.sss.presentation.noui.jwt.RedisLoginInfo; import org.sss.presentation.noui.jwt.RedisLoginInfo;
import org.sss.presentation.noui.log.aop.LogAnnotation;
import org.sss.presentation.noui.util.NoUiPresentationUtil; import org.sss.presentation.noui.util.NoUiPresentationUtil;
import org.sss.presentation.noui.util.NumericUtil; import org.sss.presentation.noui.util.NumericUtil;
import org.sss.presentation.noui.util.RedisUtil; import org.sss.presentation.noui.util.RedisUtil;
...@@ -37,6 +40,10 @@ public class LoginController { ...@@ -37,6 +40,10 @@ 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;
@LogAnnotation
@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 +91,22 @@ public class LoginController { ...@@ -84,22 +91,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;
...@@ -27,6 +29,9 @@ import log.LogFactory; ...@@ -27,6 +29,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;
} }
......
package org.sss.presentation.noui.log;
import org.apache.log4j.AppenderSkeleton;
import org.apache.log4j.Layout;
import org.apache.log4j.MDC;
import org.apache.log4j.PatternLayout;
import org.apache.log4j.spi.LoggingEvent;
import org.sss.presentation.noui.common.Constants;
import org.sss.presentation.noui.log.aop.LogAop;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class SqlLogAppender extends AppenderSkeleton {
private PatternLayout patternLayout;
// protected String pattern;
protected static Map<String, List> map = new ConcurrentHashMap();
public Map<String,List> getMap(){
return map;
}
// public String getPattern() {
// return pattern;
// }
//
// public void setPattern(String pattern) {
// this.pattern = pattern;
// }
public PatternLayout getPatternLayout() {
return patternLayout;
}
public void setPatternLayout(PatternLayout patternLayout) {
this.patternLayout = patternLayout;
}
@Override
protected void append(LoggingEvent loggingEvent) {
String message = this.subAppend(loggingEvent);
String thread_name = (String) MDC.get(LogAop.THREAD_NAME);
if(thread_name == null)return;
if(map.containsKey(thread_name)){
map.get(thread_name).add(message);
}else{
List list = new ArrayList();
list.add(message);
map.put(thread_name,list);
}
}
public String subAppend(LoggingEvent event) {
// PatternLayout patternLayout = new PatternLayout();
// patternLayout.setConversionPattern(pattern);
// setLayout(patternLayout);
String result;
if(layout ==null){
result = event.getRenderedMessage();
}else{
result = layout.format(event);
StringBuffer buffer = new StringBuffer(result);
if(layout.ignoresThrowable()) {
String[] s = event.getThrowableStrRep();
if(s != null) {
int len = s.length;
for(int i = 0; i < len; ++i) {
buffer.append(s[i]);
buffer.append(Layout.LINE_SEP);
}
}
}
result = new String(buffer);
}
return result;
}
@Override
public void close() {
}
@Override
public boolean requiresLayout() {
return false;
}
}
package org.sss.presentation.noui.log.aop;
import java.lang.annotation.*;
/**
* Created by cjh on 2019/12/12 0012.
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface LogAnnotation {
}
package org.sss.presentation.noui.log.aop;
import org.apache.log4j.Logger;
import org.apache.log4j.MDC;
import org.aspectj.lang.JoinPoint;
import org.sss.presentation.noui.log.SqlLogAppender;
import java.util.List;
import java.util.Map;
public class LogAop {
public final static String THREAD_NAME = "thread_name";
public void before(JoinPoint joinPoint){
MDC.put(THREAD_NAME,Thread.currentThread().getName());
}
public void after(JoinPoint joinPoint){
String thread_name = (String) MDC.get(THREAD_NAME);
MDC.clear();
//发送每笔交易的日志到MQ
SqlLogAppender sqlLogAppender = (SqlLogAppender) Logger.getRootLogger().getAppender("SqlLog");
if(sqlLogAppender != null){
Map<String, List> map = sqlLogAppender.getMap();
List<String> list = map.get(thread_name);
StringBuffer buffer = new StringBuffer();
if(list != null){
for(String str:list){
buffer.append(str);
}
}
map.remove(thread_name);
}
}
}
...@@ -2,44 +2,48 @@ ...@@ -2,44 +2,48 @@
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false"> <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
<appender name="FILE" class="org.apache.log4j.DailyRollingFileAppender"> <appender name="FILE" class="org.apache.log4j.DailyRollingFileAppender">
<param name="Threshold" value="ERROR" /> <param name="Threshold" value="ERROR"/>
<param name="Encoding" value="UTF-8" /> <param name="Encoding" value="UTF-8"/>
<param name="File" value="../logs/eibs.log" /> <param name="File" value="../logs/eibs.log"/>
<param name="Append" value="true" /> <param name="Append" value="true"/>
<param name="DatePattern" value="'.'yyyy-MM-dd" /> <param name="DatePattern" value="'.'yyyy-MM-dd"/>
<layout class="org.apache.log4j.PatternLayout"> <layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" /> <param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n"/>
</layout> </layout>
<filter class="log.PatternFilter" >
<param name="Pattern" value="org.sss.*" />
<param name="AcceptOnMatch" value="true" />
</filter>
</appender> </appender>
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender"> <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
<param name="Threshold" value="TRACE" /> <param name="Threshold" value="TRACE"/>
<layout class="org.apache.log4j.PatternLayout"> <layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%-10t][%c{1}] %m%n" /> <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%-10t][%c{1}] %m%n"/>
</layout> </layout>
<filter class="org.apache.log4j.varia.LevelRangeFilter"> <filter class="org.apache.log4j.varia.LevelRangeFilter">
<param name="LevelMax" value="ERROR" /> <param name="LevelMax" value="ERROR"/>
<param name="LevelMin" value="TRACE" /> <param name="LevelMin" value="TRACE"/>
</filter> </filter>
</appender> </appender>
<appender name="SqlLog" class="org.sss.presentation.noui.log.SqlLogAppender">
<param name="Threshold" value="ERROR"/>
<layout class="org.apache.log4j.PatternLayout" >
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n"/>
</layout>
</appender>
<category name="org.sss"> <category name="org.sss">
<priority value="INFO" /> <priority value="INFO"/>
</category> </category>
<category name="org.hibernate"> <category name="org.hibernate">
<priority value="ERROR" /> <priority value="ERROR"/>
</category> </category>
<category name="org.apache"> <category name="org.apache">
<priority value="ERROR" /> <priority value="ERROR"/>
</category> </category>
<category name="com.opensymphony"> <category name="com.opensymphony">
<priority value="ERROR" /> <priority value="ERROR"/>
</category> </category>
<root> <root>
<level value="WARN" /> <level value="WARN"/>
<appender-ref ref="CONSOLE" /> <appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE" /> <appender-ref ref="FILE"/>
<appender-ref ref="SqlLog"/>
</root> </root>
</log4j:configuration> </log4j:configuration>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
<File name="File" fileName="log/eibs-designer.log">
<PatternLayout pattern="%d %-5p %C{2} [%t] %m%n"/>
</File>
</Appenders>
<Loggers>
<Logger name="org.sss" level="DEBUG"/>
<Logger name="org.hibernate" level="ERROR"/>
<Logger name="org.apache" level="ERROR"/>
<Logger name="com.opensymphony" level="ERROR"/>
<Root level="DEBUG">
<AppenderRef ref="Console"/>
<AppenderRef ref="File"/>
</Root>
</Loggers>
</Configuration>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" <beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd"> http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
<mvc:annotation-driven /> <mvc:annotation-driven />
...@@ -41,6 +42,19 @@ ...@@ -41,6 +42,19 @@
<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>
<bean id="logAop" class="org.sss.presentation.noui.log.aop.LogAop" />
<aop:config>
<aop:aspect id="handler" ref="logAop">
<aop:pointcut id="point" expression="execution(* org.sss.presentation.noui.controller..*(..)) &amp;&amp; @annotation(org.sss.presentation.noui.log.aop.LogAnnotation)" />
<aop:before method="before" pointcut-ref="point" />
<aop:after method="after" pointcut-ref="point" />
</aop:aspect>
</aop:config>
<!-- 配置自动扫描的包 --> <!-- 配置自动扫描的包 -->
<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