Merge remote-tracking branch 'origin/main'

main
kjh 4 months ago
commit b35a4cb851

@ -179,7 +179,7 @@
<dependency>
<groupId>com.github.gavlyukovskiy</groupId>
<artifactId>p6spy-spring-boot-starter</artifactId>
<version>1.8.0</version>
<version>1.8.1</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>com.github.gavlyukovskiy</groupId>-->

@ -0,0 +1,26 @@
// package cokr.xit.ens.biz.traffic.cheonan.signtalk.mapper;
//
// import org.apache.ibatis.annotations.Delete;
// import org.apache.ibatis.annotations.Insert;
// import org.apache.ibatis.annotations.Mapper;
// import org.apache.ibatis.annotations.Param;
// import org.apache.ibatis.annotations.Select;
// import org.apache.ibatis.annotations.Update;
//
// import cokr.xit.ens.biz.traffic.cheonan.signtalk.dto.TcaRlaybsnmManageDTO;
//
// @Mapper
// public interface TcaRlaybsnmManageMapper {
//
// @Select("SELECT * FROM TCA_RLAYBSNM_MANAGE WHERE id = #{id}")
// TcaRlaybsnmManageDTO findById(@Param("id") String id);
//
// @Insert("INSERT INTO TCA_RLAYBSNM_MANAGE (id, ...) VALUES (#{id}, ...)")
// void insert(TcaRlaybsnmManageDTO dto);
//
// @Update("UPDATE TCA_RLAYBSNM_MANAGE SET ... WHERE id = #{id}")
// void update(TcaRlaybsnmManageDTO dto);
//
// @Delete("DELETE FROM TCA_RLAYBSNM_MANAGE WHERE id = #{id}")
// void deleteById(@Param("id") String id);
// }

@ -1,5 +1,14 @@
package cokr.xit.ens.biz.traffic.cheonan.signtalk.service;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import cokr.xit.ens.biz.traffic.cheonan.code.SndngProcessSttusCd;
import cokr.xit.ens.biz.traffic.cheonan.signtalk.domain.TcaElctrnNticSndng;
import cokr.xit.ens.biz.traffic.cheonan.signtalk.domain.repository.TcaElctrnNticSndngRepository;
@ -14,14 +23,6 @@ import cokr.xit.ens.core.utils.CmmnUtil;
import cokr.xit.ens.modules.common.ctgy.intgrnnoti.service.event.IntgrnNotiSendReserveEvent;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Slf4j
@Service
@ -42,10 +43,10 @@ public class TrafficCaSigntalkService {
/**
* (TRAFFIC -> ENS)
*/
@Transactional(readOnly = true)
public EnsResponseVO accept(String elctrnNticSndngId) {
try {
TcaElctrnNticSndng elctrnNticSndng = tcaElctrnNticSndngRepository.findById(elctrnNticSndngId)
.orElseThrow(() -> new EnsException(EnsErrCd.ACPT404, "일치하는 자료가 없습니다."));
if (!SndngProcessSttusCd.accept.equals(elctrnNticSndng.getSndngProcessSttus()))

@ -1,17 +1,17 @@
package cokr.xit.ens.core.aop;
import cokr.xit.ens.core.utils.CmmnUtil;
import cokr.xit.ens.core.monitor.Message;
import lombok.Builder;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import cokr.xit.ens.core.monitor.Message;
import cokr.xit.ens.core.utils.CmmnUtil;
import lombok.Builder;
@Builder
public class AccessErrorMessage implements Message {
private final String ACTIVE_PROFILE;
private final AccessLog accessLog;
private final AccessLogDTO accessLogDTO;
private final String serverUrl;
public String create() {
@ -27,11 +27,11 @@ public class AccessErrorMessage implements Message {
.append("[Occurrence time]: ")
.append(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS")))
.append(System.getProperty("line.separator"))
.append("[Client Ip]: " + accessLog.getIp())
.append("[Client Ip]: " + accessLogDTO.getIp())
.append(System.getProperty("line.separator"))
.append("[Request Url]: " + accessLog.getHttpMethod() + " " + accessLog.getUrl())
.append("[Request Url]: " + accessLogDTO.getHttpMethod() + " " + accessLogDTO.getUrl())
.append(System.getProperty("line.separator"))
.append("[Request Param]: " + accessLog.getParam())
.append("[Request Param]: " + accessLogDTO.getParam())
.append(System.getProperty("line.separator"))
// .append("[Details]: ")
// .append(accessLog.getErrorMsg())
@ -39,7 +39,7 @@ public class AccessErrorMessage implements Message {
.append(System.getProperty("line.separator"))
.append("[StackTrace]:")
.append(System.getProperty("line.separator"))
.append(accessLog.getErrorMsg());
.append(accessLogDTO.getErrorMsg());
return sb.toString();
}

@ -1,15 +1,15 @@
package cokr.xit.ens.core.aop;
import cokr.xit.ens.core.aop.repository.AccessLogRepository;
import cokr.xit.ens.core.exception.EnsException;
import cokr.xit.ens.core.exception.code.EnsErrCd;
import cokr.xit.ens.core.monitor.slack.event.MonitorEvent;
import cokr.xit.ens.core.utils.CmmnUtil;
import cokr.xit.ens.core.utils.JwtUtil;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import java.io.BufferedReader;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
@ -23,14 +23,16 @@ import org.springframework.util.StringUtils;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import cokr.xit.ens.core.exception.EnsException;
import cokr.xit.ens.core.exception.code.EnsErrCd;
import cokr.xit.ens.core.monitor.slack.event.MonitorEvent;
import cokr.xit.ens.core.utils.CmmnUtil;
import cokr.xit.ens.core.utils.JwtUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
/**
* @author ()
@ -51,7 +53,7 @@ public class AccessLogAspect {
@Value("${spring.profiles.active}")
private String ACTIVE_PROFILE;
private final AccessLogRepository accessLogRepository;
private final AccessLogService accessLogService;
private final String ACCESS_TOKEN_NAME = "Authorization";
private final ApplicationEventPublisher applicationEventPublisher;
@ -88,14 +90,12 @@ public class AccessLogAspect {
long start = System.currentTimeMillis();
Object result = null;
AccessLog accessLog = null;
AccessLogDTO accessLogDTO = null;
try {
log.info("[BEFORE] : ...");
accessLog = this.setRequestInfo(request);
accessLogRepository.save(accessLog);
accessLogDTO = this.setRequestInfo(request);
accessLogService.save(accessLogDTO);
if (this.isCertified(request)) {
@ -103,8 +103,8 @@ public class AccessLogAspect {
log.info("[AFTER] : ...");
this.setResponseInfo(accessLog, result);
accessLogRepository.save(accessLog);
this.setResponseInfo(accessLogDTO, result);
accessLogService.save(accessLogDTO);
} else {
@ -117,16 +117,15 @@ public class AccessLogAspect {
log.error(String.format("[NoAuth] : %s => %s", ACCESS_TOKEN_NAME, request.getHeader(ACCESS_TOKEN_NAME)));
accessLog.setResponseNoAuth(msg);
accessLogRepository.save(accessLog);
accessLogDTO.setResponseNoAuth(msg);
accessLogService.save(accessLogDTO);
}
} catch (EnsException e) {
log.error(String.format("[ERROR] : %s", e.getMessage()));
accessLog.setResponseFail(String.format("%s: %s", e.getErrCd(), e.getMessage()));
accessLogRepository.save(accessLog);
accessLogDTO.setResponseFail(String.format("%s: %s", e.getErrCd(), e.getMessage()));
accessLogService.save(accessLogDTO);
if (result == null) {
EnsResponseVO restResponseVO = EnsResponseVO
.errBuilder()
@ -138,8 +137,8 @@ public class AccessLogAspect {
} catch (Exception e) {
log.error(String.format("[%s ERROR] : %s", EnsErrCd.UNKNOWN, e.getMessage()), e);
accessLog.setResponseFail(String.format("%s: %s", EnsErrCd.UNKNOWN, CmmnUtil.printStackTraceToString(e)));
accessLogRepository.save(accessLog);
accessLogDTO.setResponseFail(String.format("%s: %s", EnsErrCd.UNKNOWN, CmmnUtil.printStackTraceToString(e)));
accessLogService.save(accessLogDTO);
if (result == null) {
EnsResponseVO restResponseVO = EnsResponseVO
.errBuilder()
@ -150,7 +149,7 @@ public class AccessLogAspect {
applicationEventPublisher.publishEvent(MonitorEvent.builder()
.message(AccessErrorMessage.builder().ACTIVE_PROFILE(ACTIVE_PROFILE).accessLog(accessLog).serverUrl(CmmnUtil.getServerUrl()).build())
.message(AccessErrorMessage.builder().ACTIVE_PROFILE(ACTIVE_PROFILE).accessLogDTO(accessLogDTO).serverUrl(CmmnUtil.getServerUrl()).build())
.build());
}
@ -174,7 +173,7 @@ public class AccessLogAspect {
* @date: 2021. 11. 30.
*/
@SuppressWarnings("deprecation")
private AccessLog setRequestInfo(HttpServletRequest request) throws JsonProcessingException {
private AccessLogDTO setRequestInfo(HttpServletRequest request) throws JsonProcessingException {
String sessionId = request.getSession().getId();
String param = null;
try {
@ -185,7 +184,7 @@ public class AccessLogAspect {
param = String.format("[요청 parameter 변환 실패]: %s", e.getMessage());
}
return AccessLog.reqBuilder()
return AccessLogDTO.reqBuilder()
.accessToken(request.getHeader(ACCESS_TOKEN_NAME))
.sessionId(sessionId)
.ip(this.getClientIpAddr(request))
@ -199,12 +198,12 @@ public class AccessLogAspect {
/**
* <pre> : </pre>
*
* @param accessLog
* @param accessLogDTO
* @param result
* @author:
* @date: 2021. 11. 30.
*/
private void setResponseInfo(AccessLog accessLog, Object result) {
private void setResponseInfo(AccessLogDTO accessLogDTO, Object result) {
String response = null;
if (result instanceof String)
response = (String) result;
@ -215,7 +214,7 @@ public class AccessLogAspect {
else
response = String.valueOf(result);
accessLog.setResponseCompleted(response);
accessLogDTO.setResponseCompleted(response);
}

@ -1,28 +1,15 @@
package cokr.xit.ens.core.aop;
import cokr.xit.ens.core.aop.code.AccessStatusCd;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;
import javax.persistence.*;
import java.time.LocalDateTime;
@Entity
@Getter
@RequiredArgsConstructor
@Table(name = "ens_access_log", schema = "", catalog = "")
public class AccessLog {
import cokr.xit.ens.core.aop.code.AccessStatusCd;
import lombok.Builder;
import lombok.Data;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Data
public class AccessLogDTO {
private Long logId;
@Column(length = 2000)
private String accessToken;
private String reqSystemId;
@ -37,27 +24,22 @@ public class AccessLog {
private String uri;
@Lob
private String param;
@Lob
private String response;
@Enumerated(EnumType.STRING)
private AccessStatusCd status;
@Lob
private String errorMsg;
@CreationTimestamp
private LocalDateTime startDt;
@UpdateTimestamp
private LocalDateTime endDt;
@Builder(builderClassName = "reqBuilder", builderMethodName = "reqBuilder")
public AccessLog(String accessToken, String sessionId, String ip, String httpMethod, String url, String uri, String param) {
public AccessLogDTO(String accessToken, String sessionId, String ip, String httpMethod, String url, String uri, String param) {
this.accessToken = accessToken;
this.sessionId = sessionId;
this.ip = ip;

@ -0,0 +1,39 @@
package cokr.xit.ens.core.aop;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import cokr.xit.ens.core.aop.mapper.IAccessLogMapper;
import lombok.RequiredArgsConstructor;
/**
* <pre>
* description :
* packageName : cokr.xit.ens.core.aop
* fileName : AccessLogService
* author : limju
* date : 2024-08-01
* ======================================================================
*
* ----------------------------------------------------------------------
* 2024-08-01 limju
*
* </pre>
*/
@Service
@RequiredArgsConstructor
public class AccessLogService {
// private final AccessLogRepository accessLogRepository;
private final IAccessLogMapper accessLogMapper;
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void save(AccessLogDTO accessLogDTO) {
if(ObjectUtils.isEmpty(accessLogDTO.getLogId())) {
accessLogMapper.insertAccessLog(accessLogDTO);
}else{
accessLogMapper.updateAccessLog(accessLogDTO);
}
}
}

@ -0,0 +1,11 @@
package cokr.xit.ens.core.aop.mapper;
import org.apache.ibatis.annotations.Mapper;
import cokr.xit.ens.core.aop.AccessLogDTO;
@Mapper
public interface IAccessLogMapper {
int insertAccessLog(AccessLogDTO accessLogDTO);
int updateAccessLog(AccessLogDTO accessLogDTO);
}

@ -1,8 +0,0 @@
package cokr.xit.ens.core.aop.repository;
import cokr.xit.ens.core.aop.AccessLog;
import org.springframework.data.jpa.repository.JpaRepository;
public interface AccessLogRepository extends JpaRepository<AccessLog, Long>{
}

@ -6,12 +6,17 @@ import org.springframework.context.annotation.Configuration;
@Configuration
public class P6SpyConfig {
@Bean
public P6SpyEventListener p6SpyCustomEventListener() {
return new P6SpyEventListener();
}
@Bean
public P6SpyFormatter p6SpyCustomFormatter() {
return new P6SpyFormatter();
public P6SpyEventListener p6SpyCustomEventListener() {
return new P6SpyEventListener();
}
@Bean
public P6SpyFormatter p6SpyCustomFormatter() {
return new P6SpyFormatter();
}
// @PostConstruct
// public void setLogMessageFormat() {
// P6SpyOptions.getActiveInstance().setLogMessageFormat(P6SpyFormatter.class.getName());
// }
}

@ -17,24 +17,27 @@ public class P6SpyFormatter implements MessageFormattingStrategy {
private static final String ALTER = "alter";
private static final String DROP = "drop";
private static final String COMMENT = "comment";
private static final String COMMIT = "commit";
@Override
public String formatMessage(int connectionId, String now, long elapsed, String category, String prepared, String sql, String url) {
if(category.equals(COMMIT)) return "Connection ID: " + connectionId + " " + COMMIT;
if (sql.trim().isEmpty()) {
return formatByCommand(category);
if (sql == null || sql.trim().isEmpty()) {
return formatByCommand(connectionId, category);
}
return formatBySql(sql, category) + getAdditionalMessages(connectionId, elapsed);
return "\n----------------------------------------------------------------------------------------------------\n"
+ "Execute DML : \n"
+ TAP + TAP
+ sql + ";"
+ getAdditionalMessages(connectionId, elapsed);
//return formatBySql(sql, category) + getAdditionalMessages(connectionId, elapsed);
}
private static String formatByCommand(String category) {
private static String formatByCommand(int connectionId, String category) {
return NEW_LINE
+ "----------------------------------------------------------------------------------------------------\n"
+ "Execute Command : "
+ NEW_LINE
+ NEW_LINE
+ TAP
+ category
+ NEW_LINE
+ category + ", Connection ID - " + connectionId
+ NEW_LINE
+ "----------------------------------------------------------------------------------------------------";
}
@ -48,6 +51,7 @@ public class P6SpyFormatter implements MessageFormattingStrategy {
.format(sql);
}
return NEW_LINE
+ "----------------------------------------------------------------------------------------------------\n"
+ "Execute DML : "
+ NEW_LINE
+ FormatStyle.BASIC
@ -57,7 +61,7 @@ public class P6SpyFormatter implements MessageFormattingStrategy {
private String getAdditionalMessages(int connectionId, long elapsed) {
return NEW_LINE
+ NEW_LINE
+ String.format("Connection ID: %s Execution Time: %s ms", connectionId, elapsed)
+ String.format("Execution Time: %s ms, Connection ID - %s", elapsed, connectionId)
+ NEW_LINE
+ "----------------------------------------------------------------------------------------------------";
}

@ -1,20 +0,0 @@
package cokr.xit.ens.core.config.logging;
import javax.annotation.PostConstruct;
import org.springframework.context.annotation.Configuration;
import com.p6spy.engine.spy.P6SpyOptions;
@Configuration
public class P6spyLoggingConfig {
/**
* JPA SQL Logging
* decorator.datasource.p6spy.enable-logging: true / false
*/
@PostConstruct
public void setLogMessageFormat() {
P6SpyOptions.getActiveInstance().setLogMessageFormat(P6SpyFormatter.class.getName());
}
}

@ -1,18 +1,17 @@
package cokr.xit.ens.modules;
import cokr.xit.ens.core.aop.repository.AccessLogRepository;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import cokr.xit.ens.core.code.CodeMapperFactory;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
@Slf4j
@Controller
@RequiredArgsConstructor
public class IndexController {
private final AccessLogRepository accessLogRepository;
private final CodeMapperFactory codeMapperFactory;
@GetMapping("/")

@ -59,7 +59,7 @@ spring:
jpa:
database-platform: org.hibernate.dialect.MariaDB103Dialect
# show-sql: true
show-sql: true
# generate-ddl: true #TODO: 필요 시 주석해제. generate-ddl를 true 설정 시 ddl-auto의 설정값과 무관하게 DDL 스크립트 실행
hibernate:
ddl-auto: none
@ -68,7 +68,7 @@ spring:
physical-strategy: org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy
properties:
hibernate:
# format_sql: true
format_sql: true
# use_sql_comments: true
order_inserts: true
order_updates: true

@ -15,7 +15,7 @@ logging:
file: utf-8
level:
root: info
'[org.hibernate.type.descriptor.sql]': off #jpa "?" 부분(binding 파라미터) 출력
#'[org.hibernate.type.descriptor.sql]': off #jpa "?" 부분(binding 파라미터) 출력
# '[org.springframework.orm.jpa]': debug
# '[org.springframework.transaction]': debug
# '[org.springframework.transaction.interceptor]': trace

@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cokr.xit.ens.core.aop.mapper.IAccessLogMapper">
<insert id="insertAccessLog" parameterType="cokr.xit.ens.core.aop.AccessLogDTO">
<selectKey keyProperty="logId" resultType="long" order="BEFORE">
SELECT nextval(hibernate_sequence)
</selectKey>
INSERT INTO ens_access_log (
log_id,
access_token,
http_method,
ip,
param,
req_system_id,
session_id,
start_dt,
status,
uri,
url
) VALUES (
#{logId},
#{accessToken},
#{httpMethod},
#{ip},
#{param},
#{reqSystemId},
#{sessionId},
now(),
#{status},
#{uri},
#{url}
)
</insert>
<update id="updateAccessLog" parameterType="cokr.xit.ens.core.aop.AccessLogDTO">
UPDATE ens_access_log
SET end_dt = now()
, status = #{status}
, response = #{response}
WHERE log_id = #{logId}
</update>
</mapper>
Loading…
Cancel
Save