no message

main
이범준 1 year ago
parent 26851e46d0
commit 9f5d1e5450

@ -1,196 +0,0 @@
package cokr.xit.fims.framework.core.aop;
import cokr.xit.fims.framework.support.mybatis.PagingConstants;
import cokr.xit.fims.framework.support.mybatis.paging.domain.Paginator;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.ui.Model;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Slf4j
@Component
@Aspect
public class LogAopAdvice {
private boolean isRsltLog = true;
@Pointcut("execution(public * cokr.xit..web.*.*(..))")
public void pointCut() {}
// @Before("pointCut()")
// public void beforeProcess(JoinPoint joinPoint) {
// MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
// Method method = methodSignature.getMethod();
// Object[] objs = joinPoint.getArgs();
// log.info("Start-{} ", methodSignature.getDeclaringTypeName() + "." + method.getName());
// log.info("Request Param : {} ", objs);
// }
//
// @AfterReturning(value = "pointCut()", returning = "returnValue")
// public void afterReturning(JoinPoint joinPoint, Object returnValue) {
// MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
// Method method = methodSignature.getMethod();
// log.info("End-{} ", methodSignature.getDeclaringTypeName() + "." + method.getName());
// log.info("Response Param : {} ", returnValue);
// }
@Around("pointCut()")
public Object aroundProceed(ProceedingJoinPoint pjp) throws Throwable {
//StopWatch sw = new StopWatch();//
// sw.start(methodName);
// Parameter log
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) requestAttributes;
HttpServletRequest request = servletRequestAttributes.getRequest();
//Object[] args = pjp.getArgs();
requestLog(request);
//TODO 필요시 insert log
//logInsert(methodName, request, paraMap+"");
Object rtnObj = pjp.proceed();
//sw.stop();
if(isRsltLog) {
StringBuilder sb = new StringBuilder();
sb.append("//==============================Result====================================").append("\n");
sb.append("Execution : ").append(pjp.getSignature()).append("\n");
sb.append("return : ").append(rtnObj).append("\n");
sb.append("=========================================================================//");
log.debug(sb.toString());
}else {
// log.info("실행시간 : {}", sw.getTotalTimeSeconds());
}
Object pageObject = RequestContextHolder.getRequestAttributes().getAttribute(PagingConstants.Session.PAGE_INFO.getCode(), RequestAttributes.SCOPE_REQUEST);
if(pageObject != null && rtnObj != null){
Paginator paginator = (Paginator)pageObject;
log.debug("###################################{}",rtnObj.getClass());
//if(rtnObj instanceof Map){
if(Map.class.isAssignableFrom(rtnObj.getClass())){
Map map = (Map)rtnObj;
map.putAll(getPageInfoMap(paginator));
return map;
//}else if(rtnObj instanceof List){
}else if(List.class.isAssignableFrom(rtnObj.getClass())){
Map<String,Object> map = new HashMap<String,Object>();
map.put("rows", rtnObj);
map.putAll(getPageInfoMap(paginator));
return map;
}else if(ModelAndView.class.isAssignableFrom(rtnObj.getClass())){
ModelAndView mav = (ModelAndView)rtnObj;
((Map)mav.getModelMap().get("data")).put("pagination", getPageInfoMap(paginator));
return mav;
}else if(Model.class.isAssignableFrom(rtnObj.getClass())){
Model mav = (Model)rtnObj;
mav.addAttribute("pagination", getPageInfoMap(paginator));
return mav;
}else if(String.class.isAssignableFrom(rtnObj.getClass())){
//String jsonObj = (String)rtnObj;
return rtnObj;
}else{
throw new IllegalArgumentException("Paging works Illegal argument type, must be : ModelAndView, Map, List:" + rtnObj.getClass());
}
}
//TODO update Log
//update(rtnObj);
// sw.stop();
// log.info(sw.prettyPrint());
return rtnObj;
}
@AfterThrowing(pointcut="execution(public * cokr.xit.fims.framework..*.*(..))||execution(public * cokr.xit.fims..*.*(..))", throwing="error")
public void afterThrowingProceed(JoinPoint jp, Throwable error) {
error.printStackTrace();
log.error("@@@(THROWS) Method called: {}", jp.getSignature());
if(jp.getArgs().length ==0 ) log.error("@@@@(THROWS) No arguments passed.");
for(Object arg:jp.getArgs()) log.error("@@@@(THROWS) Argument passed:{}", arg);
log.error("@@@(THORWS) getMessage: {}", error.getMessage());
log.error("@@@(THORWS) getCause: {}", error.getCause());
}
private void requestLog(HttpServletRequest request) {
if (log.isDebugEnabled()) {
String method = request.getMethod();
StringBuilder sb = new StringBuilder("\n");
sb.append("//=========================================================================\n");
//sb.append("Ajax Call : " + "XMLHttpRequest".equals(request.getHeader(Globals.AJAX_HEADER))).append("\n");
sb.append("URI : " + request.getRequestURI()).append("\n");
sb.append("URL : " + request.getRequestURL()).append("\n");
sb.append("IP : " + request.getRemoteAddr()).append("\n");
sb.append("Referer URI : " + request.getHeader("referer")).append("\n");
sb.append("Method : " + request.getMethod()).append("\n");
sb.append("User Agent : " + request.getHeader("User-Agent")).append("\n");
sb.append("Session : " + request.getSession().getId()).append("\n");
sb.append("Locale : " + request.getLocale().getCountry()).append("\n");
sb.append("ContentType : " + request.getContentType()).append("\n");
sb.append("----- Parameters ----- \n");
Enumeration<?> e = request.getParameterNames();
if (e.hasMoreElements()) {
String pName = "";
String pValue = "";
do {
pName = (String) e.nextElement();
pValue = request.getParameter(pName);
sb.append(pName + ": " + pValue + "\n");
} while (e.hasMoreElements());
} else {
sb.append(" is Empty \n");
}
sb.append("=========================================================================//");
log.debug(sb.toString());
sb = null;
}
}
private Map<String,Object> getPageInfoMap(Paginator paginator){
Map<String, Object> map = new HashMap<String, Object>();
map.put("totalPage", paginator.getTotalPages());
map.put("totalSize", paginator.getTotalSize());
map.put("pageNum", paginator.getPageNum());
//
// // Query Data : Paging 정보만 set 하면 되므로 필요 없다
// //map.put(FwConstants.DEFAULT_RESPONSE_BODY_DATA_NAME, new ArrayList<PageList>(pageList));
// map.put("startRow", paginator.getStartRow());
// map.put("endRow", paginator.getEndRow());
// map.put("offset", paginator.getOffset());
// //map.put("slider", paginator.getSlider());
// map.put("prePage", paginator.getPrePage());
// map.put("nextPage", paginator.getNextPage());
// map.put("firstPage", paginator.isFirstPage());
// map.put("hasNextPage", paginator.isHasNextPage());
// map.put("hasPrePage", paginator.isHasPrePage());
// map.put("lastPage", paginator.isLastPage());
return map;
}
}

@ -1,119 +0,0 @@
package cokr.xit.fims.framework.core.aop;
import cokr.xit.fims.framework.biz.cmm.XitConectLogVO;
import cokr.xit.fims.framework.biz.cmm.XitLoginVO;
import cokr.xit.fims.framework.biz.cmm.service.XitFrameCrudService;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
import cokr.xit.fims.framework.core.utils.XitCmmnUtil;
import cokr.xit.fims.framework.core.utils.XitHttpRequestHelper;
import org.egovframe.rte.fdl.cmmn.exception.FdlException;
import org.egovframe.rte.fdl.security.userdetails.util.EgovUserDetailsHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
/**
*
* @:
* @: / .
* @: 2020. 5. 6. 4:32:05
* @:
* @author ()
* @since 2002. 2. 2.
* @version 1.0 Copyright(c) XIT All rights reserved.
*/
public class XitLoginLogAspect {
@Resource
private XitFrameCrudService xitFrameCrudService;
/**
* <pre> : . </pre>
* void
* @author:
* @date: 2020. 5. 6.
*/
public void addLogLogin() throws Throwable {
String uniqId = "";
String ip = "";
/**
*
*/
Boolean isAuthenticated = EgovUserDetailsHelper.isAuthenticated();
if(isAuthenticated) {
XitLoginVO user = (XitLoginVO)EgovUserDetailsHelper.getAuthenticatedUser();
uniqId = user.getUniqId();
// ip = user.getIp();
HttpServletRequest request = XitHttpRequestHelper.getCurrentRequest();
ip = XitCmmnUtil.getClientIpAddr(request);
}
// XitLoginVO user = XitCmmnUtil.getSession(req);
// uniqId = user.getUniqId();
// ip = user.getIp();
/**
*
*/
XitConectLogVO vo = new XitConectLogVO();
vo.setLogId("nextstringid");
vo.setConectId(uniqId);
vo.setConectIp(ip);
vo.setConectMthd("I"); // 로그인:I, 로그아웃:O
vo.setErrorOccrrncYn("N");
vo.setErrorCode("");
/**
*
*/
xitFrameCrudService.addXitConectLog(vo);
}
/**
* <pre> : .</pre>
* void
* @author:
* @date: 2020. 5. 6.
*/
public void addLogLogout() throws Throwable {
String uniqId = "";
String ip = "";
/**
*
*/
Boolean isAuthenticated = EgovUserDetailsHelper.isAuthenticated();
if(isAuthenticated) {
XitLoginVO user = (XitLoginVO)EgovUserDetailsHelper.getAuthenticatedUser();
uniqId = user.getUniqId();
// ip = user.getIp();
HttpServletRequest request = XitHttpRequestHelper.getCurrentRequest();
ip = XitCmmnUtil.getClientIpAddr(request);
}
/**
*
*/
XitConectLogVO vo = new XitConectLogVO();
vo.setLogId("nextstringid");
vo.setConectId(uniqId);
vo.setConectIp(ip);
vo.setConectMthd("O"); // 로그인:I, 로그아웃:O
vo.setErrorOccrrncYn("N");
vo.setErrorCode("");
/**
*
*/
xitFrameCrudService.addXitConectLog(vo);
}
}
Loading…
Cancel
Save