MMS, 알림톡, 친구톡 기능 추가

This commit is contained in:
dsjang 2024-07-29 02:09:26 +09:00
parent e38c24b416
commit 50cccb9bdc
14 changed files with 807 additions and 151 deletions

View File

@ -1,5 +1,6 @@
package com.munjaon.client.config;
import com.zaxxer.hikari.HikariDataSource;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@ -39,7 +40,7 @@ public class DataSourceConfig {
System.out.println("MARIADB.URL : " + serverConfig.getString(dbms + ".URL"));
System.out.println("MARIADB.USER : " + serverConfig.getString(dbms + ".USER"));
System.out.println("MARIADB.PASSWORD : " + serverConfig.getString(dbms + ".PASSWORD"));
return DataSourceBuilder.create()
return DataSourceBuilder.create().type(HikariDataSource.class)
.driverClassName(serverConfig.getString(dbms + ".DRIVER"))
.url(serverConfig.getString(dbms + ".URL"))
.username(serverConfig.getString(dbms + ".USER"))

View File

@ -79,6 +79,34 @@ public class RunnerConfiguration {
return args -> System.out.println("Runner Bean #2");
}
@Bean
@Order(2)
public CommandLineRunner getRunnerBeanForKat() {
try {
String serviceName = "KAT";
String serviceType = serverConfig.getString(serviceName + ".SERVICE_TYPE");
CollectClientService collectClientService = new CollectClientService(serviceName, serviceType);
collectClientService.start();
} catch (Exception e) {
throw new RuntimeException(e);
}
return args -> System.out.println("Runner Bean #2");
}
@Bean
@Order(2)
public CommandLineRunner getRunnerBeanForKft() {
try {
String serviceName = "KFT";
String serviceType = serverConfig.getString(serviceName + ".SERVICE_TYPE");
CollectClientService collectClientService = new CollectClientService(serviceName, serviceType);
collectClientService.start();
} catch (Exception e) {
throw new RuntimeException(e);
}
return args -> System.out.println("Runner Bean #2");
}
@Bean
@Order(2)
public CommandLineRunner getRunnerBeanForReport() {

View File

@ -19,7 +19,7 @@ public class MariaDBService {
try {
int msgCount = mariaDBMapper.checkTableForMessage();
int logCount = mariaDBMapper.checkTableForLog();
if (msgCount == 1 && logCount == 1) {
if (msgCount > 0 && logCount > 0) {
isExist = true;
}
} catch (Exception e) {

View File

@ -23,6 +23,9 @@ public class MunjaonMsg {
private String filename02;
private String filename03;
private String deliverDate;
private String kakaoSenderKey;
private String kakaoTemplateCode;
private String kakaoJsonFile;
private String sendDate;
private String reportDate;
private int fileCount = 0;

View File

@ -5,9 +5,43 @@ import lombok.Getter;
@Getter
public enum ErrorCode {
OK(200, "Success"),
ERROR_DATA_IS_NULL(300, "Msg is null"),
ERROR_SUBJECT_IS_NULL(310, "Subject is null"),
ERROR_MESSAGE_IS_NULL(320, "Message is null"),
ERROR_DATA_IS_NULL(300, "DATA is null"),
/* MSG_ID : 31X */
ERROR_MSGID_IS_NULL(310, "MSG_ID is null"),
ERROR_MSGID_IS_CAPACITY(311, "MSG_ID : SIZE is Zero Or Over"),
/* SENDER : 32X */
ERROR_SENDER_IS_NULL(320, "SENDER is null"),
ERROR_SENDER_IS_CAPACITY(321, "SENDER : SIZE is Zero Or Over"),
/* RECEIVER : 33X */
ERROR_RECEIVER_IS_NULL(330, "RECEIVER is null"),
ERROR_RECEIVER_IS_CAPACITY(331, "RECEIVER : SIZE is Zero Or Over"),
ERROR_RECEIVER_IS_INVALID(332, "RECEIVER is invalid number"),
/* SMS MESSAGE : 34X */
ERROR_SMS_MSG_IS_NULL(340, "SMS MESSAGE is null"),
ERROR_SMS_MSG_IS_CAPACITY(341, "SMS MESSAGE : SIZE is Zero Or Over"),
/* LMS, MMS SUBJECT : 35X */
ERROR_SUBJECT_IS_NULL(350, "Subject is null"),
ERROR_SUBJECT_OVER_CAPACITY(351, "Subject is over capacity"),
/* LMS, MMS MESSAGE : 36X */
ERROR_MULTI_MESSAGE_IS_NULL(360, "Multimedia Message is null"),
ERROR_MULTI_MESSAGE_OVER_CAPACITY(361, "Multimedia Message is over capacity"),
/* MMS IMAGE : 37X */
ERROR_MMS_IMAGE_IS_NULL(370, "MMS_IMAGE is not exist"),
ERROR_MMS_IMAGE_IS_EXT(371, "MMS_IMAGE is not support extension"),
ERROR_MMS_IMAGE_IS_NOT_PATH(372, "MMS_IMAGE is not exists"),
ERROR_MMS_IMAGE_IS_OVER_CAPACITY(373, "MMS_IMAGE is over capacity"),
/* KAKAO_SENDER_KEY : 38X */
ERROR_KAKAO_SENDER_KEY_IS_NULL(380, "KAKAO_SENDER_KEY is null"),
ERROR_KAKAO_SENDER_KEY_OVER_CAPACITY(381, "KAKAO_SENDER_KEY is over capacity"),
/* KAKAO_TEMPLATE_CODE : 39X */
ERROR_KAKAO_TEMPLATE_CODE_IS_NULL(390, "KAKAO_TEMPLATE_CODE is null"),
ERROR_KAKAO_TEMPLATE_CODE_OVER_CAPACITY(391, "KAKAO_TEMPLATE_CODE is over capacity"),
/* KAKAO_JSON_FILE : 40X */
ERROR_KAKAO_JSON_FILE_IS_NULL(400, "KAKAO_JSON_FILE is not exist"),
ERROR_KAKAO_JSON_FILE_IS_EXT(401, "KAKAO_JSON_FILE is not support extension"),
ERROR_KAKAO_JSON_FILE_IS_NOT_PATH(402, "KAKAO_JSON_FILE is not exists"),
ERROR_KAKAO_JSON_FILE_IS_OVER_CAPACITY(403, "KAKAO_JSON_FILE is over capacity"),
ERROR_FILE_NOT_FOUND(390, "File Not Found"),
ERROR_FILE_CAPACITY_EXCEED(391, "File capacity exceeded");

View File

@ -0,0 +1,157 @@
package com.munjaon.client.server.packet;
import com.munjaon.client.model.MunjaonMsg;
import com.munjaon.client.util.CommonUtil;
import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.file.Files;
public final class KakaoMessage {
public static final int LIMIT_FILE_CAPACITY = 1024 * 50;
public static final int DELIVER_JSON_FILENAME_LENGTH = 40;
public static final int DELIVER_JSON_FILENAME_POSITION = 0;
public static final int DELIVER_JSON_FILESIZE_LENGTH = 8;
public static final int DELIVER_JSON_FILESIZE_POSITION = DELIVER_JSON_FILENAME_POSITION + DELIVER_JSON_FILENAME_LENGTH;
public static final int DELIVER_KAKAO_BODY_LENGTH = 2233;
public static final int DELIVER_KAKAO_ACK_BODY_LENGTH = 21;
/* DELIVER */
/* SUBJECT */
public static final int DELIVER_SUBJECT_LENGTH = 40;
public static final int DELIVER_SUBJECT_POSITION = CommonMessage.DELIVER_MSG_TYPE_POSITION + CommonMessage.DELIVER_MSG_TYPE_LENGTH;
/* MESSAGE */
public static final int DELIVER_MESSAGE_LENGTH = 2000;
public static final int DELIVER_MESSAGE_POSITION = DELIVER_SUBJECT_POSITION + DELIVER_SUBJECT_LENGTH;
/* KAKAO_SENDER_KEY */
public static final int DELIVER_KAKAO_SENDER_KEY_LENGTH = 40;
public static final int DELIVER_KAKAO_SENDER_KEY_POSITION = DELIVER_MESSAGE_POSITION + DELIVER_MESSAGE_LENGTH;
/* KAKAO_TEMPLATE_CODE */
public static final int DELIVER_KAKAO_TEMPLATE_CODE_LENGTH = 64;
public static final int DELIVER_KAKAO_TEMPLATE_CODE_POSITION = DELIVER_KAKAO_SENDER_KEY_POSITION + DELIVER_KAKAO_SENDER_KEY_LENGTH;
public static void putSubjectForDeliver(ByteBuffer buffer, String subject) {
if (buffer == null || subject == null) {
return;
}
subject = CommonUtil.cutString(subject, DELIVER_SUBJECT_LENGTH);
buffer.put(DELIVER_SUBJECT_POSITION, subject.getBytes());
}
public static String getSubjectForDeliver(ByteBuffer buffer) {
if (buffer == null) {
return null;
}
buffer.position(DELIVER_SUBJECT_POSITION);
byte[] destArray = new byte[DELIVER_SUBJECT_LENGTH];
buffer.get(destArray);
return Packet.getString(destArray);
}
public static void putMessageForDeliver(ByteBuffer buffer, String message) {
if (buffer == null || message == null) {
return;
}
message = CommonUtil.cutString(message, DELIVER_MESSAGE_LENGTH);
buffer.put(DELIVER_MESSAGE_POSITION, message.getBytes());
}
public static String getMessageForDeliver(ByteBuffer buffer) {
if (buffer == null) {
return null;
}
buffer.position(DELIVER_MESSAGE_POSITION);
byte[] destArray = new byte[DELIVER_MESSAGE_LENGTH];
buffer.get(destArray);
return Packet.getString(destArray);
}
public static void putKakaoSenderKeyForDeliver(ByteBuffer buffer, String kakaoSenderKey) {
if (buffer == null || kakaoSenderKey == null) {
return;
}
kakaoSenderKey = CommonUtil.cutString(kakaoSenderKey, DELIVER_KAKAO_SENDER_KEY_LENGTH);
buffer.put(DELIVER_KAKAO_SENDER_KEY_POSITION, kakaoSenderKey.getBytes());
}
public static String getKakaoSenderKeyForDeliver(ByteBuffer buffer) {
if (buffer == null) {
return null;
}
buffer.position(DELIVER_KAKAO_SENDER_KEY_POSITION);
byte[] destArray = new byte[DELIVER_KAKAO_SENDER_KEY_LENGTH];
buffer.get(destArray);
return Packet.getString(destArray);
}
public static void putKakaoTemplateCodeForDeliver(ByteBuffer buffer, String kakaoTemplateCode) {
if (buffer == null || kakaoTemplateCode == null) {
return;
}
kakaoTemplateCode = CommonUtil.cutString(kakaoTemplateCode, DELIVER_KAKAO_TEMPLATE_CODE_LENGTH);
buffer.put(DELIVER_KAKAO_TEMPLATE_CODE_POSITION, kakaoTemplateCode.getBytes());
}
public static String getKakaoTemplateCodeForDeliver(ByteBuffer buffer) {
if (buffer == null) {
return null;
}
buffer.position(DELIVER_KAKAO_TEMPLATE_CODE_POSITION);
byte[] destArray = new byte[DELIVER_KAKAO_TEMPLATE_CODE_LENGTH];
buffer.get(destArray);
return Packet.getString(destArray);
}
public static void makeDataForDeliver(ByteBuffer buffer, MunjaonMsg data) {
if (buffer == null || data == null) {
return;
}
/* MSG_ID */
CommonMessage.putMessageIdForDeliver(buffer, data.getMsgId());
/* SENDER */
CommonMessage.putSenderForDeliver(buffer, data.getSendPhone());
/* RECEIVER */
CommonMessage.putReceiverForDeliver(buffer, data.getRecvPhone());
/* RESERVE_TIME */
CommonMessage.putReserveTimeForDeliver(buffer, data.getReserveDate());
/* REQUEST_TIME */
CommonMessage.putRequestTimeForDeliver(buffer, data.getRequestDate());
/* MSG_TYPE */
CommonMessage.putMsgTypeForDeliver(buffer, data.getMsgType());
/* Subject */
putSubjectForDeliver(buffer, data.getSubject());
/* MSG */
putMessageForDeliver(buffer, data.getMessage());
/* KAKAO_SENDER_KEY */
putKakaoSenderKeyForDeliver(buffer, data.getKakaoSenderKey());
/* KAKAO_TEMPLATE_CODE */
putKakaoTemplateCodeForDeliver(buffer, data.getKakaoTemplateCode());
}
public static ByteBuffer makeJsonForDeliver(String path, String fileName) {
if (path == null || fileName == null) {
return null;
}
File file = new File(path + fileName);
if (file.exists() == false) {
return null;
}
ByteBuffer fileHeadBuffer = ByteBuffer.allocate(MmsMessage.DELIVER_MMS_FILENAME_LENGTH + MmsMessage.DELIVER_MMS_FILESIZE_LENGTH);
fileHeadBuffer.put(DELIVER_JSON_FILENAME_POSITION, fileName.getBytes());
fileHeadBuffer.put(DELIVER_JSON_FILESIZE_POSITION, String.valueOf(file.length()).getBytes());
ByteBuffer fileBodyBuffer = ByteBuffer.allocate((int) file.length());
ByteBuffer fileBuffer = null;
try {
fileBodyBuffer.put(Files.readAllBytes(file.toPath()));
fileBuffer = ByteBuffer.allocate(fileHeadBuffer.capacity() + fileBodyBuffer.capacity());
Packet.mergeBuffers(fileBuffer, fileHeadBuffer, fileBodyBuffer);
} catch (IOException e) {}
return fileBuffer;
}
}

View File

@ -6,7 +6,7 @@ import com.munjaon.client.util.CommonUtil;
import java.nio.ByteBuffer;
public final class LmsMessage {
public static final int DELIVER_LMS_BODY_LENGTH = 2091;
public static final int DELIVER_LMS_BODY_LENGTH = 2129;
public static final int DELIVER_LMS_ACK_BODY_LENGTH = 21;
/* DELIVER */

View File

@ -3,7 +3,10 @@ package com.munjaon.client.server.packet;
import com.munjaon.client.model.MunjaonMsg;
import com.munjaon.client.util.CommonUtil;
import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.file.Files;
public final class MmsMessage {
public static final int LIMIT_FILE_CAPACITY = 1024 * 300;
@ -14,7 +17,7 @@ public final class MmsMessage {
public static final int DELIVER_MMS_FILESIZE_LENGTH = 8;
public static final int DELIVER_MMS_FILESIZE_POSITION = DELIVER_MMS_FILENAME_POSITION + DELIVER_MMS_FILENAME_LENGTH;
public static final int DELIVER_MMS_BODY_LENGTH = 2092;
public static final int DELIVER_MMS_BODY_LENGTH = 2130;
public static final int DELIVER_MMS_ACK_BODY_LENGTH = 21;
/* DELIVER */
@ -110,4 +113,26 @@ public final class MmsMessage {
/* FileCount */
putFileCountForDeliver(buffer, data.getFileCount());
}
public static ByteBuffer makeImageForDeliver(String path, String fileName) {
if (path == null || fileName == null) {
return null;
}
File file = new File(path + fileName);
if (file.exists() == false) {
return null;
}
ByteBuffer fileHeadBuffer = ByteBuffer.allocate(MmsMessage.DELIVER_MMS_FILENAME_LENGTH + MmsMessage.DELIVER_MMS_FILESIZE_LENGTH);
fileHeadBuffer.put(DELIVER_MMS_FILENAME_POSITION, fileName.getBytes());
fileHeadBuffer.put(DELIVER_MMS_FILESIZE_POSITION, String.valueOf(file.length()).getBytes());
ByteBuffer fileBodyBuffer = ByteBuffer.allocate((int) file.length());
ByteBuffer fileBuffer = null;
try {
fileBodyBuffer.put(Files.readAllBytes(file.toPath()));
fileBuffer = ByteBuffer.allocate(fileHeadBuffer.capacity() + fileBodyBuffer.capacity());
Packet.mergeBuffers(fileBuffer, fileHeadBuffer, fileBodyBuffer);
} catch (IOException e) {}
return fileBuffer;
}
}

View File

@ -12,6 +12,7 @@ public final class SmsMessage {
/* DELIVER */
/* MESSAGE */
public static final int DELIVER_MESSAGE_TRANS_LENGTH = 90;
public static final int DELIVER_MESSAGE_LENGTH = 160;
public static final int DELIVER_MESSAGE_POSITION = CommonMessage.DELIVER_MSG_TYPE_POSITION + CommonMessage.DELIVER_MSG_TYPE_LENGTH;

View File

@ -4,6 +4,7 @@ import com.munjaon.client.model.MunjaonMsg;
import com.munjaon.client.server.config.ErrorCode;
import com.munjaon.client.server.packet.*;
import com.munjaon.client.service.DatabaseTypeWorker;
import com.munjaon.client.util.MessageCheckUtil;
import com.munjaon.client.util.MessageUtil;
import org.json.simple.JSONObject;
@ -34,23 +35,28 @@ public class CollectClientService extends Service {
public void checkReady() {
worker = DatabaseTypeWorker.find(System.getProperty("DBMS"));
if (worker == null) {
saveSystemLog("[checkReady][DBMS : " + System.getProperty("DBMS") + " is not ready]");
return;
}
saveSystemLog("[checkReady][DBMS : " + System.getProperty("DBMS") + " is ready]");
this.IS_READY_YN = worker.checkTableExists();
}
@Override
public void initResources() {
saveSystemLog("Resource is initializing ... ...");
this.address = getProp("HOST");
this.port = Integer.parseInt(getProp("DELIVER.PORT"));
this.id = getProp("ID");
this.pwd = getProp("PASSWORD");
saveSystemLog("Try Connect to " + this.address + ":" + this.port);
saveSystemLog("Try Connect to [ADDRESS : " + this.address + "] [PORT : " + this.port + "] [ID : " + this.id + "]");
try {
socketChannel = SocketChannel.open(new InetSocketAddress(this.address, this.port));
socketChannel.configureBlocking(false);
} catch (IOException e) {
saveSystemLog("Connect Fail " + this.address + ":" + this.port);
saveSystemLog("Connect Fail to [ADDRESS : " + this.address + "] [PORT : " + this.port + "] [ID : " + this.id + "]");
saveSystemLog("ERROR [" + e.getMessage() + "]");
throw new RuntimeException(e);
}
}
@ -61,6 +67,7 @@ public class CollectClientService extends Service {
try {
socketChannel.close();
} catch (IOException e) {
saveSystemLog("ERROR [" + e.getMessage() + "]");
throw new RuntimeException(e);
}
}
@ -75,6 +82,9 @@ public class CollectClientService extends Service {
messageService();
linkCheckService();
} catch (Exception e) {
saveSystemLog("ERROR [" + e.getMessage() + "]");
saveSystemLog("ERROR DETAIL");
saveSystemLog(e.toString());
throw new RuntimeException(e);
}
}
@ -84,29 +94,30 @@ public class CollectClientService extends Service {
ByteBuffer sendBuffer = Bind.makeBindBuffer(id, pwd);
ByteBuffer recvBuffer = ByteBuffer.allocate(Header.HEADER_LENGTH + Bind.BIND_ACK_BODY_LENGTH);
try {
saveSystemLog("sendBuffer " + sendBuffer.position() + ":" + sendBuffer.limit());
saveSystemLog("Bind Try Connect to " + this.address + ":" + this.port);
saveSystemLog("[BIND REQUEST] [IP : " + this.address + "] [PORT : " + this.port + "] [ID : " + this.id + "]");
socketChannel.write(sendBuffer);
saveSystemLog("Bind Read to " + this.address + ":" + this.port);
while (true) {
int recvCount = socketChannel.read(recvBuffer);
if (recvCount == -1) {
saveSystemLog("[BIND ERROR] [CONNECTION CLOSED]");
throw new RuntimeException("BIND ERROR");
} else if (recvCount > 0) {
String resultCode = Bind.getBindAckResultCode(recvBuffer);
saveSystemLog("resultCode " + resultCode);
if ("00".equals(resultCode)) {
lastPacketSendTime = System.currentTimeMillis();
saveSystemLog("Bind OK");
saveSystemLog("[BIND SUCCESS] [CONNECTION IS ESTABLISHED]");
break;
} else {
saveSystemLog("Bind FAIL");
saveSystemLog("[BIND FAIL] [RESULT CODE : " + resultCode + "]");
throw new RuntimeException("Bind FAIL");
}
}
}
} catch (Exception e) {
saveSystemLog("ERROR [" + e.getMessage() + "]");
saveSystemLog("ERROR DETAIL");
saveSystemLog(e.toString());
throw new RuntimeException(e);
}
}
@ -130,13 +141,10 @@ public class CollectClientService extends Service {
private void messageService() {
List<MunjaonMsg> list = selectToDeliver();
if (list == null || list.isEmpty()) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
try {Thread.sleep(1000);} catch (InterruptedException e) {throw new RuntimeException(e);}
return;
}
for (MunjaonMsg data : list) {
switch (this.serviceType) {
case "SMS": smsMessageService(data); break;
@ -146,28 +154,94 @@ public class CollectClientService extends Service {
case "KFT": kftMessageService(data); break;
default:break;
}
}
}
private void lmsMessageService(MunjaonMsg data) {
if (data == null) {
return;
}
ByteBuffer sendBuffer = ByteBuffer.allocate(Header.HEADER_LENGTH + LmsMessage.DELIVER_LMS_BODY_LENGTH);
ByteBuffer recvBuffer = ByteBuffer.allocate(Header.HEADER_LENGTH + LmsMessage.DELIVER_LMS_ACK_BODY_LENGTH);
private void smsMessageService(MunjaonMsg data) {
try {
Header.putHeader(sendBuffer, Header.COMMAND_DELIVER, LmsMessage.DELIVER_LMS_BODY_LENGTH);
LmsMessage.makeDataForDeliver(sendBuffer, data);
saveSystemLog("Deliver Send");
/* 공통 메시지 유효성 체크 */
int checkCommonCode = MessageCheckUtil.validateMessageForCommon(data);
int checkMsgCode = MessageCheckUtil.validateMessageForSms(data);
if (checkCommonCode != ErrorCode.OK.getCode() || checkMsgCode != ErrorCode.OK.getCode()) {
saveSystemLog("[MESSAGE FILTER] [COMMON_CODE : " + checkCommonCode + "] [MSG_CODE : " + checkMsgCode + "]");
saveSystemLog("[MESSAGE DATA : " + data.toString() + "]");
/* 전송처리 */
worker.updateToDeliver(data.getMsgId());
/* 실패처리 */
MunjaonMsg errorMsg = null;
if (checkCommonCode != ErrorCode.OK.getCode()) {
errorMsg = MessageCheckUtil.setReportMessage(data.getMsgId(), "00", String.valueOf(checkCommonCode), MessageUtil.getTime(), "ETC");;
} else {
errorMsg = MessageCheckUtil.setReportMessage(data.getMsgId(), "00", String.valueOf(checkMsgCode), MessageUtil.getTime(), "ETC");;
}
worker.updateToReport(errorMsg);
/* 처리완료 */
return;
}
/* 정상인 경우 메시지 전송 */
ByteBuffer sendBuffer = ByteBuffer.allocate(Header.HEADER_LENGTH + SmsMessage.DELIVER_SMS_BODY_LENGTH);
ByteBuffer recvBuffer = ByteBuffer.allocate(Header.HEADER_LENGTH + SmsMessage.DELIVER_SMS_ACK_BODY_LENGTH);
Header.putHeader(sendBuffer, Header.COMMAND_DELIVER, SmsMessage.DELIVER_SMS_BODY_LENGTH);
SmsMessage.makeDataForDeliver(sendBuffer, data);
saveSystemLog("[MESSAGE SEND] [... ...]");
saveSystemLog("[MESSAGE DATA : " + data.toString() + "]");
socketChannel.write(sendBuffer);
while (true) {
int recvCount = socketChannel.read(recvBuffer);
if (recvCount == -1) {
saveSystemLog("[MESSAGE SEND] [FAIL] [SOCKET IS CLOSED]");
throw new RuntimeException("DELIVER ERROR");
} else if (recvCount > 0) {
worker.updateToDeliver(data.getMsgId());
saveSystemLog("Deliver OK");
saveSystemLog("[MESSAGE SEND] [SUCCESS]");
lastPacketSendTime = System.currentTimeMillis();
break;
}
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
private void lmsMessageService(MunjaonMsg data) {
try {
/* 공통 메시지 유효성 체크 */
int checkCommonCode = MessageCheckUtil.validateMessageForCommon(data);
int checkMsgCode = MessageCheckUtil.validateMessageForMedia(data);
if (checkCommonCode != ErrorCode.OK.getCode() || checkMsgCode != ErrorCode.OK.getCode()) {
saveSystemLog("[MESSAGE FILTER] [COMMON_CODE : " + checkCommonCode + "] [MSG_CODE : " + checkMsgCode + "]");
saveSystemLog("[MESSAGE DATA : " + data.toString() + "]");
/* 전송처리 */
worker.updateToDeliver(data.getMsgId());
/* 실패처리 */
MunjaonMsg errorMsg = null;
if (checkCommonCode != ErrorCode.OK.getCode()) {
errorMsg = MessageCheckUtil.setReportMessage(data.getMsgId(), "00", String.valueOf(checkCommonCode), MessageUtil.getTime(), "ETC");;
} else {
errorMsg = MessageCheckUtil.setReportMessage(data.getMsgId(), "00", String.valueOf(checkMsgCode), MessageUtil.getTime(), "ETC");;
}
worker.updateToReport(errorMsg);
/* 처리완료 */
return;
}
/* 정상인 경우 메시지 전송 */
ByteBuffer sendBuffer = ByteBuffer.allocate(Header.HEADER_LENGTH + LmsMessage.DELIVER_LMS_BODY_LENGTH);
ByteBuffer recvBuffer = ByteBuffer.allocate(Header.HEADER_LENGTH + LmsMessage.DELIVER_LMS_ACK_BODY_LENGTH);
Header.putHeader(sendBuffer, Header.COMMAND_DELIVER, LmsMessage.DELIVER_LMS_BODY_LENGTH);
LmsMessage.makeDataForDeliver(sendBuffer, data);
saveSystemLog("[MESSAGE SEND] [... ...]");
saveSystemLog("[MESSAGE DATA : " + data.toString() + "]");
socketChannel.write(sendBuffer);
while (true) {
int recvCount = socketChannel.read(recvBuffer);
if (recvCount == -1) {
saveSystemLog("[MESSAGE SEND] [FAIL] [SOCKET IS CLOSED]");
throw new RuntimeException("DELIVER ERROR");
} else if (recvCount > 0) {
worker.updateToDeliver(data.getMsgId());
saveSystemLog("[MESSAGE SEND] [SUCCESS]");
lastPacketSendTime = System.currentTimeMillis();
break;
}
@ -178,68 +252,65 @@ public class CollectClientService extends Service {
}
private void mmsMessageService(MunjaonMsg data) {
if (data == null) {
return;
}
ByteBuffer sendBuffer = ByteBuffer.allocate(Header.HEADER_LENGTH + MmsMessage.DELIVER_MMS_BODY_LENGTH);
ByteBuffer recvBuffer = ByteBuffer.allocate(Header.HEADER_LENGTH + MmsMessage.DELIVER_MMS_ACK_BODY_LENGTH);
try {
/* MMS Image 저장 경로 */
String path = System.getProperty("ROOTPATH") + File.separator + "mmsfile" + File.separator;
int fileCount = 0;
int errorCode = validateErrorCodeForMms(data);
if (errorCode != ErrorCode.OK.getCode()) {
MunjaonMsg errorMsg = new MunjaonMsg();
errorMsg.setMsgId(data.getMsgId());
errorMsg.setAgentCode("00");
errorMsg.setSendStatus(String.valueOf(errorCode));
errorMsg.setSendDate(MessageUtil.getTime());
errorMsg.setTelecom("ETC");
/* 공통 메시지 유효성 체크 */
int checkCommonCode = MessageCheckUtil.validateMessageForCommon(data);
int checkMsgCode = MessageCheckUtil.validateMessageForMedia(data);
int checkImageCode = MessageCheckUtil.validateMessageForImage(data, path);
if (checkCommonCode != ErrorCode.OK.getCode() || checkMsgCode != ErrorCode.OK.getCode() || checkImageCode != ErrorCode.OK.getCode()) {
saveSystemLog("[MESSAGE FILTER] [COMMON_CODE : " + checkCommonCode + "] [MSG_CODE : " + checkMsgCode + "] [IMAGE_CODE : " + checkImageCode + "]");
saveSystemLog("[MESSAGE DATA : " + data.toString() + "]");
/* 전송처리 */
worker.updateToDeliver(data.getMsgId());
/* 실패처리 */
MunjaonMsg errorMsg = null;
if (checkCommonCode != ErrorCode.OK.getCode()) {
errorMsg = MessageCheckUtil.setReportMessage(data.getMsgId(), "00", String.valueOf(checkCommonCode), MessageUtil.getTime(), "ETC");
}else if (checkMsgCode != ErrorCode.OK.getCode()) {
errorMsg = MessageCheckUtil.setReportMessage(data.getMsgId(), "00", String.valueOf(checkMsgCode), MessageUtil.getTime(), "ETC");
} else {
errorMsg = MessageCheckUtil.setReportMessage(data.getMsgId(), "00", String.valueOf(checkImageCode), MessageUtil.getTime(), "ETC");
}
worker.updateToReport(errorMsg);
/* 처리완료 */
return;
}
/* 정상인 경우 메시지 전송 */
ByteBuffer sendBuffer = ByteBuffer.allocate(Header.HEADER_LENGTH + MmsMessage.DELIVER_MMS_BODY_LENGTH);
ByteBuffer recvBuffer = ByteBuffer.allocate(Header.HEADER_LENGTH + MmsMessage.DELIVER_MMS_ACK_BODY_LENGTH);
int fileCount = 0;
/* File check */
ByteBuffer file01Buffer = null;
if (data.getFilename01() != null) {
File file = new File(path + data.getFilename01());
if (file.exists()) {
fileCount++;
ByteBuffer fileHeadBuffer = ByteBuffer.allocate(MmsMessage.DELIVER_MMS_FILENAME_LENGTH + MmsMessage.DELIVER_MMS_FILESIZE_LENGTH);
ByteBuffer fileBodyBuffer = ByteBuffer.allocate((int) file.length());
fileBodyBuffer.put(Files.readAllBytes(file.toPath()));
file01Buffer = ByteBuffer.allocate(fileHeadBuffer.capacity() + fileBodyBuffer.capacity());
Packet.mergeBuffers(file01Buffer, fileHeadBuffer, fileBodyBuffer);
}
ByteBuffer file01Buffer = MmsMessage.makeImageForDeliver(path, data.getFilename01());
if (file01Buffer != null) {
saveSystemLog("file01Buffer : " + file01Buffer.capacity());
}
ByteBuffer file02Buffer = null;
if (data.getFilename02() != null) {
File file = new File(path + data.getFilename02());
if (file.exists()) {
fileCount++;
ByteBuffer fileHeadBuffer = ByteBuffer.allocate(MmsMessage.DELIVER_MMS_FILENAME_LENGTH + MmsMessage.DELIVER_MMS_FILESIZE_LENGTH);
ByteBuffer fileBodyBuffer = ByteBuffer.allocate((int) file.length());
fileBodyBuffer.put(Files.readAllBytes(file.toPath()));
file02Buffer = ByteBuffer.allocate(fileHeadBuffer.capacity() + fileBodyBuffer.capacity());
Packet.mergeBuffers(file02Buffer, fileHeadBuffer, fileBodyBuffer);
}
if (file01Buffer != null) {
fileCount++;
}
ByteBuffer file03Buffer = null;
if (data.getFilename03() != null) {
File file = new File(path + data.getFilename03());
if (file.exists()) {
fileCount++;
ByteBuffer fileHeadBuffer = ByteBuffer.allocate(MmsMessage.DELIVER_MMS_FILENAME_LENGTH + MmsMessage.DELIVER_MMS_FILESIZE_LENGTH);
ByteBuffer fileBodyBuffer = ByteBuffer.allocate((int) file.length());
fileBodyBuffer.put(Files.readAllBytes(file.toPath()));
file03Buffer = ByteBuffer.allocate(fileHeadBuffer.capacity() + fileBodyBuffer.capacity());
Packet.mergeBuffers(file03Buffer, fileHeadBuffer, fileBodyBuffer);
}
ByteBuffer file02Buffer = MmsMessage.makeImageForDeliver(path, data.getFilename02());
if (file02Buffer != null) {
saveSystemLog("file02Buffer : " + file02Buffer.capacity());
}
if (file02Buffer != null) {
fileCount++;
}
ByteBuffer file03Buffer = MmsMessage.makeImageForDeliver(path, data.getFilename03());
if (file03Buffer != null) {
saveSystemLog("file03Buffer : " + file03Buffer.capacity());
}
if (file03Buffer != null) {
fileCount++;
}
/* fileCount 저장 */
data.setFileCount(fileCount);
Header.putHeader(sendBuffer, Header.COMMAND_DELIVER, MmsMessage.DELIVER_MMS_BODY_LENGTH);
MmsMessage.makeDataForDeliver(sendBuffer, data);
saveSystemLog("Deliver Send");
saveSystemLog("[MESSAGE SEND] [... ...]");
saveSystemLog("[MESSAGE DATA : " + data.toString() + "]");
ByteBuffer[] byteBuffers = new ByteBuffer[fileCount + 1];
int index = 0;
@ -263,96 +334,142 @@ public class CollectClientService extends Service {
while (true) {
int recvCount = socketChannel.read(recvBuffer);
if (recvCount == -1) {
saveSystemLog("[MESSAGE SEND] [FAIL] [SOCKET IS CLOSED]");
throw new RuntimeException("DELIVER ERROR");
} else if (recvCount > 0) {
worker.updateToDeliver(data.getMsgId());
saveSystemLog("Deliver OK");
saveSystemLog("[MESSAGE SEND] [SUCCESS]");
lastPacketSendTime = System.currentTimeMillis();
break;
}
}
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
private int validateErrorCodeForMms(MunjaonMsg data) {
if (data == null) {
return ErrorCode.ERROR_DATA_IS_NULL.getCode();
}
if (data.getSubject() == null) {
return ErrorCode.ERROR_SUBJECT_IS_NULL.getCode();
}
if (data.getMessage() == null) {
return ErrorCode.ERROR_MESSAGE_IS_NULL.getCode();
}
/* 파일 체크 */
String path = System.getProperty("ROOTPATH") + File.separator + "mmsfile" + File.separator;
int fileCount = 0;
if (data.getFilename01() != null) {
File file = new File(path + data.getFilename01());
if (file.exists()) {
if (file.length() > MmsMessage.LIMIT_FILE_CAPACITY) {
return ErrorCode.ERROR_FILE_CAPACITY_EXCEED.getCode();
} else {
fileCount++;
}
}
}
if (data.getFilename02() != null) {
File file = new File(path + data.getFilename02());
if (file.exists()) {
if (file.length() > MmsMessage.LIMIT_FILE_CAPACITY) {
return ErrorCode.ERROR_FILE_CAPACITY_EXCEED.getCode();
} else {
fileCount++;
}
}
}
if (data.getFilename03() != null) {
File file = new File(path + data.getFilename03());
if (file.exists()) {
if (file.length() > MmsMessage.LIMIT_FILE_CAPACITY) {
return ErrorCode.ERROR_FILE_CAPACITY_EXCEED.getCode();
} else {
fileCount++;
}
}
}
if (fileCount == 0) {
return ErrorCode.ERROR_FILE_NOT_FOUND.getCode();
}
return ErrorCode.OK.getCode();
}
private void katMessageService(MunjaonMsg data) {
}
private void kftMessageService(MunjaonMsg data) {
}
private void smsMessageService(MunjaonMsg data) {
ByteBuffer sendBuffer = ByteBuffer.allocate(Header.HEADER_LENGTH + SmsMessage.DELIVER_SMS_BODY_LENGTH);
ByteBuffer recvBuffer = ByteBuffer.allocate(Header.HEADER_LENGTH + SmsMessage.DELIVER_SMS_ACK_BODY_LENGTH);
try {
Header.putHeader(sendBuffer, Header.COMMAND_DELIVER, SmsMessage.DELIVER_SMS_BODY_LENGTH);
SmsMessage.makeDataForDeliver(sendBuffer, data);
saveSystemLog("Deliver Send");
socketChannel.write(sendBuffer);
/* Kakao Json 저장 경로 */
String path = System.getProperty("ROOTPATH") + File.separator + "kakaofile" + File.separator;
/* 공통 메시지 유효성 체크 */
int checkCommonCode = MessageCheckUtil.validateMessageForCommon(data);
int checkMsgCode = MessageCheckUtil.validateMessageForKakao(data);
int checkFileCode = MessageCheckUtil.validateJsonFile(path, data.getKakaoJsonFile());
if (checkCommonCode != ErrorCode.OK.getCode() || checkMsgCode != ErrorCode.OK.getCode() || checkFileCode != ErrorCode.OK.getCode()) {
saveSystemLog("[MESSAGE FILTER] [COMMON_CODE : " + checkCommonCode + "] [MSG_CODE : " + checkMsgCode + "] [JSON_FILE_CODE : " + checkFileCode + "]");
saveSystemLog("[MESSAGE DATA : " + data.toString() + "]");
/* 전송처리 */
worker.updateToDeliver(data.getMsgId());
/* 실패처리 */
MunjaonMsg errorMsg = null;
if (checkCommonCode != ErrorCode.OK.getCode()) {
errorMsg = MessageCheckUtil.setReportMessage(data.getMsgId(), "00", String.valueOf(checkCommonCode), MessageUtil.getTime(), "ETC");
}else if (checkMsgCode != ErrorCode.OK.getCode()) {
errorMsg = MessageCheckUtil.setReportMessage(data.getMsgId(), "00", String.valueOf(checkMsgCode), MessageUtil.getTime(), "ETC");
} else {
errorMsg = MessageCheckUtil.setReportMessage(data.getMsgId(), "00", String.valueOf(checkFileCode), MessageUtil.getTime(), "ETC");
}
worker.updateToReport(errorMsg);
/* 처리완료 */
return;
}
/* 정상인 경우 메시지 전송 */
ByteBuffer sendBuffer = ByteBuffer.allocate(Header.HEADER_LENGTH + KakaoMessage.DELIVER_KAKAO_BODY_LENGTH);
ByteBuffer recvBuffer = ByteBuffer.allocate(Header.HEADER_LENGTH + KakaoMessage.DELIVER_KAKAO_ACK_BODY_LENGTH);
/* File check */
ByteBuffer fileBuffer = KakaoMessage.makeJsonForDeliver(path, data.getKakaoJsonFile());
Header.putHeader(sendBuffer, Header.COMMAND_DELIVER, KakaoMessage.DELIVER_KAKAO_BODY_LENGTH);
KakaoMessage.makeDataForDeliver(sendBuffer, data);
saveSystemLog("[MESSAGE SEND] [... ...]");
saveSystemLog("[MESSAGE DATA : " + data.toString() + "]");
ByteBuffer[] byteBuffers = new ByteBuffer[2];
byteBuffers[0] = sendBuffer;
byteBuffers[1] = fileBuffer;
socketChannel.write(byteBuffers);
while (true) {
int recvCount = socketChannel.read(recvBuffer);
if (recvCount == -1) {
saveSystemLog("[MESSAGE SEND] [FAIL] [SOCKET IS CLOSED]");
throw new RuntimeException("DELIVER ERROR");
} else if (recvCount > 0) {
worker.updateToDeliver(data.getMsgId());
saveSystemLog("Deliver OK");
saveSystemLog("[MESSAGE SEND] [SUCCESS]");
lastPacketSendTime = System.currentTimeMillis();
break;
}
}
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
private void kftMessageService(MunjaonMsg data) {
try {
/* Kakao Json 저장 경로 */
String path = System.getProperty("ROOTPATH") + File.separator + "kakaofile" + File.separator;
/* 공통 메시지 유효성 체크 */
int checkCommonCode = MessageCheckUtil.validateMessageForCommon(data);
int checkMsgCode = MessageCheckUtil.validateMessageForKakao(data);
int checkFileCode = MessageCheckUtil.validateJsonFile(path, data.getKakaoJsonFile());
if (checkCommonCode != ErrorCode.OK.getCode() || checkMsgCode != ErrorCode.OK.getCode() || checkFileCode != ErrorCode.OK.getCode()) {
saveSystemLog("[MESSAGE FILTER] [COMMON_CODE : " + checkCommonCode + "] [MSG_CODE : " + checkMsgCode + "] [JSON_FILE_CODE : " + checkFileCode + "]");
saveSystemLog("[MESSAGE DATA : " + data.toString() + "]");
/* 전송처리 */
worker.updateToDeliver(data.getMsgId());
/* 실패처리 */
MunjaonMsg errorMsg = null;
if (checkCommonCode != ErrorCode.OK.getCode()) {
errorMsg = MessageCheckUtil.setReportMessage(data.getMsgId(), "00", String.valueOf(checkCommonCode), MessageUtil.getTime(), "ETC");
}else if (checkMsgCode != ErrorCode.OK.getCode()) {
errorMsg = MessageCheckUtil.setReportMessage(data.getMsgId(), "00", String.valueOf(checkMsgCode), MessageUtil.getTime(), "ETC");
} else {
errorMsg = MessageCheckUtil.setReportMessage(data.getMsgId(), "00", String.valueOf(checkFileCode), MessageUtil.getTime(), "ETC");
}
worker.updateToReport(errorMsg);
/* 처리완료 */
return;
}
/* 정상인 경우 메시지 전송 */
ByteBuffer sendBuffer = ByteBuffer.allocate(Header.HEADER_LENGTH + KakaoMessage.DELIVER_KAKAO_BODY_LENGTH);
ByteBuffer recvBuffer = ByteBuffer.allocate(Header.HEADER_LENGTH + KakaoMessage.DELIVER_KAKAO_ACK_BODY_LENGTH);
/* File check */
ByteBuffer fileBuffer = KakaoMessage.makeJsonForDeliver(path, data.getKakaoJsonFile());
Header.putHeader(sendBuffer, Header.COMMAND_DELIVER, KakaoMessage.DELIVER_KAKAO_BODY_LENGTH);
KakaoMessage.makeDataForDeliver(sendBuffer, data);
saveSystemLog("[MESSAGE SEND] [... ...]");
saveSystemLog("[MESSAGE DATA : " + data.toString() + "]");
ByteBuffer[] byteBuffers = new ByteBuffer[2];
byteBuffers[0] = sendBuffer;
byteBuffers[1] = fileBuffer;
socketChannel.write(byteBuffers);
while (true) {
int recvCount = socketChannel.read(recvBuffer);
if (recvCount == -1) {
saveSystemLog("[MESSAGE SEND] [FAIL] [SOCKET IS CLOSED]");
throw new RuntimeException("DELIVER ERROR");
} else if (recvCount > 0) {
worker.updateToDeliver(data.getMsgId());
saveSystemLog("[MESSAGE SEND] [SUCCESS]");
lastPacketSendTime = System.currentTimeMillis();
break;
}
}
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
@ -365,14 +482,15 @@ public class CollectClientService extends Service {
ByteBuffer recvBuffer = ByteBuffer.allocate(Header.HEADER_LENGTH + LinkCheck.LINK_CHECK_ACK_BODY_LENGTH);
try {
saveSystemLog("LinkCheck Send");
saveSystemLog("[LINK_CHECK SEND] [... ...]");
socketChannel.write(LinkCheck.makeLinkCheckBuffer());
while (true) {
int recvCount = socketChannel.read(recvBuffer);
if (recvCount == -1) {
saveSystemLog("[LINK_CHECK SEND] [FAIL] [SOCKET IS CLOSED]");
throw new RuntimeException("LINK_CHECK ERROR");
} else if (recvCount > 0) {
saveSystemLog("LinkCheck OK");
saveSystemLog("[LINK_CHECK SEND] [SUCCESS]");
lastPacketSendTime = System.currentTimeMillis();
break;
}

View File

@ -33,8 +33,11 @@ public class ReportClientService extends Service {
public void checkReady() {
worker = DatabaseTypeWorker.find(System.getProperty("DBMS"));
if (worker == null) {
saveSystemLog("[checkReady][DBMS : " + System.getProperty("DBMS") + " is not ready]");
return;
}
saveSystemLog("[checkReady][DBMS : " + System.getProperty("DBMS") + " is ready]");
this.IS_READY_YN = worker.checkTableExists();
}
@ -44,12 +47,15 @@ public class ReportClientService extends Service {
this.port = Integer.parseInt(getProp("PORT"));
this.id = getProp("ID");
this.pwd = getProp("PASSWORD");
saveSystemLog("Try Connect to " + this.address + ":" + this.port);
saveSystemLog("Try Connect to [ADDRESS : " + this.address + "] [PORT : " + this.port + "] [ID : " + this.id + "]");
try {
socketChannel = SocketChannel.open(new InetSocketAddress(this.address, this.port));
socketChannel.configureBlocking(false);
} catch (IOException e) {
saveSystemLog("Connect Fail " + this.address + ":" + this.port);
saveSystemLog("Connect Fail to [ADDRESS : " + this.address + "] [PORT : " + this.port + "] [ID : " + this.id + "]");
saveSystemLog("ERROR [" + e.getMessage() + "]");
saveSystemLog("ERROR DETAIL");
saveSystemLog(e.toString());
throw new RuntimeException(e);
}
}
@ -60,6 +66,9 @@ public class ReportClientService extends Service {
try {
socketChannel.close();
} catch (IOException e) {
saveSystemLog("ERROR [" + e.getMessage() + "]");
saveSystemLog("ERROR DETAIL");
saveSystemLog(e.toString());
throw new RuntimeException(e);
}
}

View File

@ -108,7 +108,7 @@ public abstract class Service extends Thread {
initLogFile();
/* 3. Runflag reload */
reloadCheckRun();
saveSystemLog("[SERVICE_READY : " + IS_READY_YN + " || SERVICE_RUN : " + IS_RUN_YN);
if (isRun() && isReady()) {
/* 3. 서비스 초기화 */
initResources();
@ -116,9 +116,9 @@ public abstract class Service extends Thread {
doService();
/* 5. 서비스 자원 해제 */
releaseResources();
saveSystemLog("Service Stopped.");
saveSystemLog("[SERVICE IS STOPPED] [... ...]");
} else {
saveSystemLog("Service is Not Running.");
saveSystemLog("[SERVICE IS NOT RUNNING] [... ...]");
}
/* 6. 3초간 sleep */
Thread.sleep(3000);

View File

@ -0,0 +1,277 @@
package com.munjaon.client.util;
import com.munjaon.client.model.MunjaonMsg;
import com.munjaon.client.server.config.ErrorCode;
import com.munjaon.client.server.packet.*;
import java.io.File;
public class MessageCheckUtil {
public static int validateMessageForCommon(MunjaonMsg data) {
int code = isNullMessageForCommon(data);
if (code != ErrorCode.OK.getCode()) {
return code;
}
return isLengthMessageForCommon(data);
}
public static int isLengthMessageForCommon(MunjaonMsg data) {
/* MSG_ID */
String value = data.getMsgId().trim();
if (value.length() == 0 || value.getBytes().length > CommonMessage.DELIVER_MESSAGE_ID_LENGTH) {
return ErrorCode.ERROR_MSGID_IS_CAPACITY.getCode();
}
/* SENDER */
value = MessageUtil.doNumber(data.getSendPhone());
if (value.getBytes().length < 8 || value.getBytes().length > CommonMessage.DELIVER_SENDER_LENGTH) {
return ErrorCode.ERROR_SENDER_IS_CAPACITY.getCode();
}
/* RECEIVER */
value = MessageUtil.doNumber(data.getRecvPhone());
if (value.getBytes().length < 10 || value.getBytes().length > CommonMessage.DELIVER_RECEIVER_LENGTH) {
return ErrorCode.ERROR_RECEIVER_IS_CAPACITY.getCode();
}
if ("01".equals(value.substring(0, 2)) == false) {
return ErrorCode.ERROR_RECEIVER_IS_INVALID.getCode();
}
return ErrorCode.OK.getCode();
}
public static int isNullMessageForCommon(MunjaonMsg data) {
if (data == null) {
return ErrorCode.ERROR_DATA_IS_NULL.getCode();
}
if (data.getMsgId() == null || data.getMsgId().isEmpty()) {
return ErrorCode.ERROR_MSGID_IS_NULL.getCode();
}
if (data.getSendPhone() == null || data.getSendPhone().isEmpty()) {
return ErrorCode.ERROR_SENDER_IS_NULL.getCode();
}
if (data.getRecvPhone() == null || data.getRecvPhone().isEmpty()) {
return ErrorCode.ERROR_RECEIVER_IS_NULL.getCode();
}
return ErrorCode.OK.getCode();
}
public static int validateMessageForSms(MunjaonMsg data) {
if (data.getMessage() == null || data.getMessage().isEmpty()) {
return ErrorCode.ERROR_SMS_MSG_IS_NULL.getCode();
}
if (data.getMessage().getBytes().length > SmsMessage.DELIVER_MESSAGE_TRANS_LENGTH) {
return ErrorCode.ERROR_SMS_MSG_IS_CAPACITY.getCode();
}
return ErrorCode.OK.getCode();
}
public static int validateMessageForMedia(MunjaonMsg data) {
if (data == null) {
return ErrorCode.ERROR_DATA_IS_NULL.getCode();
}
if (data.getSubject() == null) {
return ErrorCode.ERROR_SUBJECT_IS_NULL.getCode();
}
if (data.getMessage() == null) {
return ErrorCode.ERROR_MULTI_MESSAGE_IS_NULL.getCode();
}
if (data.getSubject().getBytes().length > LmsMessage.DELIVER_SUBJECT_LENGTH) {
return ErrorCode.ERROR_SUBJECT_OVER_CAPACITY.getCode();
}
if (data.getMessage().getBytes().length > LmsMessage.DELIVER_MESSAGE_LENGTH) {
return ErrorCode.ERROR_MULTI_MESSAGE_OVER_CAPACITY.getCode();
}
return ErrorCode.OK.getCode();
}
public static int validateMessageForImage(MunjaonMsg data, String path) {
if (imageFileCount(data) == 0) {
return ErrorCode.ERROR_MMS_IMAGE_IS_NULL.getCode();
}
if (imageExtErrorCount(data) > 0) {
return ErrorCode.ERROR_MMS_IMAGE_IS_EXT.getCode();
}
if (imagePathErrorCount(data, path) > 0) {
return ErrorCode.ERROR_MMS_IMAGE_IS_NOT_PATH.getCode();
}
if (imageSizeErrorCount(data, path) > 0) {
return ErrorCode.ERROR_MMS_IMAGE_IS_OVER_CAPACITY.getCode();
}
return ErrorCode.OK.getCode();
}
public static int imageSizeErrorCount(MunjaonMsg data, String path) {
int errorCount = 0;
if (data.getFilename01() != null) {
File file = new File(path + data.getFilename01());
if (file.length() > MmsMessage.LIMIT_FILE_CAPACITY) {
errorCount++;
}
}
if (data.getFilename02() != null) {
File file = new File(path + data.getFilename02());
if (file.length() > MmsMessage.LIMIT_FILE_CAPACITY) {
errorCount++;
}
}
if (data.getFilename03() != null) {
File file = new File(path + data.getFilename03());
if (file.length() > MmsMessage.LIMIT_FILE_CAPACITY) {
errorCount++;
}
}
return errorCount;
}
public static int imagePathErrorCount(MunjaonMsg data, String path) {
int errorCount = 0;
if (data.getFilename01() != null) {
File file = new File(path + data.getFilename01());
if (file.exists() == false) {
errorCount++;
}
}
if (data.getFilename02() != null) {
File file = new File(path + data.getFilename02());
if (file.exists() == false) {
errorCount++;
}
}
if (data.getFilename03() != null) {
File file = new File(path + data.getFilename03());
if (file.exists() == false) {
errorCount++;
}
}
return errorCount;
}
public static int imageExtErrorCount(MunjaonMsg data) {
int errorCount = 0;
if (data.getFilename01() != null && checkImageFileForExtension(data.getFilename01()) == false) {
errorCount++;
}
if (data.getFilename02() != null && checkImageFileForExtension(data.getFilename02()) == false) {
errorCount++;
}
if (data.getFilename03() != null && checkImageFileForExtension(data.getFilename03()) == false) {
errorCount++;
}
return errorCount;
}
public static int imageFileCount(MunjaonMsg data) {
if (data == null) {
return 0;
}
int count = 0;
if (data.getFilename01() != null) {
count++;
}
if (data.getFilename02() != null) {
count++;
}
if (data.getFilename03() != null) {
count++;
}
return count;
}
public static boolean checkImageFileForExtension(String fileName) {
int lastIndex = fileName.lastIndexOf(".");
if (lastIndex == -1) {
return false;
}
String extension = fileName.substring(lastIndex + 1).toUpperCase();
if ("JPG".equals(extension) || "PNG".equals(extension) || "GIF".equals(extension) || "JPEG".equals(extension)) {
return true;
}
return false;
}
public static int validateMessageForKakao(MunjaonMsg data) {
if (data == null) {
return ErrorCode.ERROR_DATA_IS_NULL.getCode();
}
if (data.getSubject() == null) {
return ErrorCode.ERROR_SUBJECT_IS_NULL.getCode();
}
if (data.getMessage() == null) {
return ErrorCode.ERROR_MULTI_MESSAGE_IS_NULL.getCode();
}
if (data.getKakaoSenderKey() == null) {
return ErrorCode.ERROR_KAKAO_SENDER_KEY_IS_NULL.getCode();
}
if (data.getKakaoTemplateCode() == null) {
return ErrorCode.ERROR_KAKAO_TEMPLATE_CODE_IS_NULL.getCode();
}
if (data.getKakaoJsonFile() == null) {
return ErrorCode.ERROR_KAKAO_JSON_FILE_IS_NULL.getCode();
}
if (data.getSubject().getBytes().length > LmsMessage.DELIVER_SUBJECT_LENGTH) {
return ErrorCode.ERROR_SUBJECT_OVER_CAPACITY.getCode();
}
if (data.getMessage().getBytes().length > LmsMessage.DELIVER_MESSAGE_LENGTH) {
return ErrorCode.ERROR_MULTI_MESSAGE_OVER_CAPACITY.getCode();
}
if (data.getKakaoSenderKey().getBytes().length > KakaoMessage.DELIVER_KAKAO_SENDER_KEY_LENGTH) {
return ErrorCode.ERROR_KAKAO_SENDER_KEY_OVER_CAPACITY.getCode();
}
if (data.getKakaoTemplateCode().getBytes().length > KakaoMessage.DELIVER_KAKAO_TEMPLATE_CODE_LENGTH) {
return ErrorCode.ERROR_KAKAO_TEMPLATE_CODE_OVER_CAPACITY.getCode();
}
return ErrorCode.OK.getCode();
}
public static int validateJsonFile(String path, String fileName) {
int lastIndex = fileName.lastIndexOf(".");
if (lastIndex == -1) {
return ErrorCode.ERROR_KAKAO_JSON_FILE_IS_EXT.getCode();
}
String extension = fileName.substring(lastIndex + 1).toUpperCase();
if ("JSON".equals(extension) == false) {
return ErrorCode.ERROR_KAKAO_JSON_FILE_IS_EXT.getCode();
}
File file = new File(path + fileName);
if (file.exists() == false) {
return ErrorCode.ERROR_KAKAO_JSON_FILE_IS_NOT_PATH.getCode();
}
if (file.length() > KakaoMessage.LIMIT_FILE_CAPACITY) {
return ErrorCode.ERROR_KAKAO_JSON_FILE_IS_OVER_CAPACITY.getCode();
}
return ErrorCode.OK.getCode();
}
public static int validateMessageForJson(MunjaonMsg data) {
return ErrorCode.OK.getCode();
}
public static MunjaonMsg setReportMessage(String msgId, String agentCode, String sendStatus, String sendDate, String telecom) {
MunjaonMsg msg = new MunjaonMsg();
msg.setMsgId(msgId);
msg.setAgentCode(agentCode);
msg.setSendStatus(sendStatus);
msg.setSendDate(sendDate);
msg.setTelecom(telecom);
return msg;
}
public static void main(String[] args) {
String fileName = " .dat";
int lastIndex = fileName.lastIndexOf(".");
if (lastIndex < 0) {
System.out.println("EXT is not ");
} else {
System.out.println("EXT : " + fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length()));
}
System.out.println("NM :" + fileName.substring(0, lastIndex) + "<<");
}
}

View File

@ -33,6 +33,9 @@
, FILENAME01
, FILENAME02
, FILENAME03
, KAKAO_SENDER_KEY
, KAKAO_TEMPLATE_CODE
, KAKAO_JSON_FILE
FROM MUNJAON_MSG
WHERE SEND_STATUS = '0'
AND MSG_TYPE = #{msgType}