Compare commits
10 Commits
7e1af96fcf
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 73a50e5db4 | |||
| ebf3cfa98d | |||
| 15ac0fa2a2 | |||
| e0039aca81 | |||
| 5c094ef9b4 | |||
| 3772805301 | |||
| d31b7a343c | |||
| 47cb243ff4 | |||
| e3fb52343d | |||
| 46463a27a4 |
Vendored
+127
-133
@@ -1,163 +1,157 @@
|
|||||||
pipeline {
|
pipeline {
|
||||||
agent { label 'djb-vm' }
|
agent none
|
||||||
|
|
||||||
options {
|
options {
|
||||||
timestamps()
|
timestamps()
|
||||||
disableConcurrentBuilds()
|
disableConcurrentBuilds()
|
||||||
|
skipDefaultCheckout() // stage별 agent의 자동 SCM checkout 방지 (Deploy 노드는 git 접근 불필요, unstash로만 WAR 수신)
|
||||||
buildDiscarder(logRotator(numToKeepStr: '20', artifactNumToKeepStr: '20'))
|
buildDiscarder(logRotator(numToKeepStr: '20', artifactNumToKeepStr: '20'))
|
||||||
}
|
}
|
||||||
|
|
||||||
environment {
|
environment {
|
||||||
JAVA_HOME = '/apps/opts/jdk8'
|
|
||||||
JAVA_HOME_TOMCAT = '/apps/opts/jdk17'
|
|
||||||
GRADLE_HOME = '/apps/opts/gradle-8.7'
|
|
||||||
GRADLE_USER_HOME = '/apps/opts/gradle-home'
|
|
||||||
NODE_HOME = '/apps/opts/node-v24'
|
|
||||||
PATH = "/apps/opts/jdk8/bin:/apps/opts/gradle-8.7/bin:/apps/opts/node-v24/bin:/apps/opts/bin:${env.PATH}"
|
|
||||||
GIT_SSH_COMMAND = 'ssh -o StrictHostKeyChecking=accept-new'
|
GIT_SSH_COMMAND = 'ssh -o StrictHostKeyChecking=accept-new'
|
||||||
CATALINA_BASE = '/prod/eapim/apigw'
|
WEBHOOK_URL = 'http://172.30.1.50:18000/api/hooks/01ba51b01d3c4c98ae8f3183a23a84ed713197857d024b5da4f303458195eb32'
|
||||||
CATALINA_HOME = '/prod/eapim/apache-tomcat-9.0.116'
|
|
||||||
CATALINA_PID = '/prod/eapim/apigw/logs/catalina.pid'
|
|
||||||
DEPLOY_HTTP_PORT = '39110'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stages {
|
stages {
|
||||||
stage('Checkout') {
|
stage('Build (djb-vm)') {
|
||||||
steps {
|
agent { label 'djb-vm' }
|
||||||
checkout scm
|
environment {
|
||||||
|
JAVA_HOME = '/apps/opts/jdk8'
|
||||||
|
GRADLE_HOME = '/apps/opts/gradle-8.7'
|
||||||
|
GRADLE_USER_HOME = '/apps/opts/gradle-home'
|
||||||
|
NODE_HOME = '/apps/opts/node-v24'
|
||||||
|
PATH = "/apps/opts/jdk8/bin:/apps/opts/gradle-8.7/bin:/apps/opts/node-v24/bin:/apps/opts/bin:${env.PATH}"
|
||||||
}
|
}
|
||||||
}
|
stages {
|
||||||
|
stage('Checkout') {
|
||||||
|
steps { checkout scm }
|
||||||
|
}
|
||||||
|
|
||||||
stage('Checkout modules') {
|
stage('Checkout modules') {
|
||||||
steps {
|
steps {
|
||||||
sh '''
|
sh '''
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
for REPO in elink-online-core elink-online-transformer elink-online-common elink-online-emsclient elink-online-core-jpa; do
|
for REPO in elink-online-core elink-online-transformer elink-online-common elink-online-emsclient elink-online-core-jpa; do
|
||||||
if [ ! -e "$REPO/.git" ]; then
|
if [ ! -e "$REPO/.git" ]; then
|
||||||
rm -rf "$REPO"
|
rm -rf "$REPO"
|
||||||
git clone --depth=1 --branch master \
|
git clone --depth=1 --branch master \
|
||||||
"ssh://git@172.30.1.50:2222/djb-eapim/$REPO.git" \
|
"ssh://git@172.30.1.50:2222/djb-eapim/$REPO.git" \
|
||||||
"$REPO"
|
"$REPO"
|
||||||
else
|
else
|
||||||
git -C "$REPO" fetch --depth=1 origin master
|
git -C "$REPO" fetch --depth=1 origin master
|
||||||
git -C "$REPO" reset --hard origin/master
|
git -C "$REPO" reset --hard origin/master
|
||||||
git -C "$REPO" clean -fdx
|
git -C "$REPO" clean -fdx
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
'''
|
'''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Verify toolchain') {
|
stage('Verify toolchain') {
|
||||||
steps {
|
steps {
|
||||||
sh '''
|
sh '''
|
||||||
set -eu
|
set -eu
|
||||||
java -version
|
java -version
|
||||||
gradle --version
|
gradle --version
|
||||||
'''
|
'''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Build WAR') {
|
stage('Build WAR') {
|
||||||
steps {
|
steps { sh 'gradle clean build -x test --no-daemon -Pprofile=weblogic' }
|
||||||
sh 'gradle clean build -x test --no-daemon'
|
post {
|
||||||
}
|
success {
|
||||||
post {
|
sh '''
|
||||||
success {
|
set -eu
|
||||||
sh '''
|
cd build/libs
|
||||||
set -eu
|
sha256sum eapim-online.war > eapim-online.war.sha256
|
||||||
cd build/libs
|
'''
|
||||||
sha1sum eapim-online.war > eapim-online.war.sha1
|
archiveArtifacts artifacts: 'build/libs/eapim-online.war,build/libs/eapim-online.war.sha256', fingerprint: true
|
||||||
sha256sum eapim-online.war > eapim-online.war.sha256
|
stash name: 'war', includes: 'build/libs/eapim-online.war'
|
||||||
md5sum eapim-online.war > eapim-online.war.md5
|
}
|
||||||
'''
|
}
|
||||||
archiveArtifacts artifacts: 'build/libs/eapim-online.war,build/libs/eapim-online.war.sha1,build/libs/eapim-online.war.sha256,build/libs/eapim-online.war.md5', fingerprint: true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Stop Tomcat') {
|
stage('Deploy (weblogic)') {
|
||||||
steps {
|
agent { label 'weblogic' }
|
||||||
sh '''
|
environment {
|
||||||
set +e
|
JENKINS_NODE_COOKIE = 'dontKillMe' // background weblogic를 빌드 종료 시 죽이지 않게
|
||||||
systemctl --user stop eapim-apigw 2>/dev/null
|
WL_HOME = '/app/eapim/apigw'
|
||||||
|
WL_DEPLOY_DIR = '/app/eapim/apigw'
|
||||||
if [ -f "$CATALINA_PID" ] && kill -0 "$(cat "$CATALINA_PID")" 2>/dev/null; then
|
WL_WAR_NAME = 'eapim-online.war'
|
||||||
JAVA_HOME="$JAVA_HOME_TOMCAT" "$CATALINA_HOME/bin/shutdown.sh" 30 -force || true
|
WL_HTTP_PORT = '39110'
|
||||||
for i in $(seq 1 30); do
|
WL_NOHUP = '/logs/weblogic/domains/eapimDomain/nohup.agwSvr11.out'
|
||||||
[ -f "$CATALINA_PID" ] && kill -0 "$(cat "$CATALINA_PID")" 2>/dev/null || break
|
|
||||||
sleep 1
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
rm -f "$CATALINA_PID"
|
|
||||||
'''
|
|
||||||
}
|
}
|
||||||
}
|
stages {
|
||||||
|
stage('Stop WebLogic') {
|
||||||
|
steps {
|
||||||
|
sh '"$WL_HOME/stopAgw11.sh"' // 동기: 완전 종료까지 블록, 미기동 시에도 안전
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stage('Deploy WAR') {
|
||||||
|
steps {
|
||||||
|
unstash 'war'
|
||||||
|
sh '''
|
||||||
|
set -eu
|
||||||
|
cp build/libs/eapim-online.war "$WL_DEPLOY_DIR/$WL_WAR_NAME"
|
||||||
|
ls -la "$WL_DEPLOY_DIR"
|
||||||
|
'''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stage('Start WebLogic and readiness') {
|
||||||
|
steps {
|
||||||
|
sh '''
|
||||||
|
set -eu
|
||||||
|
"$WL_HOME/startAgw11.sh" # nohup & 로 백그라운드 기동, 즉시 리턴
|
||||||
|
|
||||||
stage('Deploy ROOT.war') {
|
DEADLINE=$(($(date +%s) + 300))
|
||||||
steps {
|
STATUS=000
|
||||||
sh '''
|
while [ "$(date +%s)" -lt "$DEADLINE" ]; do
|
||||||
set -eu
|
STATUS=$(curl -sS -o /dev/null -w '%{http_code}' --max-time 3 \
|
||||||
DEPLOY_DIR="$CATALINA_BASE/webapps"
|
"http://localhost:$WL_HTTP_PORT/" 2>/dev/null || echo "000")
|
||||||
rm -rf "$DEPLOY_DIR/ROOT" "$DEPLOY_DIR/ROOT.war"
|
case "$STATUS" in
|
||||||
cp build/libs/eapim-online.war "$DEPLOY_DIR/ROOT.war"
|
200|302|401|403|404) echo "Readiness OK (/ HTTP $STATUS)"; break ;;
|
||||||
ls -la "$DEPLOY_DIR"
|
esac
|
||||||
'''
|
sleep 3
|
||||||
}
|
done
|
||||||
}
|
|
||||||
|
|
||||||
stage('Start Tomcat and readiness') {
|
case "$STATUS" in
|
||||||
steps {
|
200|302|401|403|404) ;;
|
||||||
sh '''
|
*)
|
||||||
set -eu
|
echo "Readiness failed within 300s, last HTTP=$STATUS"
|
||||||
LOG="$CATALINA_BASE/logs/catalina.$(date +%Y-%m-%d).log"
|
[ -f "$WL_NOHUP" ] && tail -120 "$WL_NOHUP"
|
||||||
BEFORE=0
|
exit 1
|
||||||
[ -f "$LOG" ] && BEFORE=$(stat -c %s "$LOG")
|
;;
|
||||||
|
esac
|
||||||
systemctl --user start eapim-apigw
|
'''
|
||||||
|
}
|
||||||
PROBE_URL="http://localhost:$DEPLOY_HTTP_PORT/"
|
}
|
||||||
DEADLINE=$(($(date +%s) + 300))
|
|
||||||
STATUS=000
|
|
||||||
|
|
||||||
while [ "$(date +%s)" -lt "$DEADLINE" ]; do
|
|
||||||
STATUS=$(curl -sS -o /dev/null -w '%{http_code}' --max-time 3 \
|
|
||||||
"$PROBE_URL" 2>/dev/null || echo "000")
|
|
||||||
case "$STATUS" in
|
|
||||||
200|302|401|403|404)
|
|
||||||
echo "Readiness OK ($PROBE_URL HTTP $STATUS)"
|
|
||||||
break
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
if [ -f "$LOG" ] && tail -c +$((BEFORE+1)) "$LOG" | grep -qE "Application listener .* Exception|SEVERE.*startup.Catalina"; then
|
|
||||||
echo "Startup error detected in log"
|
|
||||||
tail -c +$((BEFORE+1)) "$LOG" | tail -80
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
sleep 2
|
|
||||||
done
|
|
||||||
|
|
||||||
case "$STATUS" in
|
|
||||||
200|302|401|403|404) ;;
|
|
||||||
*)
|
|
||||||
echo "Readiness probe failed within 300s, last HTTP status: $STATUS"
|
|
||||||
echo "--- last 300 lines of catalina log ---"
|
|
||||||
[ -f "$LOG" ] && tail -c +$((BEFORE+1)) "$LOG" | tail -300
|
|
||||||
echo "--- systemd unit status ---"
|
|
||||||
systemctl --user status eapim-apigw --no-pager || true
|
|
||||||
echo "--- listening ports ---"
|
|
||||||
ss -tlnp 2>/dev/null | grep -E ":$DEPLOY_HTTP_PORT\\b" || echo "(port $DEPLOY_HTTP_PORT not listening)"
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
echo "--- key boot log lines ---"
|
|
||||||
tail -c +$((BEFORE+1)) "$LOG" | grep -E "Server startup|Deployment of web" | head -10 || true
|
|
||||||
'''
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
post {
|
||||||
|
success {
|
||||||
|
node('weblogic') {
|
||||||
|
sh '''
|
||||||
|
set +e
|
||||||
|
payload=$(printf '{"text":"[%s #%s](%s) SUCCESS"}' "$JOB_NAME" "$BUILD_NUMBER" "$BUILD_URL")
|
||||||
|
curl -sS --fail --max-time 5 -H 'Content-Type: application/json' -X POST --data "$payload" "$WEBHOOK_URL" >/dev/null || echo "Webhook failed"
|
||||||
|
'''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
failure {
|
||||||
|
node('weblogic') {
|
||||||
|
sh '''
|
||||||
|
set +e
|
||||||
|
payload=$(printf '{"text":"[%s #%s](%s) FAILURE"}' "$JOB_NAME" "$BUILD_NUMBER" "$BUILD_URL")
|
||||||
|
curl -sS --fail --max-time 5 -H 'Content-Type: application/json' -X POST --data "$payload" "$WEBHOOK_URL" >/dev/null || echo "Webhook failed"
|
||||||
|
'''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,9 +33,11 @@ import com.eactive.eai.common.TransactionContextKeys;
|
|||||||
import com.eactive.eai.common.exception.ExceptionUtil;
|
import com.eactive.eai.common.exception.ExceptionUtil;
|
||||||
import com.eactive.eai.common.server.EAIServerManager;
|
import com.eactive.eai.common.server.EAIServerManager;
|
||||||
import com.eactive.eai.common.util.DatetimeUtil;
|
import com.eactive.eai.common.util.DatetimeUtil;
|
||||||
|
import com.eactive.eai.common.util.HttpAdapterExtraLogUtil;
|
||||||
import com.eactive.eai.common.util.InboundErrorLogger;
|
import com.eactive.eai.common.util.InboundErrorLogger;
|
||||||
import com.eactive.eai.common.util.Logger;
|
import com.eactive.eai.common.util.Logger;
|
||||||
import com.eactive.eai.common.util.MessageUtil;
|
import com.eactive.eai.common.util.MessageUtil;
|
||||||
|
import com.eactive.eai.common.util.RestSendBodyLogUtils;
|
||||||
import com.eactive.eai.common.util.TxFileLogger;
|
import com.eactive.eai.common.util.TxFileLogger;
|
||||||
import com.eactive.eai.common.util.TxSiftContext;
|
import com.eactive.eai.common.util.TxSiftContext;
|
||||||
import com.eactive.eai.common.util.UUIDGenerator;
|
import com.eactive.eai.common.util.UUIDGenerator;
|
||||||
@@ -65,7 +67,7 @@ public class DJBApiAdapterController implements HttpAdapterServiceKey {
|
|||||||
"/tsb/{path:^(?!oauth).*$}", "/tsb/{path:^(?!oauth).*$}/**",
|
"/tsb/{path:^(?!oauth).*$}", "/tsb/{path:^(?!oauth).*$}/**",
|
||||||
"/shb/{path:^(?!oauth).*$}", "/shb/{path:^(?!oauth).*$}/**",
|
"/shb/{path:^(?!oauth).*$}", "/shb/{path:^(?!oauth).*$}/**",
|
||||||
"/tst/{path:^(?!oauth).*$}", "/tst/{path:^(?!oauth).*$}/**",
|
"/tst/{path:^(?!oauth).*$}", "/tst/{path:^(?!oauth).*$}/**",
|
||||||
"/**/{path:^(?!oauth).*$}", "/**/{path:^(?!oauth).*$}/**",
|
"/**/{path:^(?!oauth)(?!favicon\\.ico$).*$}", "/**/{path:^(?!oauth)(?!favicon\\.ico$).*$}/**",
|
||||||
})
|
})
|
||||||
public ResponseEntity<String> callApi(HttpServletRequest servletRequest, HttpServletResponse servletResponse)
|
public ResponseEntity<String> callApi(HttpServletRequest servletRequest, HttpServletResponse servletResponse)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
@@ -81,17 +83,25 @@ public class DJBApiAdapterController implements HttpAdapterServiceKey {
|
|||||||
logger.debug("ApiAdapterController] service request uri : " + servletRequest.getRequestURI());
|
logger.debug("ApiAdapterController] service request uri : " + servletRequest.getRequestURI());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (adptUri == null) {
|
|
||||||
logError(servletRequest);
|
|
||||||
String errorMsg = MessageUtil.makeJsonErrorMessage(MessageUtil.ERROR_CODE_SERVICE_NOT_FOUND,
|
|
||||||
"can not find Adapter Uri");
|
|
||||||
return ResponseEntity.status(HttpStatus.NOT_FOUND).contentType(MediaType.APPLICATION_JSON).body(errorMsg);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Received time , jwhong
|
// Received time , jwhong
|
||||||
long receivedTimeMillis = System.currentTimeMillis(); // 밀리세컨 단위로 보내야함
|
long receivedTimeMillis = System.currentTimeMillis(); // 밀리세컨 단위로 보내야함
|
||||||
String receivedTimeStr = String.valueOf(receivedTimeMillis);
|
String receivedTimeStr = String.valueOf(receivedTimeMillis);
|
||||||
|
|
||||||
|
ResponseEntity<String> responseEntity = null;
|
||||||
|
Properties transactionProp = new Properties();
|
||||||
|
String uuid = UUIDGenerator.getUUID().toString().replaceAll("-", "");
|
||||||
|
transactionProp.setProperty(TransactionContextKeys.TRANSACTION_UUID, uuid);
|
||||||
|
transactionProp.put(INBOUND_REQUESTED_TIME, receivedTimeStr);
|
||||||
|
|
||||||
|
if (adptUri == null) {
|
||||||
|
//logError(servletRequest);
|
||||||
|
String errorMsg = MessageUtil.makeJsonErrorMessage(MessageUtil.ERROR_CODE_SERVICE_NOT_FOUND,
|
||||||
|
"can not find Adapter Uri");
|
||||||
|
logError(servletRequest, "HTTP_IN_NO_URI", MessageUtil.ERROR_CODE_SERVICE_NOT_FOUND,
|
||||||
|
errorMsg, transactionProp, null);
|
||||||
|
return ResponseEntity.status(HttpStatus.NOT_FOUND).contentType(MediaType.APPLICATION_JSON).body(errorMsg);
|
||||||
|
}
|
||||||
|
|
||||||
String adapterGroupName = adptUri.getAdptGrpName();
|
String adapterGroupName = adptUri.getAdptGrpName();
|
||||||
String adapterName = adptUri.getAdptName();
|
String adapterName = adptUri.getAdptName();
|
||||||
AdapterGroupVO adapterGroupVO = AdapterManager.getInstance().getAdapterGroupVO(adapterGroupName);
|
AdapterGroupVO adapterGroupVO = AdapterManager.getInstance().getAdapterGroupVO(adapterGroupName);
|
||||||
@@ -99,6 +109,8 @@ public class DJBApiAdapterController implements HttpAdapterServiceKey {
|
|||||||
if (adapterVO == null) {
|
if (adapterVO == null) {
|
||||||
String errorMsg = MessageUtil.makeJsonErrorMessage(MessageUtil.ERROR_CODE_AP_ERROR,
|
String errorMsg = MessageUtil.makeJsonErrorMessage(MessageUtil.ERROR_CODE_AP_ERROR,
|
||||||
"Adapter not found error");
|
"Adapter not found error");
|
||||||
|
logError(servletRequest, adapterGroupName, MessageUtil.ERROR_CODE_AP_ERROR,
|
||||||
|
errorMsg, transactionProp, null);
|
||||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).contentType(MediaType.APPLICATION_JSON)
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).contentType(MediaType.APPLICATION_JSON)
|
||||||
.body(errorMsg);
|
.body(errorMsg);
|
||||||
}
|
}
|
||||||
@@ -110,16 +122,10 @@ public class DJBApiAdapterController implements HttpAdapterServiceKey {
|
|||||||
MediaType mediaType = MediaType.valueOf("application/json;charset=" + encode);
|
MediaType mediaType = MediaType.valueOf("application/json;charset=" + encode);
|
||||||
String errorResponseFormat = httpProp.getProperty(ERROR_RESPONSE_FORMAT);
|
String errorResponseFormat = httpProp.getProperty(ERROR_RESPONSE_FORMAT);
|
||||||
|
|
||||||
ResponseEntity<String> responseEntity = null;
|
|
||||||
Properties transactionProp = new Properties();
|
|
||||||
String uuid = UUIDGenerator.getUUID().toString().replaceAll("-", "");
|
|
||||||
transactionProp.setProperty(TransactionContextKeys.TRANSACTION_UUID, uuid);
|
|
||||||
|
|
||||||
TxSiftContext.begin(uuid);
|
TxSiftContext.begin(uuid);
|
||||||
|
|
||||||
// jwhong, put api received time, eaiSvcCode
|
// jwhong, put api received time, eaiSvcCode
|
||||||
transactionProp.put(INBOUND_REQUESTED_TIME, receivedTimeStr);
|
|
||||||
|
|
||||||
String responseData = "";
|
String responseData = "";
|
||||||
try {
|
try {
|
||||||
responseData = service.callApi(servletRequest, servletResponse, httpProp, adapterGroupVO, adapterVO,
|
responseData = service.callApi(servletRequest, servletResponse, httpProp, adapterGroupVO, adapterVO,
|
||||||
@@ -169,6 +175,14 @@ public class DJBApiAdapterController implements HttpAdapterServiceKey {
|
|||||||
responseData = responseErrorMsg;
|
responseData = responseErrorMsg;
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
|
|
||||||
|
// 어댑터 HTTP 로그에 응답 body 출력
|
||||||
|
if (RestSendBodyLogUtils.isBodyLoggingApi(transactionProp.getProperty("API_SERVICE_CODE"))) {
|
||||||
|
String trimmedBody = RestSendBodyLogUtils.getBodyByMaxSize(responseData);
|
||||||
|
transactionProp.setProperty(HttpAdapterExtraLogUtil.BODY_FIELD_NAME, trimmedBody);
|
||||||
|
}
|
||||||
|
servletRequest.setAttribute(TransactionContextKeys.TRANSACTION_PROP, transactionProp);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 로깅 인터셉터에 데이터를 전달하기 위한 처리 이미 거래처리가 끝나서 영향도가 없을만한 servletRequest에 Attribute로 전달
|
* 로깅 인터셉터에 데이터를 전달하기 위한 처리 이미 거래처리가 끝나서 영향도가 없을만한 servletRequest에 Attribute로 전달
|
||||||
* 추후 더 좋은방법이 생길경우 개선 요망
|
* 추후 더 좋은방법이 생길경우 개선 요망
|
||||||
|
|||||||
+18
-10
@@ -1,19 +1,22 @@
|
|||||||
package com.eactive.eai.adapter.interceptor;
|
package com.eactive.eai.adapter.interceptor;
|
||||||
|
|
||||||
import com.eactive.eai.adapter.http.client.HttpClientAdapterServiceKey;
|
import java.util.HashMap;
|
||||||
import com.eactive.eai.adapter.http.dynamic.HttpAdapterServiceKey;
|
import java.util.List;
|
||||||
import com.eactive.eai.common.TransactionContextKeys;
|
import java.util.Map;
|
||||||
import com.eactive.eai.common.util.HttpAdapterExtraLogUtil;
|
import java.util.Properties;
|
||||||
import com.eactive.eai.common.util.Logger;
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.springframework.web.servlet.HandlerInterceptor;
|
import org.springframework.web.servlet.HandlerInterceptor;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import com.eactive.eai.adapter.http.client.HttpClientAdapterServiceKey;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import com.eactive.eai.adapter.http.dynamic.HttpAdapterServiceKey;
|
||||||
import java.util.HashMap;
|
import com.eactive.eai.common.TransactionContextKeys;
|
||||||
import java.util.Map;
|
import com.eactive.eai.common.logger.HttpAdapterExtraHeaderVo;
|
||||||
import java.util.Properties;
|
import com.eactive.eai.common.util.HttpAdapterExtraLogUtil;
|
||||||
|
import com.eactive.eai.common.util.Logger;
|
||||||
|
|
||||||
public class HttpResponseLoggingInterceptor implements HandlerInterceptor {
|
public class HttpResponseLoggingInterceptor implements HandlerInterceptor {
|
||||||
|
|
||||||
@@ -55,6 +58,11 @@ public class HttpResponseLoggingInterceptor implements HandlerInterceptor {
|
|||||||
logger.debug(String.format( "httpHeader logging Interceptor headerKey=%s, headerValue=%s", headerName, headerValue));
|
logger.debug(String.format( "httpHeader logging Interceptor headerKey=%s, headerValue=%s", headerName, headerValue));
|
||||||
headerMap.put(headerName, headerValue);
|
headerMap.put(headerName, headerValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String body = transactionProp.getProperty(HttpAdapterExtraLogUtil.BODY_FIELD_NAME);
|
||||||
|
if (StringUtils.isNotEmpty(body)) {
|
||||||
|
headerMap.put(HttpAdapterExtraLogUtil.BODY_FIELD_NAME, body);
|
||||||
|
}
|
||||||
|
|
||||||
int httpStatusCode = response.getStatus();
|
int httpStatusCode = response.getStatus();
|
||||||
HttpAdapterExtraLogUtil.insertHttpAdapterExtraLog(uuid, 400, adapterGroupName, adapterName, headerMap, url, method, httpStatusCode);
|
HttpAdapterExtraLogUtil.insertHttpAdapterExtraLog(uuid, 400, adapterGroupName, adapterName, headerMap, url, method, httpStatusCode);
|
||||||
|
|||||||
@@ -154,6 +154,8 @@ public class DJBApiAdapterService extends HttpAdapterServiceSupport {
|
|||||||
transactionProp.put(HEADER_GROUP, headerGroupName);
|
transactionProp.put(HEADER_GROUP, headerGroupName);
|
||||||
transactionProp.put(HEADER_KEYS, relayRequestHeaderKeys);
|
transactionProp.put(HEADER_KEYS, relayRequestHeaderKeys);
|
||||||
|
|
||||||
|
transactionProp.put(ADAPTER_TOKEN_HEADER_NAME, httpProp.getProperty(ADAPTER_TOKEN_HEADER_NAME, "")); // OAuth 인증 토큰 헤더 이름
|
||||||
|
transactionProp.put(ADAPTER_APIKEY_HEADER_NAME, httpProp.getProperty(ADAPTER_APIKEY_HEADER_NAME, "")); // API-KEY 인증 헤더 이름
|
||||||
// SEED 컬럼암호하 시 Key로 사용함
|
// SEED 컬럼암호하 시 Key로 사용함
|
||||||
String seedkey = inboundHeaderProp.getOrDefault("x-obp-partnercode", "").toString();
|
String seedkey = inboundHeaderProp.getOrDefault("x-obp-partnercode", "").toString();
|
||||||
ElinkTransactionContext.setSeedKey(seedkey);
|
ElinkTransactionContext.setSeedKey(seedkey);
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
|||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
|
||||||
import com.eactive.eai.adapter.http.dynamic.UnkownMessageLogUtils;
|
import com.eactive.eai.adapter.http.dynamic.UnknownMessageLogUtils;
|
||||||
import com.eactive.eai.adapter.http.dynamic.filter.JwtAuthException;
|
import com.eactive.eai.adapter.http.dynamic.filter.JwtAuthException;
|
||||||
import com.eactive.eai.authserver.config.RequestContextData;
|
import com.eactive.eai.authserver.config.RequestContextData;
|
||||||
import com.eactive.eai.authserver.dao.TokenIssuanceLogDAO;
|
import com.eactive.eai.authserver.dao.TokenIssuanceLogDAO;
|
||||||
@@ -164,7 +164,7 @@ public class DJBOAuth2Controller {
|
|||||||
|
|
||||||
Properties logProp = new Properties();
|
Properties logProp = new Properties();
|
||||||
logProp.put("clientId", clientId);
|
logProp.put("clientId", clientId);
|
||||||
UnkownMessageLogUtils.logUnkownMessage(this.getClass().getSimpleName(), this.getClass().getSimpleName(),
|
UnknownMessageLogUtils.logUnkownMessage(this.getClass().getSimpleName(), this.getClass().getSimpleName(),
|
||||||
tokenRequest.toString(), logProp, request, response, "RECEAIIRP301", e);
|
tokenRequest.toString(), logProp, request, response, "RECEAIIRP301", e);
|
||||||
|
|
||||||
String errorJson = MessageUtil.makeJsonErrorMessage(MessageUtil.ERROR_CODE_AUTH_FAIL, e.getMessage());
|
String errorJson = MessageUtil.makeJsonErrorMessage(MessageUtil.ERROR_CODE_AUTH_FAIL, e.getMessage());
|
||||||
@@ -179,7 +179,7 @@ public class DJBOAuth2Controller {
|
|||||||
|
|
||||||
Properties logProp = new Properties();
|
Properties logProp = new Properties();
|
||||||
logProp.put("clientId", clientId);
|
logProp.put("clientId", clientId);
|
||||||
UnkownMessageLogUtils.logUnkownMessage(this.getClass().getSimpleName(), this.getClass().getSimpleName(),
|
UnknownMessageLogUtils.logUnkownMessage(this.getClass().getSimpleName(), this.getClass().getSimpleName(),
|
||||||
tokenRequest.toString(), logProp, request, response, "RECEAIIRP301", e);
|
tokenRequest.toString(), logProp, request, response, "RECEAIIRP301", e);
|
||||||
|
|
||||||
String errorJson = MessageUtil.makeJsonErrorMessage(MessageUtil.ERROR_CODE_AUTH_FAIL, "Unauthorized. [Unknown]");
|
String errorJson = MessageUtil.makeJsonErrorMessage(MessageUtil.ERROR_CODE_AUTH_FAIL, "Unauthorized. [Unknown]");
|
||||||
|
|||||||
+35
-26
@@ -14,6 +14,7 @@ import org.apache.hc.client5.http.classic.methods.HttpUriRequestBase;
|
|||||||
import com.eactive.eai.adapter.http.client.HttpClientAdapterServiceKey;
|
import com.eactive.eai.adapter.http.client.HttpClientAdapterServiceKey;
|
||||||
import com.eactive.eai.adapter.http.client.impl.HttpClient5AdapterServiceRest;
|
import com.eactive.eai.adapter.http.client.impl.HttpClient5AdapterServiceRest;
|
||||||
import com.eactive.eai.common.property.PropManager;
|
import com.eactive.eai.common.property.PropManager;
|
||||||
|
import com.eactive.eai.common.util.MaskingUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 1. 기능 : EAI HTTP OutBound 용 어댑터로 수동 시스템의 HTTP 웹 컴포넌트를 GET/POST 방식으로 호출할 수 있는
|
* 1. 기능 : EAI HTTP OutBound 용 어댑터로 수동 시스템의 HTTP 웹 컴포넌트를 GET/POST 방식으로 호출할 수 있는
|
||||||
@@ -79,13 +80,21 @@ public class HttpClient5AdapterServiceBigTech extends HttpClient5AdapterServiceR
|
|||||||
String adapterGroupName = tempProp.getProperty(ADAPTER_GROUP_NAME);
|
String adapterGroupName = tempProp.getProperty(ADAPTER_GROUP_NAME);
|
||||||
Properties customProp = PropManager.getInstance().getProperties(adapterGroupName);
|
Properties customProp = PropManager.getInstance().getProperties(adapterGroupName);
|
||||||
String charset = customProp.getProperty("_BTP_CHARSET", _BTP_CHARSET);
|
String charset = customProp.getProperty("_BTP_CHARSET", _BTP_CHARSET);
|
||||||
String alorithm = customProp.getProperty("_BTP_ALGORITHM", _BTP_ALGORITHM);
|
String algorithm = customProp.getProperty("_BTP_ALGORITHM", _BTP_ALGORITHM);
|
||||||
String timestamp = System.currentTimeMillis() + "";
|
String timestamp = System.currentTimeMillis() + "";
|
||||||
String accessKey = customProp.getProperty("_BTP_ACCESS_KEY", _BTP_ACCESS_KEY);
|
String accessKey = customProp.getProperty("_BTP_ACCESS_KEY", _BTP_ACCESS_KEY);
|
||||||
String secretKey = customProp.getProperty("_BTP_SECRET_KEY", _BTP_SECRET_KEY);
|
String secretKey = customProp.getProperty("_BTP_SECRET_KEY", _BTP_SECRET_KEY);
|
||||||
|
if(logger.isDebug()) {
|
||||||
|
logger.debug("charset={}", charset);
|
||||||
|
logger.debug("algorithm={}", algorithm);
|
||||||
|
logger.debug("timestamp={}", timestamp);
|
||||||
|
logger.debug("accessKey={}", accessKey);
|
||||||
|
logger.debug("secretKey={}", MaskingUtils.maskPassword(secretKey));
|
||||||
|
logger.debug("url={}", method.getRequestUri());
|
||||||
|
}
|
||||||
|
|
||||||
String signature = macHex(charset// charset
|
String signature = macHex(charset// charset
|
||||||
, alorithm// algorithm
|
, algorithm// algorithm
|
||||||
, timestamp// timestamp
|
, timestamp// timestamp
|
||||||
, accessKey// accessKey
|
, accessKey// accessKey
|
||||||
, secretKey// secretKey
|
, secretKey// secretKey
|
||||||
@@ -100,28 +109,28 @@ public class HttpClient5AdapterServiceBigTech extends HttpClient5AdapterServiceR
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
// public static void main(String[] args) {
|
||||||
try {
|
// try {
|
||||||
String url = "/rest/v1/service?param0=¶m1=";
|
// String url = "/rest/v1/service?param0=¶m1=";
|
||||||
String timestamp = System.currentTimeMillis()+"";
|
// String timestamp = System.currentTimeMillis()+"";
|
||||||
String accessKey = _BTP_ACCESS_KEY;
|
// String accessKey = _BTP_ACCESS_KEY;
|
||||||
String secretKey = _BTP_SECRET_KEY;
|
// String secretKey = _BTP_SECRET_KEY;
|
||||||
String signature = macHex(
|
// String signature = macHex(
|
||||||
_BTP_CHARSET//charset
|
// _BTP_CHARSET//charset
|
||||||
, _BTP_ALGORITHM//algorithm
|
// , _BTP_ALGORITHM//algorithm
|
||||||
, timestamp// timestamp
|
// , timestamp// timestamp
|
||||||
, _BTP_ACCESS_KEY//accessKey
|
// , _BTP_ACCESS_KEY//accessKey
|
||||||
, _BTP_SECRET_KEY//secretKey
|
// , _BTP_SECRET_KEY//secretKey
|
||||||
, url
|
// , url
|
||||||
);
|
// );
|
||||||
System.out.println(String.format("charset=%s", _BTP_CHARSET));
|
// System.out.println(String.format("charset=%s", _BTP_CHARSET));
|
||||||
System.out.println(String.format("algorithm=%s", _BTP_ALGORITHM));
|
// System.out.println(String.format("algorithm=%s", _BTP_ALGORITHM));
|
||||||
System.out.println(String.format("accessKey=%s", accessKey));
|
// System.out.println(String.format("accessKey=%s", accessKey));
|
||||||
System.out.println(String.format("secretKey=%s", secretKey));
|
// System.out.println(String.format("secretKey=%s", secretKey));
|
||||||
System.out.println(String.format("timestamp=%s", timestamp));
|
// System.out.println(String.format("timestamp=%s", timestamp));
|
||||||
System.out.println(String.format("signature=%s", signature));
|
// System.out.println(String.format("signature=%s", signature));
|
||||||
} catch (Exception e) {
|
// } catch (Exception e) {
|
||||||
e.printStackTrace();
|
// e.printStackTrace();
|
||||||
}
|
// }
|
||||||
}// end of main
|
// }// end of main
|
||||||
}
|
}
|
||||||
|
|||||||
+147
@@ -0,0 +1,147 @@
|
|||||||
|
package com.eactive.eai.custom.adapter.http.client.impl;
|
||||||
|
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.dom4j.Node;
|
||||||
|
import org.json.simple.JSONObject;
|
||||||
|
|
||||||
|
import com.eactive.eai.adapter.http.client.HttpClientAdapterServiceKey;
|
||||||
|
import com.eactive.eai.adapter.http.client.impl.filter.HttpClient5AdapterFilterFactory;
|
||||||
|
import com.eactive.eai.adapter.http.client.impl.filter.HttpClientAdapterFilter;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 1. 기능 : HttpClient5AdapterServiceRest 호출 전후 Filter 적용할 수 있는 기능을 제공한다.<br>
|
||||||
|
* 2. 처리 개요 : <br>
|
||||||
|
* 3. 주의사항 <br>
|
||||||
|
*
|
||||||
|
* @author :
|
||||||
|
* @version : v 1.0.0
|
||||||
|
* @see : HttpClientAdapterServiceFactory.java,
|
||||||
|
* HttpClientAdapterServiceSupport.java, HttpClient5AdapterServiceRest.java
|
||||||
|
* @since :
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class HttpClient5AdapterServiceBigTechAddFilter extends HttpClient5AdapterServiceBigTech
|
||||||
|
implements HttpClientAdapterServiceKey {
|
||||||
|
|
||||||
|
// 요청전 수행할 필터(쉼표(,)로 구분)
|
||||||
|
static final String PRE_FILTERS = "PRE_FILTERS";
|
||||||
|
|
||||||
|
// 요청후 수행할 필터(쉼표(,)로 구분)
|
||||||
|
static final String POST_FILTERS = "POST_FILTERS";
|
||||||
|
|
||||||
|
// // Adapter에서 Exception이 발생한 경우, 처리할 필터
|
||||||
|
// static final String EXCEPTION_FILTER = "EXCEPTION_FILTER";
|
||||||
|
|
||||||
|
private ObjectMapper mapper = new ObjectMapper();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 1. 기능 : HttpClient 호출 전후 Filter 적용용 2. 처리 개요 : <br>
|
||||||
|
* 3. 주의사항 <br>
|
||||||
|
*
|
||||||
|
* @param prop Http Adapter 속성 정보
|
||||||
|
* @return 반환 된 Object
|
||||||
|
* @exception Exception 수동 시스템 간 통신 중 발생
|
||||||
|
*/
|
||||||
|
public Object execute(Properties prop, Object data, Properties tempProp) throws Exception {
|
||||||
|
|
||||||
|
String adptGrpName = tempProp.getProperty(ADAPTER_GROUP_NAME);
|
||||||
|
String adptName = tempProp.getProperty(ADAPTER_NAME);
|
||||||
|
|
||||||
|
data = doPreFilters(adptGrpName, adptName, prop, data, tempProp);
|
||||||
|
|
||||||
|
Object adapterResponse = super.execute(prop, data, tempProp);
|
||||||
|
|
||||||
|
adapterResponse = doPostFilters(adptGrpName, adptName, prop, adapterResponse, tempProp);
|
||||||
|
if (adapterResponse instanceof JSONObject)
|
||||||
|
adapterResponse = ((JSONObject) adapterResponse).toJSONString();
|
||||||
|
else if (adapterResponse instanceof ObjectNode)
|
||||||
|
adapterResponse = mapper.writeValueAsString((ObjectNode) adapterResponse);
|
||||||
|
else if (adapterResponse instanceof Node)
|
||||||
|
adapterResponse = ((Node) adapterResponse).asXML();
|
||||||
|
|
||||||
|
return adapterResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Object doPreFilters(String adptGrpName, String adptName, Properties prop, Object message,
|
||||||
|
Properties tempProp) throws Exception {
|
||||||
|
|
||||||
|
// boolean isSetCommonFilterInAdapterProp = false;
|
||||||
|
// 1. adapter에 설정된 필터 수행
|
||||||
|
String preFiltersStr = prop.getProperty(PRE_FILTERS);
|
||||||
|
if (StringUtils.isNotEmpty(preFiltersStr)) {
|
||||||
|
String[] preFilters = StringUtils.split(preFiltersStr, ",");
|
||||||
|
for (String filterName : preFilters) {
|
||||||
|
if (StringUtils.isBlank(filterName)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.debug("HttpClient5AdapterServiceRestAddFilter] Processing Start [" + filterName + "]");
|
||||||
|
HttpClientAdapterFilter adapterFilter = HttpClient5AdapterFilterFactory.createFilter(filterName.trim());
|
||||||
|
|
||||||
|
if (adapterFilter != null) {
|
||||||
|
// if (adapterFilter instanceof IBKOutCommonFilter)
|
||||||
|
// isSetCommonFilterInAdapterProp = true;
|
||||||
|
|
||||||
|
message = adapterFilter.doPreFilter(adptGrpName, adptName, prop, message, tempProp);
|
||||||
|
} else {
|
||||||
|
throw new Exception("Failed get Filter Class: " + filterName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// // 2. IBKOutCommonFilter 필터 수행(adapter 필터에서 수행하지 않을 때만)
|
||||||
|
// if (!isSetCommonFilterInAdapterProp) {
|
||||||
|
// HttpClientAdapterFilter ibkFilter = HttpClient5AdapterFilterFactory
|
||||||
|
// .createFilter(IBKOutCommonFilter.class.getName());
|
||||||
|
// if (ibkFilter != null) {
|
||||||
|
// message = ibkFilter.doPreFilter(adptGrpName, adptName, prop, message, tempProp);
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// logger.debug("IBKOutCommonFilter isSetCommonFilterInAdapterProp 'POST_FILTERS'. already in adapter filters");
|
||||||
|
// }
|
||||||
|
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Object doPostFilters(String adptGrpName, String adptName, Properties prop, Object message,
|
||||||
|
Properties tempProp) throws Exception {
|
||||||
|
|
||||||
|
// boolean isSetCommonFilterInAdapterProp = false;
|
||||||
|
// 1. adapter에 설정된 필터 수행
|
||||||
|
String postFiltersStr = prop.getProperty(POST_FILTERS);
|
||||||
|
if (StringUtils.isNotEmpty(postFiltersStr)) {
|
||||||
|
String[] postFilters = StringUtils.split(postFiltersStr, ",");
|
||||||
|
for (String filterName : postFilters) {
|
||||||
|
if (StringUtils.isBlank(filterName)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
HttpClientAdapterFilter adapterFilter = HttpClient5AdapterFilterFactory.createFilter(filterName.trim());
|
||||||
|
if (adapterFilter != null) {
|
||||||
|
// if (adapterFilter instanceof IBKOutCommonFilter)
|
||||||
|
// isSetCommonFilterInAdapterProp = true;
|
||||||
|
message = adapterFilter.doPostFilter(adptGrpName, adptName, prop, message, tempProp);
|
||||||
|
} else {
|
||||||
|
throw new Exception("Failed get Filter Class: " + filterName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// // 2. IBKOutCommonFilter 필터 수행
|
||||||
|
// if (!isSetCommonFilterInAdapterProp) {
|
||||||
|
// HttpClientAdapterFilter ibkFilter = HttpClient5AdapterFilterFactory
|
||||||
|
// .createFilter(IBKOutCommonFilter.class.getName());
|
||||||
|
// if (ibkFilter != null) {
|
||||||
|
// message = ibkFilter.doPostFilter(adptGrpName, adptName, prop, message, tempProp);
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// logger.debug("IBKOutCommonFilter isSetCommonFilterInAdapterProp 'PRE_FILTERS'. already in adapter filters");
|
||||||
|
// }
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user