REST Header 로그에 송신 Body 출력할 수 있는 기능 추가
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.eactive.eai.common.logger;
|
||||
|
||||
import com.eactive.eai.common.logger.mapper.HttpAdapterExtraLogMapper;
|
||||
import com.eactive.eai.common.util.Logger;
|
||||
import com.eactive.eai.data.entity.onl.logger.HttpAdapterExtraLog;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -10,7 +11,9 @@ import org.springframework.stereotype.Service;
|
||||
@Service
|
||||
public class HttpLoggingService {
|
||||
|
||||
@Autowired
|
||||
static Logger logger = Logger.getLogger(Logger.LOGGER_DEFAULT);
|
||||
|
||||
@Autowired
|
||||
private HttpAdapterExtraLogMapper mapper;
|
||||
|
||||
@Autowired
|
||||
@@ -24,6 +27,7 @@ public class HttpLoggingService {
|
||||
if (EAIDBLogControl.isEnable()) {
|
||||
try {
|
||||
dbLogger.save(httpAdapterExtraLog);
|
||||
logger.debug("inserted to DB");
|
||||
} catch(Exception e){
|
||||
String message = e.getMessage();
|
||||
// 오류 메시지 추가 - Could not open JPA EntityManager for transaction; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC Connection
|
||||
@@ -33,9 +37,11 @@ public class HttpLoggingService {
|
||||
EAIDBLogControl.setEnable(false);
|
||||
}
|
||||
fileLogger.writeFileLog(httpAdapterExtraLog);
|
||||
logger.debug("wrote to File");
|
||||
}
|
||||
} else {
|
||||
fileLogger.writeFileLog(httpAdapterExtraLog);
|
||||
logger.debug("wrote to File");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,24 +2,25 @@ package com.eactive.eai.common.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.hc.core5.http.Header;
|
||||
|
||||
import com.eactive.eai.common.logger.HttpAdapterExtraHeaderVo;
|
||||
import com.eactive.eai.common.logger.HttpAdapterExtraLogVo;
|
||||
import com.eactive.eai.common.logger.HttpLoggingService;
|
||||
import com.eactive.eai.common.logger.async.AsyncHttpLoggingPoolManager;
|
||||
import com.eactive.eai.env.ElinkConfig;
|
||||
import org.apache.hc.core5.http.Header;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
|
||||
public class HttpAdapterExtraLogUtil {
|
||||
|
||||
public static final int MAX_HEADER_VALUE_SIZE = 400;
|
||||
public static final String BODY_FIELD_NAME = "eapim-adapter-send-body";
|
||||
static Logger logger = Logger.getLogger(Logger.LOGGER_DEFAULT);
|
||||
|
||||
public static boolean isHttpHeaderMode() {
|
||||
@@ -62,14 +63,19 @@ public class HttpAdapterExtraLogUtil {
|
||||
httpAdapterExtraLogVo.setHttpMethod(httpMethod);
|
||||
|
||||
for (HttpAdapterExtraHeaderVo httpAdapterExtraHeaderVo : headerVoList) {
|
||||
|
||||
// String name = httpAdapterExtraHeaderVo.getName();
|
||||
// if(StringUtils.isNotBlank(name) && "authorization".equals(name.toLowerCase())) {
|
||||
// httpAdapterExtraHeaderVo.setValue("{hidden}");
|
||||
// }
|
||||
String value = httpAdapterExtraHeaderVo.getValue();
|
||||
|
||||
if (value == null) {
|
||||
httpAdapterExtraHeaderVo.setValue(" ");
|
||||
}
|
||||
|
||||
if(StringUtils.isNotBlank(value) && value.length() > MAX_HEADER_VALUE_SIZE) {
|
||||
value = value.substring(0, 400) + "...";
|
||||
httpAdapterExtraHeaderVo.setValue(value);
|
||||
}else if(value == null){
|
||||
httpAdapterExtraHeaderVo.setValue(" ");
|
||||
}
|
||||
}
|
||||
|
||||
httpAdapterExtraLogVo.setHeaderList(headerVoList);
|
||||
httpAdapterExtraLogVo.setHttpStatus(httpStatus);
|
||||
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.eactive.eai.common.util;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.eactive.eai.common.property.PropManager;
|
||||
import com.eactive.eai.common.util.HttpAdapterExtraLogUtil;
|
||||
|
||||
public class RestSendBodyLogUtils {
|
||||
|
||||
private static final String PROP_LOG_MAX_DATA_SIZE = "log.max.data.size";
|
||||
private static final String PROP_GROUP = "RestSendBodyLog";
|
||||
|
||||
private RestSendBodyLogUtils() {
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
/**
|
||||
* API ID 별 어댑터 body 로그 남기는 지 여부
|
||||
*
|
||||
* @param apiId
|
||||
* @return
|
||||
*/
|
||||
public static boolean isBodyLoggingApi(String apiId) {
|
||||
if (StringUtils.isEmpty(apiId))
|
||||
return false;
|
||||
|
||||
String logging = PropManager.getInstance().getProperty(PROP_GROUP, apiId, "N");
|
||||
return StringUtils.equals("Y", logging);
|
||||
}
|
||||
|
||||
/**
|
||||
* body 로그에 남길 만큼 자르기
|
||||
*
|
||||
* @param body
|
||||
* @return
|
||||
*/
|
||||
public static String getBodyByMaxSize(String body) {
|
||||
String maxDataSize = PropManager.getInstance().getProperty(PROP_GROUP, PROP_LOG_MAX_DATA_SIZE);
|
||||
int imaxDataSize = HttpAdapterExtraLogUtil.MAX_HEADER_VALUE_SIZE;
|
||||
if (maxDataSize != null)
|
||||
imaxDataSize = Integer.parseInt(maxDataSize);
|
||||
|
||||
if (body.length() > imaxDataSize)
|
||||
return StringUtils.substring(body, 0, imaxDataSize) + "...";
|
||||
|
||||
return body;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user