Report 기능 추가, LMS기능 추가, MMS 테스트중
This commit is contained in:
parent
8976f34e7a
commit
e38c24b416
@ -2,6 +2,7 @@ package com.munjaon.client.config;
|
||||
|
||||
import com.munjaon.client.server.service.CollectClientService;
|
||||
import com.munjaon.client.server.service.PropertyLoader;
|
||||
import com.munjaon.client.server.service.ReportClientService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.configuration2.ex.ConfigurationException;
|
||||
@ -49,4 +50,45 @@ public class RunnerConfiguration {
|
||||
}
|
||||
return args -> System.out.println("Runner Bean #2");
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Order(2)
|
||||
public CommandLineRunner getRunnerBeanForLms() {
|
||||
try {
|
||||
String serviceName = "LMS";
|
||||
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 getRunnerBeanForMms() {
|
||||
try {
|
||||
String serviceName = "MMS";
|
||||
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() {
|
||||
try {
|
||||
String serviceName = "REPORT";
|
||||
ReportClientService reportClientService = new ReportClientService(serviceName);
|
||||
reportClientService.start();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return args -> System.out.println("Runner Bean #2");
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,4 +25,5 @@ public class MunjaonMsg {
|
||||
private String deliverDate;
|
||||
private String sendDate;
|
||||
private String reportDate;
|
||||
private int fileCount = 0;
|
||||
}
|
||||
|
||||
@ -0,0 +1,37 @@
|
||||
package com.munjaon.client.server.config;
|
||||
|
||||
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_FILE_NOT_FOUND(390, "File Not Found"),
|
||||
ERROR_FILE_CAPACITY_EXCEED(391, "File capacity exceeded");
|
||||
|
||||
|
||||
|
||||
private Integer code;
|
||||
private String message;
|
||||
|
||||
ErrorCode(Integer code, String message) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public static String getMessage(Integer code) {
|
||||
if (code == null) {
|
||||
return "etc";
|
||||
}
|
||||
|
||||
for (ErrorCode resCode : values()) {
|
||||
if (resCode.getCode().equals(code)) {
|
||||
return resCode.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
return "etc";
|
||||
}
|
||||
}
|
||||
@ -23,7 +23,7 @@ public final class LinkCheck {
|
||||
public static ByteBuffer makeLinkCheckAckBuffer() {
|
||||
ByteBuffer buffer = ByteBuffer.allocate(Header.HEADER_LENGTH + LINK_CHECK_ACK_BODY_LENGTH);
|
||||
Packet.setDefaultByte(buffer);
|
||||
Header.putHeader(buffer, Header.COMMAND_LINK_CHECK, LINK_CHECK_ACK_BODY_LENGTH);
|
||||
Header.putHeader(buffer, Header.COMMAND_LINK_CHECK_ACK, LINK_CHECK_ACK_BODY_LENGTH);
|
||||
buffer.put(LINK_CHECK_ACK_BODY_POSITION, LINK_CHECK_ACK_VALUE.getBytes());
|
||||
|
||||
return buffer;
|
||||
|
||||
@ -0,0 +1,78 @@
|
||||
package com.munjaon.client.server.packet;
|
||||
|
||||
import com.munjaon.client.model.MunjaonMsg;
|
||||
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_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;
|
||||
|
||||
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 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());
|
||||
}
|
||||
}
|
||||
113
src/main/java/com/munjaon/client/server/packet/MmsMessage.java
Normal file
113
src/main/java/com/munjaon/client/server/packet/MmsMessage.java
Normal file
@ -0,0 +1,113 @@
|
||||
package com.munjaon.client.server.packet;
|
||||
|
||||
import com.munjaon.client.model.MunjaonMsg;
|
||||
import com.munjaon.client.util.CommonUtil;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public final class MmsMessage {
|
||||
public static final int LIMIT_FILE_CAPACITY = 1024 * 300;
|
||||
|
||||
public static final int DELIVER_MMS_FILENAME_LENGTH = 40;
|
||||
public static final int DELIVER_MMS_FILENAME_POSITION = 0;
|
||||
|
||||
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_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;
|
||||
/* FILECOUNT */
|
||||
public static final int DELIVER_FILECOUNT_LENGTH = 1;
|
||||
public static final int DELIVER_FILECOUNT_POSITION = DELIVER_MESSAGE_POSITION + DELIVER_MESSAGE_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 putFileCountForDeliver(ByteBuffer buffer, int fileCount) {
|
||||
putFileCountForDeliver(buffer, Integer.toString(fileCount));
|
||||
}
|
||||
|
||||
public static void putFileCountForDeliver(ByteBuffer buffer, String fileCount) {
|
||||
if (buffer == null || fileCount == null) {
|
||||
return;
|
||||
}
|
||||
buffer.put(DELIVER_FILECOUNT_POSITION, fileCount.getBytes());
|
||||
}
|
||||
public static String getFileCountForDeliver(ByteBuffer buffer) {
|
||||
if (buffer == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
buffer.position(DELIVER_FILECOUNT_POSITION);
|
||||
byte[] destArray = new byte[DELIVER_FILECOUNT_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());
|
||||
/* FileCount */
|
||||
putFileCountForDeliver(buffer, data.getFileCount());
|
||||
}
|
||||
}
|
||||
@ -4,7 +4,7 @@ import java.nio.ByteBuffer;
|
||||
|
||||
public final class Packet {
|
||||
public static final byte SET_DEFAULT_BYTE = (byte) 0x00;
|
||||
public static final long LINK_CHECK_CYCLE = 3000L;
|
||||
public static final long LINK_CHECK_CYCLE = 10000L;
|
||||
// public static final long LINK_CHECK_CYCLE = 30000L;
|
||||
|
||||
public static void setDefaultByte(ByteBuffer buffer) {
|
||||
@ -43,4 +43,33 @@ public final class Packet {
|
||||
|
||||
return destArray == null ? null : new String(destArray);
|
||||
}
|
||||
|
||||
public static void mergeBuffers(ByteBuffer dest, ByteBuffer srcHead, ByteBuffer srcBody) {
|
||||
if (dest == null || srcHead == null || srcBody == null) {
|
||||
return;
|
||||
}
|
||||
if (dest.capacity() != (srcHead.capacity() + srcBody.capacity())) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < srcHead.capacity(); i++) {
|
||||
dest.put(i, srcHead.get(i));
|
||||
}
|
||||
for (int i = 0; i < srcBody.capacity(); i++) {
|
||||
dest.put((i + srcHead.capacity()), srcBody.get(i));
|
||||
}
|
||||
// byte[] srcHeadArray = srcHead.array();
|
||||
// byte[] srcBodyArray = srcBody.array();
|
||||
//
|
||||
// dest.put(0, srcHeadArray);
|
||||
// dest.put(srcHeadArray.length, srcBodyArray);
|
||||
}
|
||||
|
||||
public static void printBuffer(ByteBuffer buffer) {
|
||||
if (buffer == null) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < buffer.capacity(); i++) {
|
||||
System.out.print(buffer.get(i) + " ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -40,6 +40,20 @@ public final class Report {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public static MunjaonMsg getMsgData(final ByteBuffer buffer) {
|
||||
if (buffer == null) {
|
||||
return null;
|
||||
}
|
||||
MunjaonMsg msgData = new MunjaonMsg();
|
||||
msgData.setMsgId(getReportForMsgId(buffer));
|
||||
msgData.setAgentCode(getReportForAgentCode(buffer));
|
||||
msgData.setSendDate(getReportForSendTime(buffer));
|
||||
msgData.setTelecom(getReportForTelecom(buffer));
|
||||
msgData.setSendStatus(getReportForResult(buffer));
|
||||
|
||||
return msgData;
|
||||
}
|
||||
|
||||
public static void makeReportForMsgId(final ByteBuffer buffer, final String msgId) {
|
||||
if (buffer == null || msgId == null) {
|
||||
return;
|
||||
@ -139,4 +153,13 @@ public final class Report {
|
||||
|
||||
return Packet.getString(destArray);
|
||||
}
|
||||
|
||||
public static ByteBuffer makeReportAckBuffer() {
|
||||
ByteBuffer buffer = ByteBuffer.allocate(Header.HEADER_LENGTH + REPORT_ACK_BODY_LENGTH);
|
||||
Packet.setDefaultByte(buffer);
|
||||
Header.putHeader(buffer, Header.COMMAND_REPORT_ACK, REPORT_ACK_BODY_LENGTH);
|
||||
buffer.put(REPORT_ACK_RESULT_CODE_POSITION, "1".getBytes());
|
||||
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,18 +1,23 @@
|
||||
package com.munjaon.client.server.service;
|
||||
|
||||
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.MessageUtil;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.SocketChannel;
|
||||
import java.nio.file.Files;
|
||||
import java.util.List;
|
||||
|
||||
public class CollectClientService extends Service {
|
||||
private final String serviceType;
|
||||
private DatabaseTypeWorker worker;
|
||||
private SocketChannel socketChannel;
|
||||
private long lastPacketSendTime = 0;
|
||||
private String address;
|
||||
@ -27,7 +32,7 @@ public class CollectClientService extends Service {
|
||||
|
||||
@Override
|
||||
public void checkReady() {
|
||||
DatabaseTypeWorker worker = DatabaseTypeWorker.find(System.getProperty("DBMS"));
|
||||
worker = DatabaseTypeWorker.find(System.getProperty("DBMS"));
|
||||
if (worker == null) {
|
||||
return;
|
||||
}
|
||||
@ -66,6 +71,7 @@ public class CollectClientService extends Service {
|
||||
bind();
|
||||
while (isRun()) {
|
||||
try {
|
||||
// saveSystemLog("Root Path : " + System.getProperty("ROOTPATH"));
|
||||
messageService();
|
||||
linkCheckService();
|
||||
} catch (Exception e) {
|
||||
@ -105,58 +111,255 @@ public class CollectClientService extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
private void messageService() {
|
||||
DatabaseTypeWorker worker = DatabaseTypeWorker.find(System.getProperty("DBMS"));
|
||||
if (worker == null) {
|
||||
return;
|
||||
private List<MunjaonMsg> selectToDeliver() {
|
||||
if ("SMS".equals(this.serviceType)) {
|
||||
return worker.selectToDeliver("S");
|
||||
} else if ("LMS".equals(this.serviceType)) {
|
||||
return worker.selectToDeliver("L");
|
||||
} else if ("MMS".equals(this.serviceType)) {
|
||||
return worker.selectToDeliver("M");
|
||||
} else if ("KAT".equals(this.serviceType)) {
|
||||
return worker.selectToDeliver("A");
|
||||
} else if ("KFT".equals(this.serviceType)) {
|
||||
return worker.selectToDeliver("F");
|
||||
}
|
||||
List<MunjaonMsg> list = worker.selectToDeliver("S");
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void messageService() {
|
||||
List<MunjaonMsg> list = selectToDeliver();
|
||||
if (list == null || list.isEmpty()) {
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
for (MunjaonMsg data : list) {
|
||||
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);
|
||||
// sendBuffer.flip();
|
||||
try {
|
||||
Header.putHeader(sendBuffer, Header.COMMAND_DELIVER, SmsMessage.DELIVER_SMS_BODY_LENGTH);
|
||||
SmsMessage.makeDataForDeliver(sendBuffer, data);
|
||||
// CommonMessage.putMessageIdForDeliver(sendBuffer, data.getMsgId());
|
||||
// CommonMessage.putSenderForDeliver(sendBuffer, data.getSendPhone());
|
||||
//
|
||||
// CommonMessage.putReceiverForDeliver(sendBuffer, data.getRecvPhone());
|
||||
// CommonMessage.putReserveTimeForDeliver(sendBuffer, data.getReserveDate());
|
||||
// CommonMessage.putRequestTimeForDeliver(sendBuffer, data.getRequestDate());
|
||||
// CommonMessage.putMsgTypeForDeliver(sendBuffer, data.getMsgType());
|
||||
// CommonMessage.putSenderForDeliver(sendBuffer, data.getSendPhone());
|
||||
saveSystemLog("Deliver Send");
|
||||
socketChannel.write(sendBuffer);
|
||||
while (true) {
|
||||
int recvCount = socketChannel.read(recvBuffer);
|
||||
if (recvCount == -1) {
|
||||
throw new RuntimeException("DELIVER ERROR");
|
||||
} else if (recvCount > 0) {
|
||||
worker.updateToDeliver(data.getMsgId());
|
||||
saveSystemLog("Deliver OK");
|
||||
lastPacketSendTime = System.currentTimeMillis();
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
switch (this.serviceType) {
|
||||
case "SMS": smsMessageService(data); break;
|
||||
case "LMS": lmsMessageService(data); break;
|
||||
case "MMS": mmsMessageService(data); break;
|
||||
case "KAT": katMessageService(data); break;
|
||||
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);
|
||||
try {
|
||||
Header.putHeader(sendBuffer, Header.COMMAND_DELIVER, LmsMessage.DELIVER_LMS_BODY_LENGTH);
|
||||
LmsMessage.makeDataForDeliver(sendBuffer, data);
|
||||
saveSystemLog("Deliver Send");
|
||||
socketChannel.write(sendBuffer);
|
||||
while (true) {
|
||||
int recvCount = socketChannel.read(recvBuffer);
|
||||
if (recvCount == -1) {
|
||||
throw new RuntimeException("DELIVER ERROR");
|
||||
} else if (recvCount > 0) {
|
||||
worker.updateToDeliver(data.getMsgId());
|
||||
saveSystemLog("Deliver OK");
|
||||
lastPacketSendTime = System.currentTimeMillis();
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
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");
|
||||
worker.updateToDeliver(data.getMsgId());
|
||||
worker.updateToReport(errorMsg);
|
||||
}
|
||||
/* 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 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);
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
/* fileCount 저장 */
|
||||
data.setFileCount(fileCount);
|
||||
|
||||
Header.putHeader(sendBuffer, Header.COMMAND_DELIVER, MmsMessage.DELIVER_MMS_BODY_LENGTH);
|
||||
MmsMessage.makeDataForDeliver(sendBuffer, data);
|
||||
saveSystemLog("Deliver Send");
|
||||
|
||||
ByteBuffer[] byteBuffers = new ByteBuffer[fileCount + 1];
|
||||
int index = 0;
|
||||
byteBuffers[index] = sendBuffer;
|
||||
index++;
|
||||
if (file01Buffer != null) {
|
||||
byteBuffers[index] = file01Buffer;
|
||||
index++;
|
||||
}
|
||||
if (file02Buffer != null) {
|
||||
byteBuffers[index] = file02Buffer;
|
||||
index++;
|
||||
}
|
||||
if (file03Buffer != null) {
|
||||
byteBuffers[index] = file03Buffer;
|
||||
index++;
|
||||
}
|
||||
|
||||
socketChannel.write(byteBuffers);
|
||||
|
||||
while (true) {
|
||||
int recvCount = socketChannel.read(recvBuffer);
|
||||
if (recvCount == -1) {
|
||||
throw new RuntimeException("DELIVER ERROR");
|
||||
} else if (recvCount > 0) {
|
||||
worker.updateToDeliver(data.getMsgId());
|
||||
saveSystemLog("Deliver OK");
|
||||
lastPacketSendTime = System.currentTimeMillis();
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
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);
|
||||
while (true) {
|
||||
int recvCount = socketChannel.read(recvBuffer);
|
||||
if (recvCount == -1) {
|
||||
throw new RuntimeException("DELIVER ERROR");
|
||||
} else if (recvCount > 0) {
|
||||
worker.updateToDeliver(data.getMsgId());
|
||||
saveSystemLog("Deliver OK");
|
||||
lastPacketSendTime = System.currentTimeMillis();
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void linkCheckService() {
|
||||
if (System.currentTimeMillis() - lastPacketSendTime < Packet.LINK_CHECK_CYCLE) {
|
||||
saveSystemLog("LinkCheck Is Not");
|
||||
// saveSystemLog("LinkCheck Is Not");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
package com.munjaon.client.server.service;
|
||||
|
||||
import com.munjaon.client.server.packet.Bind;
|
||||
import com.munjaon.client.server.packet.Header;
|
||||
import com.munjaon.client.server.packet.LinkCheck;
|
||||
import com.munjaon.client.server.packet.Packet;
|
||||
import com.munjaon.client.model.MunjaonMsg;
|
||||
import com.munjaon.client.server.packet.*;
|
||||
import com.munjaon.client.service.DatabaseTypeWorker;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
@ -19,6 +17,13 @@ public class ReportClientService extends Service {
|
||||
private int port;
|
||||
private String id;
|
||||
private String pwd;
|
||||
private DatabaseTypeWorker worker;
|
||||
|
||||
ByteBuffer headBuffer = ByteBuffer.allocateDirect(Header.HEADER_LENGTH);
|
||||
ByteBuffer linkBodyBuffer = ByteBuffer.allocateDirect(LinkCheck.LINK_CHECK_BODY_LENGTH);
|
||||
ByteBuffer reportBodyBuffer = ByteBuffer.allocateDirect(Report.REPORT_BODY_LENGTH);
|
||||
ByteBuffer reportBuffer = ByteBuffer.allocateDirect(Header.HEADER_LENGTH + Report.REPORT_BODY_LENGTH);
|
||||
|
||||
|
||||
public ReportClientService(String serviceName) {
|
||||
super(serviceName);
|
||||
@ -26,7 +31,7 @@ public class ReportClientService extends Service {
|
||||
|
||||
@Override
|
||||
public void checkReady() {
|
||||
DatabaseTypeWorker worker = DatabaseTypeWorker.find(System.getProperty("DBMS"));
|
||||
worker = DatabaseTypeWorker.find(System.getProperty("DBMS"));
|
||||
if (worker == null) {
|
||||
return;
|
||||
}
|
||||
@ -62,7 +67,14 @@ public class ReportClientService extends Service {
|
||||
|
||||
@Override
|
||||
public void doService() {
|
||||
|
||||
bind();
|
||||
while (isRun()) {
|
||||
try {
|
||||
messageService();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void bind() {
|
||||
@ -97,37 +109,67 @@ public class ReportClientService extends Service {
|
||||
}
|
||||
|
||||
private void messageService() {
|
||||
bind();
|
||||
while (isRun()) {
|
||||
try {
|
||||
messageService();
|
||||
linkCheckService();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
|
||||
try {
|
||||
while (true) {
|
||||
headBuffer.clear();
|
||||
int recvCount = socketChannel.read(headBuffer);
|
||||
// saveSystemLog("recvCount : " + recvCount);
|
||||
if (recvCount == -1) {
|
||||
throw new RuntimeException("REPORT ERROR : Connection closed");
|
||||
} else if (recvCount > 0) {
|
||||
// Packet.printBuffer(headBuffer);
|
||||
String command = Header.getCommand(headBuffer);
|
||||
if (command == null) {
|
||||
continue;
|
||||
}
|
||||
saveSystemLog("command : " + command);
|
||||
switch (Integer.parseInt(command)) {
|
||||
case 5 :
|
||||
reportBodyBuffer.clear();
|
||||
socketChannel.read(reportBodyBuffer);
|
||||
reportService(headBuffer, reportBodyBuffer);
|
||||
break;
|
||||
case 7 :
|
||||
linkBodyBuffer.clear();
|
||||
socketChannel.read(linkBodyBuffer);
|
||||
linkCheckService(headBuffer, linkBodyBuffer);
|
||||
break;
|
||||
default: throw new RuntimeException("REPORT ERROR");
|
||||
}
|
||||
} else {
|
||||
Thread.sleep(10L);
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void linkCheckService() {
|
||||
if (System.currentTimeMillis() - lastPacketSendTime < Packet.LINK_CHECK_CYCLE) {
|
||||
saveSystemLog("LinkCheck Is Not");
|
||||
return;
|
||||
}
|
||||
|
||||
ByteBuffer recvBuffer = ByteBuffer.allocate(Header.HEADER_LENGTH + LinkCheck.LINK_CHECK_ACK_BODY_LENGTH);
|
||||
private void reportService(ByteBuffer headBuffer, ByteBuffer reportBodyBuffer) {
|
||||
try {
|
||||
saveSystemLog("LinkCheck Send");
|
||||
socketChannel.write(LinkCheck.makeLinkCheckBuffer());
|
||||
while (true) {
|
||||
int recvCount = socketChannel.read(recvBuffer);
|
||||
if (recvCount == -1) {
|
||||
throw new RuntimeException("LINK_CHECK ERROR");
|
||||
} else if (recvCount > 0) {
|
||||
saveSystemLog("LinkCheck OK");
|
||||
lastPacketSendTime = System.currentTimeMillis();
|
||||
break;
|
||||
}
|
||||
saveSystemLog("Report Received");
|
||||
reportBuffer.clear();
|
||||
Packet.mergeBuffers(reportBuffer, headBuffer, reportBodyBuffer);
|
||||
|
||||
MunjaonMsg data = Report.getMsgData(reportBuffer);
|
||||
if (data != null) {
|
||||
saveSystemLog("Report : " + data.toString());
|
||||
worker.updateToReport(data);
|
||||
socketChannel.write(Report.makeReportAckBuffer());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void linkCheckService(ByteBuffer headBuffer, ByteBuffer linkBodyBuffer) {
|
||||
try {
|
||||
saveSystemLog("LinkCheck Received");
|
||||
socketChannel.write(LinkCheck.makeLinkCheckAckBuffer());
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
108
src/main/java/com/munjaon/client/util/MessageUtil.java
Normal file
108
src/main/java/com/munjaon/client/util/MessageUtil.java
Normal file
@ -0,0 +1,108 @@
|
||||
package com.munjaon.client.util;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
public final class MessageUtil {
|
||||
public static String getDateFormat(String format) {
|
||||
return LocalDateTime.now().format(DateTimeFormatter.ofPattern(format));
|
||||
}
|
||||
|
||||
/**
|
||||
* DateFormat : yyyyMMdd
|
||||
* @return
|
||||
*/
|
||||
public static String getDate() {
|
||||
return getDateFormat("yyyyMMdd");
|
||||
}
|
||||
|
||||
/**
|
||||
* DateFormat : yyyyMMddHHmmss
|
||||
* @return
|
||||
*/
|
||||
public static String getTime() {
|
||||
return getDateFormat("yyyyMMddHHmmss");
|
||||
}
|
||||
|
||||
public static String doNumber(String spell){
|
||||
StringBuilder phoneNumber = new StringBuilder();
|
||||
if (spell == null){
|
||||
return phoneNumber.toString();
|
||||
}
|
||||
spell = spell.trim();
|
||||
int spell_Length = spell.length();
|
||||
if (spell_Length < 1){
|
||||
return phoneNumber.toString();
|
||||
}
|
||||
for (int i=0; i<spell_Length; i++){
|
||||
char eachChar = spell.charAt(i);
|
||||
if( 0x30 <= eachChar && eachChar <= 0x39 ){
|
||||
phoneNumber.append(eachChar);
|
||||
}
|
||||
}
|
||||
return phoneNumber.toString();
|
||||
}
|
||||
|
||||
// 소수점 뒤에 해당하는 자리만큼 자르기
|
||||
public static String cutFloatNumber(String srcNum, int digit){
|
||||
String headNum = "";
|
||||
String tailNum = "";
|
||||
String retNum = "";
|
||||
|
||||
if(!(srcNum == null || srcNum.trim().isEmpty())){
|
||||
srcNum = srcNum.trim();
|
||||
int index = srcNum.indexOf(".");
|
||||
// 소수점 위치가 0보다 큰경우만 처리
|
||||
if(index > 0){
|
||||
headNum = srcNum.substring(0, index);
|
||||
tailNum = srcNum.substring((index + 1));
|
||||
|
||||
if (tailNum.isEmpty()) {
|
||||
tailNum = "0";
|
||||
}
|
||||
if(tailNum.length() > digit){
|
||||
tailNum = tailNum.substring(0, digit);
|
||||
}
|
||||
retNum = headNum + "." + tailNum;
|
||||
}
|
||||
}
|
||||
|
||||
return retNum;
|
||||
}
|
||||
|
||||
// 수신번호 체크하기
|
||||
public static boolean checkPhone(String src) {
|
||||
if(src == null || src.trim().length() < 10) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return src.startsWith("0");
|
||||
}
|
||||
// 문자열 공백 제거
|
||||
public static String trim(String obj) {
|
||||
return StringUtil.trim(obj);
|
||||
}
|
||||
|
||||
public static boolean isEmptyForMessage(String obj, boolean trimFlag) {
|
||||
if (trimFlag)
|
||||
return obj == null || obj.trim().isEmpty();
|
||||
else
|
||||
return obj == null || obj.isEmpty();
|
||||
}
|
||||
|
||||
public static boolean isEmptyForMessage(String obj) {
|
||||
return isEmptyForMessage(obj, false);
|
||||
}
|
||||
|
||||
public static boolean isOverByteForMessage(String obj, int limitCount, boolean trimFlag) {
|
||||
if (isEmptyForMessage(obj, trimFlag)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return obj.getBytes().length > limitCount;
|
||||
}
|
||||
|
||||
public static boolean isOverByteForMessage(String obj, int limitCount) {
|
||||
return isOverByteForMessage(obj, limitCount, false);
|
||||
}
|
||||
}
|
||||
@ -51,7 +51,7 @@
|
||||
/* MariaDBMapper.updateToReport */
|
||||
UPDATE MUNJAON_MSG SET
|
||||
SEND_STATUS = #{sendStatus}
|
||||
, SENT_DATE = FROM_UNIXTIME(UNIX_TIMESTAMP(#{sentDate}))
|
||||
, SENT_DATE = FROM_UNIXTIME(UNIX_TIMESTAMP(#{sendDate}))
|
||||
, REPORT_DATE = NOW()
|
||||
, TELECOM = #{telecom}
|
||||
WHERE MSG_ID = #{msgId}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user