Merge branch 'hylee'
This commit is contained in:
commit
6760736a71
@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import com.itn.mjonApi.cmn.idgen.service.IdgenService;
|
||||
import com.itn.mjonApi.cmn.msg.RestResponse;
|
||||
import com.itn.mjonApi.mjon.api.access.mapper.domain.AccessKeyVO;
|
||||
import com.itn.mjonApi.mjon.log.service.mapper.LettnAccessLogMapper;
|
||||
import com.itn.mjonApi.mjon.log.service.mapper.domain.LettnAccessLogVO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -20,8 +21,6 @@ import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* packageName : com.itn.mjonApi.cmn.aop
|
||||
@ -110,7 +109,6 @@ public class LogAspect {
|
||||
String resutlCode = "";
|
||||
// HttpServletRequest 객체를 가져옴
|
||||
HttpServletRequest request = this.getHttpServletRequest();
|
||||
|
||||
// @Befer에서 저장한 logId를 가져옴
|
||||
String logId = (String) request.getAttribute("logId");
|
||||
|
||||
@ -119,61 +117,38 @@ public class LogAspect {
|
||||
LettnAccessLogVO lettnAccessLogVO = new LettnAccessLogVO()
|
||||
.builder()
|
||||
.logId(logId)
|
||||
.resCn(this.mapToJson(this.getStringObjectMap(returnValue)))
|
||||
// .resCn(this.getJsonToString(returnValue))
|
||||
.resCn(this.getJsonToString(returnValue))
|
||||
.resCode(resutlCode)
|
||||
.build();
|
||||
lettnAccessLogMapper.update(lettnAccessLogVO);
|
||||
}
|
||||
|
||||
|
||||
private Map<String, Object> getStringObjectMap(Object returnValue) throws IllegalAccessException {
|
||||
Map<String, Object> returnMap = new HashMap<String, Object>();
|
||||
Map<String, Object> dataMap = new HashMap<String, Object>();
|
||||
String val = "";
|
||||
|
||||
|
||||
// for(Field field : returnValue.getClass().getDeclaredFields()){
|
||||
// field.setAccessible(true);
|
||||
//
|
||||
// if("data".equals(field.getName()))
|
||||
// {
|
||||
// Object dataObj = field.get(returnValue);
|
||||
// for(Field dataF : dataObj.getClass().getDeclaredFields()){
|
||||
// dataF.setAccessible(true);
|
||||
// log.info("dataF.getName() :: [{}]", dataF.getName());
|
||||
// log.info("dataF.get(dataObj) :: [{}]", dataF.get(dataObj));
|
||||
// dataMap.put(dataF.getName(), this.getValChk(dataF.get(dataObj)));
|
||||
// }
|
||||
//
|
||||
// returnMap.put(field.getName(), dataMap);
|
||||
// continue;
|
||||
//
|
||||
// }
|
||||
// //field.get(returnValue) null check
|
||||
// returnMap.put(field.getName(), this.getValChk(field.get(returnValue)));
|
||||
// }
|
||||
return returnMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : field.get(returnValue) null check
|
||||
* null 이면 nullPointException 발생
|
||||
* @param returnValue
|
||||
* @description object의 맞는 Class를 찾아서 맵핑
|
||||
* @return
|
||||
* @throws IllegalAccessException
|
||||
*/
|
||||
private static String getValChk(Object returnValue) {
|
||||
String val;
|
||||
if(returnValue == null) val = "";
|
||||
else val = returnValue.toString();
|
||||
return val;
|
||||
private String getJsonToString(Object returnValue) throws JsonProcessingException {
|
||||
|
||||
String classNmTemp = returnValue.getClass().getName();
|
||||
String classNm = classNmTemp.substring(classNmTemp.lastIndexOf(".")+1, classNmTemp.length());
|
||||
|
||||
/**
|
||||
* @description : return Class가 추가되면 여기에 추가
|
||||
*/
|
||||
if("AccessKeyVO".equals(classNm)){
|
||||
AccessKeyVO accessKeyVO = (AccessKeyVO) returnValue;
|
||||
return this.getAccessKeyVOToJsonString(accessKeyVO);
|
||||
}else{
|
||||
RestResponse restResponse = (RestResponse) returnValue;
|
||||
return this.getRestResponseToJsonString(restResponse);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public String mapToJson(Map<String, Object> map) throws Exception
|
||||
{
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
return mapper.writeValueAsString(map);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @description : VO를 json으로 변환
|
||||
@ -181,11 +156,22 @@ public class LogAspect {
|
||||
* @return String
|
||||
* @throws JsonProcessingException
|
||||
*/
|
||||
private static String getJsonToString(RestResponse restResponse) throws JsonProcessingException {
|
||||
private static String getRestResponseToJsonString(RestResponse restResponse) throws JsonProcessingException {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
// .registerModule(new JavaTimeModule()) : LocalDateTime을 json으로 변환하기 위함
|
||||
return objectMapper.registerModule(new JavaTimeModule()).writeValueAsString(restResponse);
|
||||
}
|
||||
/**
|
||||
* @description : VO를 json으로 변환
|
||||
* @param accessKeyVO
|
||||
* @return String
|
||||
* @throws JsonProcessingException
|
||||
*/
|
||||
private static String getAccessKeyVOToJsonString(AccessKeyVO accessKeyVO) throws JsonProcessingException {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
// .registerModule(new JavaTimeModule()) : LocalDateTime을 json으로 변환하기 위함
|
||||
return objectMapper.registerModule(new JavaTimeModule()).writeValueAsString(accessKeyVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : HttpServletRequest 객체를 가져옴
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
package com.itn.mjonApi.cmn.config;
|
||||
|
||||
import com.itn.mjonApi.cmn.interceptor.CertifInterceptor;
|
||||
import com.itn.mjonApi.cmn.interceptor.SendInterceptor;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
@ -26,10 +25,7 @@ public class WebConfig implements WebMvcConfigurer {
|
||||
public CertifInterceptor certifInterceptor(){
|
||||
return new CertifInterceptor();
|
||||
}
|
||||
@Bean
|
||||
public SendInterceptor sendInterceptor(){
|
||||
return new SendInterceptor();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
|
||||
@ -1,129 +0,0 @@
|
||||
package com.itn.mjonApi.cmn.interceptor;
|
||||
|
||||
//import java.sql.Date;
|
||||
|
||||
import com.itn.mjonApi.cmn.idgen.service.IdgenService;
|
||||
import com.itn.mjonApi.mjon.log.service.LettnAccessLogService;
|
||||
import com.itn.mjonApi.mjon.log.service.mapper.domain.LettnAccessLogVO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* packageName : com.itn.mjonApi.mjon.send.web
|
||||
* fileName : SendRestController
|
||||
* author : hylee
|
||||
* date : 2023-02-15
|
||||
* description :
|
||||
* ===========================================================
|
||||
* DATE AUTHOR NOTE
|
||||
* -----------------------------------------------------------
|
||||
* 2023-02-15 hylee 최초 생성
|
||||
*/
|
||||
//@Component
|
||||
@Slf4j
|
||||
public class SendInterceptor implements HandlerInterceptor{
|
||||
|
||||
|
||||
@Autowired
|
||||
private LettnAccessLogService lettnAccessLogService;
|
||||
|
||||
@Resource(name = "apiAccessLog")
|
||||
private IdgenService idgenApiAccessLogId;
|
||||
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
|
||||
throws Exception {
|
||||
log.debug("=========== SendInterceptor preHandle()============");
|
||||
|
||||
|
||||
|
||||
{
|
||||
try {
|
||||
|
||||
// TODO accessType 구분추가
|
||||
LettnAccessLogVO lettnAccessLogVO = new LettnAccessLogVO()
|
||||
.builder()
|
||||
.logId(idgenApiAccessLogId.getNextStringId())
|
||||
.accessType("K") // key : K , token : T
|
||||
.accessKey(request.getParameter("accessKey"))
|
||||
.reqUserId(request.getParameter("mberId"))
|
||||
.reqCn("문자 전송")
|
||||
.reqInfoRef(request.getParameter("Referer"))
|
||||
.reqUrl(request.getRequestURI())
|
||||
.build();
|
||||
|
||||
//IP 컬럼 길이를 늘려서 비교 조건 제거함 2023-04-05
|
||||
if (lettnAccessLogVO.getReqUrl().length() > 200) { //길이문제로 오류가 발생하는 경우도 처리하도록 수정
|
||||
lettnAccessLogVO.setReqUrl(lettnAccessLogVO.getReqUrl().substring(0, 199));
|
||||
}
|
||||
|
||||
lettnAccessLogService.insert(lettnAccessLogVO);
|
||||
|
||||
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
|
||||
//내부 오류
|
||||
this._jsonResult(response, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
|
||||
ModelAndView modelAndView) throws Exception {
|
||||
// TODO Auto-generated method stub
|
||||
System.out.println("===== SendInterceptor postHandle apikey ==");
|
||||
|
||||
System.out.println("modelAndView.getModel() : "+ modelAndView);
|
||||
|
||||
|
||||
// Get the request returned VO by the controller
|
||||
if(modelAndView != null){
|
||||
Object obj = modelAndView.getModel().get("mjonResponseVO");
|
||||
System.out.println("obj : "+ obj);
|
||||
}
|
||||
// get response getHeaders value
|
||||
System.out.println("response.getHeaderNames() : "+ response.getHeaderNames());
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
|
||||
throws Exception {
|
||||
// TODO Auto-generated method stub
|
||||
System.out.println("===== SendInterceptor afterCompletion apikey ==");
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void _jsonResult(
|
||||
HttpServletResponse p_response
|
||||
, HttpStatus p_HttpStatus
|
||||
) throws Exception{
|
||||
|
||||
p_response.setContentType("application/json");
|
||||
p_response.setCharacterEncoding("UTF-8");
|
||||
p_response.getWriter().write("{\"resultCode\":\""+p_HttpStatus.value()+"\",\"message\":\""+p_HttpStatus.getReasonPhrase()+"\"}");
|
||||
|
||||
//return "{\"resultCode\":\""+p_HttpStatus.value()+"\",\"message\":\""+p_HttpStatus.getReasonPhrase()+"\"}";
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user