Report 기능 추가, LMS기능 추가, MMS 테스트중
@e38c24b416b91059e57ac69c7cb7744d885f06fe
--- src/main/java/com/munjaon/client/config/RunnerConfiguration.java
+++ src/main/java/com/munjaon/client/config/RunnerConfiguration.java
... | ... | @@ -2,6 +2,7 @@ |
| 2 | 2 |
|
| 3 | 3 |
import com.munjaon.client.server.service.CollectClientService; |
| 4 | 4 |
import com.munjaon.client.server.service.PropertyLoader; |
| 5 |
+import com.munjaon.client.server.service.ReportClientService; |
|
| 5 | 6 |
import lombok.RequiredArgsConstructor; |
| 6 | 7 |
import lombok.extern.slf4j.Slf4j; |
| 7 | 8 |
import org.apache.commons.configuration2.ex.ConfigurationException; |
... | ... | @@ -49,4 +50,45 @@ |
| 49 | 50 |
} |
| 50 | 51 |
return args -> System.out.println("Runner Bean #2");
|
| 51 | 52 |
} |
| 53 |
+ |
|
| 54 |
+ @Bean |
|
| 55 |
+ @Order(2) |
|
| 56 |
+ public CommandLineRunner getRunnerBeanForLms() {
|
|
| 57 |
+ try {
|
|
| 58 |
+ String serviceName = "LMS"; |
|
| 59 |
+ String serviceType = serverConfig.getString(serviceName + ".SERVICE_TYPE"); |
|
| 60 |
+ CollectClientService collectClientService = new CollectClientService(serviceName, serviceType); |
|
| 61 |
+ collectClientService.start(); |
|
| 62 |
+ } catch (Exception e) {
|
|
| 63 |
+ throw new RuntimeException(e); |
|
| 64 |
+ } |
|
| 65 |
+ return args -> System.out.println("Runner Bean #2");
|
|
| 66 |
+ } |
|
| 67 |
+ |
|
| 68 |
+ @Bean |
|
| 69 |
+ @Order(2) |
|
| 70 |
+ public CommandLineRunner getRunnerBeanForMms() {
|
|
| 71 |
+ try {
|
|
| 72 |
+ String serviceName = "MMS"; |
|
| 73 |
+ String serviceType = serverConfig.getString(serviceName + ".SERVICE_TYPE"); |
|
| 74 |
+ CollectClientService collectClientService = new CollectClientService(serviceName, serviceType); |
|
| 75 |
+ collectClientService.start(); |
|
| 76 |
+ } catch (Exception e) {
|
|
| 77 |
+ throw new RuntimeException(e); |
|
| 78 |
+ } |
|
| 79 |
+ return args -> System.out.println("Runner Bean #2");
|
|
| 80 |
+ } |
|
| 81 |
+ |
|
| 82 |
+ @Bean |
|
| 83 |
+ @Order(2) |
|
| 84 |
+ public CommandLineRunner getRunnerBeanForReport() {
|
|
| 85 |
+ try {
|
|
| 86 |
+ String serviceName = "REPORT"; |
|
| 87 |
+ ReportClientService reportClientService = new ReportClientService(serviceName); |
|
| 88 |
+ reportClientService.start(); |
|
| 89 |
+ } catch (Exception e) {
|
|
| 90 |
+ throw new RuntimeException(e); |
|
| 91 |
+ } |
|
| 92 |
+ return args -> System.out.println("Runner Bean #2");
|
|
| 93 |
+ } |
|
| 52 | 94 |
} |
--- src/main/java/com/munjaon/client/model/MunjaonMsg.java
+++ src/main/java/com/munjaon/client/model/MunjaonMsg.java
... | ... | @@ -25,4 +25,5 @@ |
| 25 | 25 |
private String deliverDate; |
| 26 | 26 |
private String sendDate; |
| 27 | 27 |
private String reportDate; |
| 28 |
+ private int fileCount = 0; |
|
| 28 | 29 |
} |
+++ src/main/java/com/munjaon/client/server/config/ErrorCode.java
... | ... | @@ -0,0 +1,37 @@ |
| 1 | +package com.munjaon.client.server.config; | |
| 2 | + | |
| 3 | +import lombok.Getter; | |
| 4 | + | |
| 5 | +@Getter | |
| 6 | +public enum ErrorCode { | |
| 7 | + OK(200, "Success"), | |
| 8 | + ERROR_DATA_IS_NULL(300, "Msg is null"), | |
| 9 | + ERROR_SUBJECT_IS_NULL(310, "Subject is null"), | |
| 10 | + ERROR_MESSAGE_IS_NULL(320, "Message is null"), | |
| 11 | + ERROR_FILE_NOT_FOUND(390, "File Not Found"), | |
| 12 | + ERROR_FILE_CAPACITY_EXCEED(391, "File capacity exceeded"); | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + private Integer code; | |
| 17 | + private String message; | |
| 18 | + | |
| 19 | + ErrorCode(Integer code, String message) { | |
| 20 | + this.code = code; | |
| 21 | + this.message = message; | |
| 22 | + } | |
| 23 | + | |
| 24 | + public static String getMessage(Integer code) { | |
| 25 | + if (code == null) { | |
| 26 | + return "etc"; | |
| 27 | + } | |
| 28 | + | |
| 29 | + for (ErrorCode resCode : values()) { | |
| 30 | + if (resCode.getCode().equals(code)) { | |
| 31 | + return resCode.getMessage(); | |
| 32 | + } | |
| 33 | + } | |
| 34 | + | |
| 35 | + return "etc"; | |
| 36 | + } | |
| 37 | +} |
--- src/main/java/com/munjaon/client/server/packet/LinkCheck.java
+++ src/main/java/com/munjaon/client/server/packet/LinkCheck.java
... | ... | @@ -23,7 +23,7 @@ |
| 23 | 23 |
public static ByteBuffer makeLinkCheckAckBuffer() {
|
| 24 | 24 |
ByteBuffer buffer = ByteBuffer.allocate(Header.HEADER_LENGTH + LINK_CHECK_ACK_BODY_LENGTH); |
| 25 | 25 |
Packet.setDefaultByte(buffer); |
| 26 |
- Header.putHeader(buffer, Header.COMMAND_LINK_CHECK, LINK_CHECK_ACK_BODY_LENGTH); |
|
| 26 |
+ Header.putHeader(buffer, Header.COMMAND_LINK_CHECK_ACK, LINK_CHECK_ACK_BODY_LENGTH); |
|
| 27 | 27 |
buffer.put(LINK_CHECK_ACK_BODY_POSITION, LINK_CHECK_ACK_VALUE.getBytes()); |
| 28 | 28 |
|
| 29 | 29 |
return buffer; |
+++ src/main/java/com/munjaon/client/server/packet/LmsMessage.java
... | ... | @@ -0,0 +1,78 @@ |
| 1 | +package com.munjaon.client.server.packet; | |
| 2 | + | |
| 3 | +import com.munjaon.client.model.MunjaonMsg; | |
| 4 | +import com.munjaon.client.util.CommonUtil; | |
| 5 | + | |
| 6 | +import java.nio.ByteBuffer; | |
| 7 | + | |
| 8 | +public final class LmsMessage { | |
| 9 | + public static final int DELIVER_LMS_BODY_LENGTH = 2091; | |
| 10 | + public static final int DELIVER_LMS_ACK_BODY_LENGTH = 21; | |
| 11 | + | |
| 12 | + /* DELIVER */ | |
| 13 | + /* SUBJECT */ | |
| 14 | + public static final int DELIVER_SUBJECT_LENGTH = 40; | |
| 15 | + public static final int DELIVER_SUBJECT_POSITION = CommonMessage.DELIVER_MSG_TYPE_POSITION + CommonMessage.DELIVER_MSG_TYPE_LENGTH; | |
| 16 | + /* MESSAGE */ | |
| 17 | + public static final int DELIVER_MESSAGE_LENGTH = 2000; | |
| 18 | + public static final int DELIVER_MESSAGE_POSITION = DELIVER_SUBJECT_POSITION + DELIVER_SUBJECT_LENGTH; | |
| 19 | + | |
| 20 | + public static void putSubjectForDeliver(ByteBuffer buffer, String subject) { | |
| 21 | + if (buffer == null || subject == null) { | |
| 22 | + return; | |
| 23 | + } | |
| 24 | + subject = CommonUtil.cutString(subject, DELIVER_SUBJECT_LENGTH); | |
| 25 | + buffer.put(DELIVER_SUBJECT_POSITION, subject.getBytes()); | |
| 26 | + } | |
| 27 | + public static String getSubjectForDeliver(ByteBuffer buffer) { | |
| 28 | + if (buffer == null) { | |
| 29 | + return null; | |
| 30 | + } | |
| 31 | + | |
| 32 | + buffer.position(DELIVER_SUBJECT_POSITION); | |
| 33 | + byte[] destArray = new byte[DELIVER_SUBJECT_LENGTH]; | |
| 34 | + buffer.get(destArray); | |
| 35 | + | |
| 36 | + return Packet.getString(destArray); | |
| 37 | + } | |
| 38 | + | |
| 39 | + public static void putMessageForDeliver(ByteBuffer buffer, String message) { | |
| 40 | + if (buffer == null || message == null) { | |
| 41 | + return; | |
| 42 | + } | |
| 43 | + message = CommonUtil.cutString(message, DELIVER_MESSAGE_LENGTH); | |
| 44 | + buffer.put(DELIVER_MESSAGE_POSITION, message.getBytes()); | |
| 45 | + } | |
| 46 | + public static String getMessageForDeliver(ByteBuffer buffer) { | |
| 47 | + if (buffer == null) { | |
| 48 | + return null; | |
| 49 | + } | |
| 50 | + | |
| 51 | + buffer.position(DELIVER_MESSAGE_POSITION); | |
| 52 | + byte[] destArray = new byte[DELIVER_MESSAGE_LENGTH]; | |
| 53 | + buffer.get(destArray); | |
| 54 | + | |
| 55 | + return Packet.getString(destArray); | |
| 56 | + } | |
| 57 | + public static void makeDataForDeliver(ByteBuffer buffer, MunjaonMsg data) { | |
| 58 | + if (buffer == null || data == null) { | |
| 59 | + return; | |
| 60 | + } | |
| 61 | + /* MSG_ID */ | |
| 62 | + CommonMessage.putMessageIdForDeliver(buffer, data.getMsgId()); | |
| 63 | + /* SENDER */ | |
| 64 | + CommonMessage.putSenderForDeliver(buffer, data.getSendPhone()); | |
| 65 | + /* RECEIVER */ | |
| 66 | + CommonMessage.putReceiverForDeliver(buffer, data.getRecvPhone()); | |
| 67 | + /* RESERVE_TIME */ | |
| 68 | + CommonMessage.putReserveTimeForDeliver(buffer, data.getReserveDate()); | |
| 69 | + /* REQUEST_TIME */ | |
| 70 | + CommonMessage.putRequestTimeForDeliver(buffer, data.getRequestDate()); | |
| 71 | + /* MSG_TYPE */ | |
| 72 | + CommonMessage.putMsgTypeForDeliver(buffer, data.getMsgType()); | |
| 73 | + /* Subject */ | |
| 74 | + putSubjectForDeliver(buffer, data.getSubject()); | |
| 75 | + /* MSG */ | |
| 76 | + putMessageForDeliver(buffer, data.getMessage()); | |
| 77 | + } | |
| 78 | +} |
+++ src/main/java/com/munjaon/client/server/packet/MmsMessage.java
... | ... | @@ -0,0 +1,113 @@ |
| 1 | +package com.munjaon.client.server.packet; | |
| 2 | + | |
| 3 | +import com.munjaon.client.model.MunjaonMsg; | |
| 4 | +import com.munjaon.client.util.CommonUtil; | |
| 5 | + | |
| 6 | +import java.nio.ByteBuffer; | |
| 7 | + | |
| 8 | +public final class MmsMessage { | |
| 9 | + public static final int LIMIT_FILE_CAPACITY = 1024 * 300; | |
| 10 | + | |
| 11 | + public static final int DELIVER_MMS_FILENAME_LENGTH = 40; | |
| 12 | + public static final int DELIVER_MMS_FILENAME_POSITION = 0; | |
| 13 | + | |
| 14 | + public static final int DELIVER_MMS_FILESIZE_LENGTH = 8; | |
| 15 | + public static final int DELIVER_MMS_FILESIZE_POSITION = DELIVER_MMS_FILENAME_POSITION + DELIVER_MMS_FILENAME_LENGTH; | |
| 16 | + | |
| 17 | + public static final int DELIVER_MMS_BODY_LENGTH = 2092; | |
| 18 | + public static final int DELIVER_MMS_ACK_BODY_LENGTH = 21; | |
| 19 | + | |
| 20 | + /* DELIVER */ | |
| 21 | + /* SUBJECT */ | |
| 22 | + public static final int DELIVER_SUBJECT_LENGTH = 40; | |
| 23 | + public static final int DELIVER_SUBJECT_POSITION = CommonMessage.DELIVER_MSG_TYPE_POSITION + CommonMessage.DELIVER_MSG_TYPE_LENGTH; | |
| 24 | + /* MESSAGE */ | |
| 25 | + public static final int DELIVER_MESSAGE_LENGTH = 2000; | |
| 26 | + public static final int DELIVER_MESSAGE_POSITION = DELIVER_SUBJECT_POSITION + DELIVER_SUBJECT_LENGTH; | |
| 27 | + /* FILECOUNT */ | |
| 28 | + public static final int DELIVER_FILECOUNT_LENGTH = 1; | |
| 29 | + public static final int DELIVER_FILECOUNT_POSITION = DELIVER_MESSAGE_POSITION + DELIVER_MESSAGE_LENGTH; | |
| 30 | + | |
| 31 | + public static void putSubjectForDeliver(ByteBuffer buffer, String subject) { | |
| 32 | + if (buffer == null || subject == null) { | |
| 33 | + return; | |
| 34 | + } | |
| 35 | + subject = CommonUtil.cutString(subject, DELIVER_SUBJECT_LENGTH); | |
| 36 | + buffer.put(DELIVER_SUBJECT_POSITION, subject.getBytes()); | |
| 37 | + } | |
| 38 | + public static String getSubjectForDeliver(ByteBuffer buffer) { | |
| 39 | + if (buffer == null) { | |
| 40 | + return null; | |
| 41 | + } | |
| 42 | + | |
| 43 | + buffer.position(DELIVER_SUBJECT_POSITION); | |
| 44 | + byte[] destArray = new byte[DELIVER_SUBJECT_LENGTH]; | |
| 45 | + buffer.get(destArray); | |
| 46 | + | |
| 47 | + return Packet.getString(destArray); | |
| 48 | + } | |
| 49 | + | |
| 50 | + public static void putMessageForDeliver(ByteBuffer buffer, String message) { | |
| 51 | + if (buffer == null || message == null) { | |
| 52 | + return; | |
| 53 | + } | |
| 54 | + message = CommonUtil.cutString(message, DELIVER_MESSAGE_LENGTH); | |
| 55 | + buffer.put(DELIVER_MESSAGE_POSITION, message.getBytes()); | |
| 56 | + } | |
| 57 | + public static String getMessageForDeliver(ByteBuffer buffer) { | |
| 58 | + if (buffer == null) { | |
| 59 | + return null; | |
| 60 | + } | |
| 61 | + | |
| 62 | + buffer.position(DELIVER_MESSAGE_POSITION); | |
| 63 | + byte[] destArray = new byte[DELIVER_MESSAGE_LENGTH]; | |
| 64 | + buffer.get(destArray); | |
| 65 | + | |
| 66 | + return Packet.getString(destArray); | |
| 67 | + } | |
| 68 | + | |
| 69 | + public static void putFileCountForDeliver(ByteBuffer buffer, int fileCount) { | |
| 70 | + putFileCountForDeliver(buffer, Integer.toString(fileCount)); | |
| 71 | + } | |
| 72 | + | |
| 73 | + public static void putFileCountForDeliver(ByteBuffer buffer, String fileCount) { | |
| 74 | + if (buffer == null || fileCount == null) { | |
| 75 | + return; | |
| 76 | + } | |
| 77 | + buffer.put(DELIVER_FILECOUNT_POSITION, fileCount.getBytes()); | |
| 78 | + } | |
| 79 | + public static String getFileCountForDeliver(ByteBuffer buffer) { | |
| 80 | + if (buffer == null) { | |
| 81 | + return null; | |
| 82 | + } | |
| 83 | + | |
| 84 | + buffer.position(DELIVER_FILECOUNT_POSITION); | |
| 85 | + byte[] destArray = new byte[DELIVER_FILECOUNT_LENGTH]; | |
| 86 | + buffer.get(destArray); | |
| 87 | + | |
| 88 | + return Packet.getString(destArray); | |
| 89 | + } | |
| 90 | + public static void makeDataForDeliver(ByteBuffer buffer, MunjaonMsg data) { | |
| 91 | + if (buffer == null || data == null) { | |
| 92 | + return; | |
| 93 | + } | |
| 94 | + /* MSG_ID */ | |
| 95 | + CommonMessage.putMessageIdForDeliver(buffer, data.getMsgId()); | |
| 96 | + /* SENDER */ | |
| 97 | + CommonMessage.putSenderForDeliver(buffer, data.getSendPhone()); | |
| 98 | + /* RECEIVER */ | |
| 99 | + CommonMessage.putReceiverForDeliver(buffer, data.getRecvPhone()); | |
| 100 | + /* RESERVE_TIME */ | |
| 101 | + CommonMessage.putReserveTimeForDeliver(buffer, data.getReserveDate()); | |
| 102 | + /* REQUEST_TIME */ | |
| 103 | + CommonMessage.putRequestTimeForDeliver(buffer, data.getRequestDate()); | |
| 104 | + /* MSG_TYPE */ | |
| 105 | + CommonMessage.putMsgTypeForDeliver(buffer, data.getMsgType()); | |
| 106 | + /* Subject */ | |
| 107 | + putSubjectForDeliver(buffer, data.getSubject()); | |
| 108 | + /* MSG */ | |
| 109 | + putMessageForDeliver(buffer, data.getMessage()); | |
| 110 | + /* FileCount */ | |
| 111 | + putFileCountForDeliver(buffer, data.getFileCount()); | |
| 112 | + } | |
| 113 | +} |
--- src/main/java/com/munjaon/client/server/packet/Packet.java
+++ src/main/java/com/munjaon/client/server/packet/Packet.java
... | ... | @@ -4,7 +4,7 @@ |
| 4 | 4 |
|
| 5 | 5 |
public final class Packet {
|
| 6 | 6 |
public static final byte SET_DEFAULT_BYTE = (byte) 0x00; |
| 7 |
- public static final long LINK_CHECK_CYCLE = 3000L; |
|
| 7 |
+ public static final long LINK_CHECK_CYCLE = 10000L; |
|
| 8 | 8 |
// public static final long LINK_CHECK_CYCLE = 30000L; |
| 9 | 9 |
|
| 10 | 10 |
public static void setDefaultByte(ByteBuffer buffer) {
|
... | ... | @@ -43,4 +43,33 @@ |
| 43 | 43 |
|
| 44 | 44 |
return destArray == null ? null : new String(destArray); |
| 45 | 45 |
} |
| 46 |
+ |
|
| 47 |
+ public static void mergeBuffers(ByteBuffer dest, ByteBuffer srcHead, ByteBuffer srcBody) {
|
|
| 48 |
+ if (dest == null || srcHead == null || srcBody == null) {
|
|
| 49 |
+ return; |
|
| 50 |
+ } |
|
| 51 |
+ if (dest.capacity() != (srcHead.capacity() + srcBody.capacity())) {
|
|
| 52 |
+ return; |
|
| 53 |
+ } |
|
| 54 |
+ for (int i = 0; i < srcHead.capacity(); i++) {
|
|
| 55 |
+ dest.put(i, srcHead.get(i)); |
|
| 56 |
+ } |
|
| 57 |
+ for (int i = 0; i < srcBody.capacity(); i++) {
|
|
| 58 |
+ dest.put((i + srcHead.capacity()), srcBody.get(i)); |
|
| 59 |
+ } |
|
| 60 |
+// byte[] srcHeadArray = srcHead.array(); |
|
| 61 |
+// byte[] srcBodyArray = srcBody.array(); |
|
| 62 |
+// |
|
| 63 |
+// dest.put(0, srcHeadArray); |
|
| 64 |
+// dest.put(srcHeadArray.length, srcBodyArray); |
|
| 65 |
+ } |
|
| 66 |
+ |
|
| 67 |
+ public static void printBuffer(ByteBuffer buffer) {
|
|
| 68 |
+ if (buffer == null) {
|
|
| 69 |
+ return; |
|
| 70 |
+ } |
|
| 71 |
+ for (int i = 0; i < buffer.capacity(); i++) {
|
|
| 72 |
+ System.out.print(buffer.get(i) + " "); |
|
| 73 |
+ } |
|
| 74 |
+ } |
|
| 46 | 75 |
} |
--- src/main/java/com/munjaon/client/server/packet/Report.java
+++ src/main/java/com/munjaon/client/server/packet/Report.java
... | ... | @@ -40,6 +40,20 @@ |
| 40 | 40 |
return buffer; |
| 41 | 41 |
} |
| 42 | 42 |
|
| 43 |
+ public static MunjaonMsg getMsgData(final ByteBuffer buffer) {
|
|
| 44 |
+ if (buffer == null) {
|
|
| 45 |
+ return null; |
|
| 46 |
+ } |
|
| 47 |
+ MunjaonMsg msgData = new MunjaonMsg(); |
|
| 48 |
+ msgData.setMsgId(getReportForMsgId(buffer)); |
|
| 49 |
+ msgData.setAgentCode(getReportForAgentCode(buffer)); |
|
| 50 |
+ msgData.setSendDate(getReportForSendTime(buffer)); |
|
| 51 |
+ msgData.setTelecom(getReportForTelecom(buffer)); |
|
| 52 |
+ msgData.setSendStatus(getReportForResult(buffer)); |
|
| 53 |
+ |
|
| 54 |
+ return msgData; |
|
| 55 |
+ } |
|
| 56 |
+ |
|
| 43 | 57 |
public static void makeReportForMsgId(final ByteBuffer buffer, final String msgId) {
|
| 44 | 58 |
if (buffer == null || msgId == null) {
|
| 45 | 59 |
return; |
... | ... | @@ -139,4 +153,13 @@ |
| 139 | 153 |
|
| 140 | 154 |
return Packet.getString(destArray); |
| 141 | 155 |
} |
| 156 |
+ |
|
| 157 |
+ public static ByteBuffer makeReportAckBuffer() {
|
|
| 158 |
+ ByteBuffer buffer = ByteBuffer.allocate(Header.HEADER_LENGTH + REPORT_ACK_BODY_LENGTH); |
|
| 159 |
+ Packet.setDefaultByte(buffer); |
|
| 160 |
+ Header.putHeader(buffer, Header.COMMAND_REPORT_ACK, REPORT_ACK_BODY_LENGTH); |
|
| 161 |
+ buffer.put(REPORT_ACK_RESULT_CODE_POSITION, "1".getBytes()); |
|
| 162 |
+ |
|
| 163 |
+ return buffer; |
|
| 164 |
+ } |
|
| 142 | 165 |
} |
--- src/main/java/com/munjaon/client/server/service/CollectClientService.java
+++ src/main/java/com/munjaon/client/server/service/CollectClientService.java
... | ... | @@ -1,18 +1,23 @@ |
| 1 | 1 |
package com.munjaon.client.server.service; |
| 2 | 2 |
|
| 3 | 3 |
import com.munjaon.client.model.MunjaonMsg; |
| 4 |
+import com.munjaon.client.server.config.ErrorCode; |
|
| 4 | 5 |
import com.munjaon.client.server.packet.*; |
| 5 | 6 |
import com.munjaon.client.service.DatabaseTypeWorker; |
| 7 |
+import com.munjaon.client.util.MessageUtil; |
|
| 6 | 8 |
import org.json.simple.JSONObject; |
| 7 | 9 |
|
| 10 |
+import java.io.File; |
|
| 8 | 11 |
import java.io.IOException; |
| 9 | 12 |
import java.net.InetSocketAddress; |
| 10 | 13 |
import java.nio.ByteBuffer; |
| 11 | 14 |
import java.nio.channels.SocketChannel; |
| 15 |
+import java.nio.file.Files; |
|
| 12 | 16 |
import java.util.List; |
| 13 | 17 |
|
| 14 | 18 |
public class CollectClientService extends Service {
|
| 15 | 19 |
private final String serviceType; |
| 20 |
+ private DatabaseTypeWorker worker; |
|
| 16 | 21 |
private SocketChannel socketChannel; |
| 17 | 22 |
private long lastPacketSendTime = 0; |
| 18 | 23 |
private String address; |
... | ... | @@ -27,7 +32,7 @@ |
| 27 | 32 |
|
| 28 | 33 |
@Override |
| 29 | 34 |
public void checkReady() {
|
| 30 |
- DatabaseTypeWorker worker = DatabaseTypeWorker.find(System.getProperty("DBMS"));
|
|
| 35 |
+ worker = DatabaseTypeWorker.find(System.getProperty("DBMS"));
|
|
| 31 | 36 |
if (worker == null) {
|
| 32 | 37 |
return; |
| 33 | 38 |
} |
... | ... | @@ -66,6 +71,7 @@ |
| 66 | 71 |
bind(); |
| 67 | 72 |
while (isRun()) {
|
| 68 | 73 |
try {
|
| 74 |
+// saveSystemLog("Root Path : " + System.getProperty("ROOTPATH"));
|
|
| 69 | 75 |
messageService(); |
| 70 | 76 |
linkCheckService(); |
| 71 | 77 |
} catch (Exception e) {
|
... | ... | @@ -105,58 +111,255 @@ |
| 105 | 111 |
} |
| 106 | 112 |
} |
| 107 | 113 |
|
| 108 |
- private void messageService() {
|
|
| 109 |
- DatabaseTypeWorker worker = DatabaseTypeWorker.find(System.getProperty("DBMS"));
|
|
| 110 |
- if (worker == null) {
|
|
| 111 |
- return; |
|
| 114 |
+ private List<MunjaonMsg> selectToDeliver() {
|
|
| 115 |
+ if ("SMS".equals(this.serviceType)) {
|
|
| 116 |
+ return worker.selectToDeliver("S");
|
|
| 117 |
+ } else if ("LMS".equals(this.serviceType)) {
|
|
| 118 |
+ return worker.selectToDeliver("L");
|
|
| 119 |
+ } else if ("MMS".equals(this.serviceType)) {
|
|
| 120 |
+ return worker.selectToDeliver("M");
|
|
| 121 |
+ } else if ("KAT".equals(this.serviceType)) {
|
|
| 122 |
+ return worker.selectToDeliver("A");
|
|
| 123 |
+ } else if ("KFT".equals(this.serviceType)) {
|
|
| 124 |
+ return worker.selectToDeliver("F");
|
|
| 112 | 125 |
} |
| 113 |
- List<MunjaonMsg> list = worker.selectToDeliver("S");
|
|
| 126 |
+ |
|
| 127 |
+ return null; |
|
| 128 |
+ } |
|
| 129 |
+ |
|
| 130 |
+ private void messageService() {
|
|
| 131 |
+ List<MunjaonMsg> list = selectToDeliver(); |
|
| 114 | 132 |
if (list == null || list.isEmpty()) {
|
| 115 | 133 |
try {
|
| 116 | 134 |
Thread.sleep(1000); |
| 117 | 135 |
} catch (InterruptedException e) {
|
| 118 | 136 |
throw new RuntimeException(e); |
| 119 | 137 |
} |
| 120 |
- |
|
| 121 | 138 |
return; |
| 122 | 139 |
} |
| 123 | 140 |
for (MunjaonMsg data : list) {
|
| 124 |
- ByteBuffer sendBuffer = ByteBuffer.allocate(Header.HEADER_LENGTH + SmsMessage.DELIVER_SMS_BODY_LENGTH); |
|
| 125 |
- ByteBuffer recvBuffer = ByteBuffer.allocate(Header.HEADER_LENGTH + SmsMessage.DELIVER_SMS_ACK_BODY_LENGTH); |
|
| 126 |
-// sendBuffer.flip(); |
|
| 127 |
- try {
|
|
| 128 |
- Header.putHeader(sendBuffer, Header.COMMAND_DELIVER, SmsMessage.DELIVER_SMS_BODY_LENGTH); |
|
| 129 |
- SmsMessage.makeDataForDeliver(sendBuffer, data); |
|
| 130 |
-// CommonMessage.putMessageIdForDeliver(sendBuffer, data.getMsgId()); |
|
| 131 |
-// CommonMessage.putSenderForDeliver(sendBuffer, data.getSendPhone()); |
|
| 132 |
-// |
|
| 133 |
-// CommonMessage.putReceiverForDeliver(sendBuffer, data.getRecvPhone()); |
|
| 134 |
-// CommonMessage.putReserveTimeForDeliver(sendBuffer, data.getReserveDate()); |
|
| 135 |
-// CommonMessage.putRequestTimeForDeliver(sendBuffer, data.getRequestDate()); |
|
| 136 |
-// CommonMessage.putMsgTypeForDeliver(sendBuffer, data.getMsgType()); |
|
| 137 |
-// CommonMessage.putSenderForDeliver(sendBuffer, data.getSendPhone()); |
|
| 138 |
- saveSystemLog("Deliver Send");
|
|
| 139 |
- socketChannel.write(sendBuffer); |
|
| 140 |
- while (true) {
|
|
| 141 |
- int recvCount = socketChannel.read(recvBuffer); |
|
| 142 |
- if (recvCount == -1) {
|
|
| 143 |
- throw new RuntimeException("DELIVER ERROR");
|
|
| 144 |
- } else if (recvCount > 0) {
|
|
| 145 |
- worker.updateToDeliver(data.getMsgId()); |
|
| 146 |
- saveSystemLog("Deliver OK");
|
|
| 147 |
- lastPacketSendTime = System.currentTimeMillis(); |
|
| 148 |
- break; |
|
| 149 |
- } |
|
| 150 |
- } |
|
| 151 |
- } catch (IOException e) {
|
|
| 152 |
- throw new RuntimeException(e); |
|
| 141 |
+ switch (this.serviceType) {
|
|
| 142 |
+ case "SMS": smsMessageService(data); break; |
|
| 143 |
+ case "LMS": lmsMessageService(data); break; |
|
| 144 |
+ case "MMS": mmsMessageService(data); break; |
|
| 145 |
+ case "KAT": katMessageService(data); break; |
|
| 146 |
+ case "KFT": kftMessageService(data); break; |
|
| 147 |
+ default:break; |
|
| 153 | 148 |
} |
| 149 |
+ |
|
| 150 |
+ } |
|
| 151 |
+ } |
|
| 152 |
+ |
|
| 153 |
+ private void lmsMessageService(MunjaonMsg data) {
|
|
| 154 |
+ if (data == null) {
|
|
| 155 |
+ return; |
|
| 156 |
+ } |
|
| 157 |
+ ByteBuffer sendBuffer = ByteBuffer.allocate(Header.HEADER_LENGTH + LmsMessage.DELIVER_LMS_BODY_LENGTH); |
|
| 158 |
+ ByteBuffer recvBuffer = ByteBuffer.allocate(Header.HEADER_LENGTH + LmsMessage.DELIVER_LMS_ACK_BODY_LENGTH); |
|
| 159 |
+ try {
|
|
| 160 |
+ Header.putHeader(sendBuffer, Header.COMMAND_DELIVER, LmsMessage.DELIVER_LMS_BODY_LENGTH); |
|
| 161 |
+ LmsMessage.makeDataForDeliver(sendBuffer, data); |
|
| 162 |
+ saveSystemLog("Deliver Send");
|
|
| 163 |
+ socketChannel.write(sendBuffer); |
|
| 164 |
+ while (true) {
|
|
| 165 |
+ int recvCount = socketChannel.read(recvBuffer); |
|
| 166 |
+ if (recvCount == -1) {
|
|
| 167 |
+ throw new RuntimeException("DELIVER ERROR");
|
|
| 168 |
+ } else if (recvCount > 0) {
|
|
| 169 |
+ worker.updateToDeliver(data.getMsgId()); |
|
| 170 |
+ saveSystemLog("Deliver OK");
|
|
| 171 |
+ lastPacketSendTime = System.currentTimeMillis(); |
|
| 172 |
+ break; |
|
| 173 |
+ } |
|
| 174 |
+ } |
|
| 175 |
+ } catch (IOException e) {
|
|
| 176 |
+ throw new RuntimeException(e); |
|
| 177 |
+ } |
|
| 178 |
+ } |
|
| 179 |
+ |
|
| 180 |
+ private void mmsMessageService(MunjaonMsg data) {
|
|
| 181 |
+ if (data == null) {
|
|
| 182 |
+ return; |
|
| 183 |
+ } |
|
| 184 |
+ ByteBuffer sendBuffer = ByteBuffer.allocate(Header.HEADER_LENGTH + MmsMessage.DELIVER_MMS_BODY_LENGTH); |
|
| 185 |
+ ByteBuffer recvBuffer = ByteBuffer.allocate(Header.HEADER_LENGTH + MmsMessage.DELIVER_MMS_ACK_BODY_LENGTH); |
|
| 186 |
+ try {
|
|
| 187 |
+ String path = System.getProperty("ROOTPATH") + File.separator + "mmsfile" + File.separator;
|
|
| 188 |
+ int fileCount = 0; |
|
| 189 |
+ int errorCode = validateErrorCodeForMms(data); |
|
| 190 |
+ if (errorCode != ErrorCode.OK.getCode()) {
|
|
| 191 |
+ MunjaonMsg errorMsg = new MunjaonMsg(); |
|
| 192 |
+ errorMsg.setMsgId(data.getMsgId()); |
|
| 193 |
+ errorMsg.setAgentCode("00");
|
|
| 194 |
+ errorMsg.setSendStatus(String.valueOf(errorCode)); |
|
| 195 |
+ errorMsg.setSendDate(MessageUtil.getTime()); |
|
| 196 |
+ errorMsg.setTelecom("ETC");
|
|
| 197 |
+ worker.updateToDeliver(data.getMsgId()); |
|
| 198 |
+ worker.updateToReport(errorMsg); |
|
| 199 |
+ } |
|
| 200 |
+ /* File check */ |
|
| 201 |
+ ByteBuffer file01Buffer = null; |
|
| 202 |
+ if (data.getFilename01() != null) {
|
|
| 203 |
+ File file = new File(path + data.getFilename01()); |
|
| 204 |
+ if (file.exists()) {
|
|
| 205 |
+ fileCount++; |
|
| 206 |
+ ByteBuffer fileHeadBuffer = ByteBuffer.allocate(MmsMessage.DELIVER_MMS_FILENAME_LENGTH + MmsMessage.DELIVER_MMS_FILESIZE_LENGTH); |
|
| 207 |
+ ByteBuffer fileBodyBuffer = ByteBuffer.allocate((int) file.length()); |
|
| 208 |
+ fileBodyBuffer.put(Files.readAllBytes(file.toPath())); |
|
| 209 |
+ file01Buffer = ByteBuffer.allocate(fileHeadBuffer.capacity() + fileBodyBuffer.capacity()); |
|
| 210 |
+ Packet.mergeBuffers(file01Buffer, fileHeadBuffer, fileBodyBuffer); |
|
| 211 |
+ } |
|
| 212 |
+ } |
|
| 213 |
+ ByteBuffer file02Buffer = null; |
|
| 214 |
+ if (data.getFilename02() != null) {
|
|
| 215 |
+ File file = new File(path + data.getFilename02()); |
|
| 216 |
+ if (file.exists()) {
|
|
| 217 |
+ fileCount++; |
|
| 218 |
+ ByteBuffer fileHeadBuffer = ByteBuffer.allocate(MmsMessage.DELIVER_MMS_FILENAME_LENGTH + MmsMessage.DELIVER_MMS_FILESIZE_LENGTH); |
|
| 219 |
+ ByteBuffer fileBodyBuffer = ByteBuffer.allocate((int) file.length()); |
|
| 220 |
+ fileBodyBuffer.put(Files.readAllBytes(file.toPath())); |
|
| 221 |
+ file02Buffer = ByteBuffer.allocate(fileHeadBuffer.capacity() + fileBodyBuffer.capacity()); |
|
| 222 |
+ Packet.mergeBuffers(file02Buffer, fileHeadBuffer, fileBodyBuffer); |
|
| 223 |
+ } |
|
| 224 |
+ } |
|
| 225 |
+ ByteBuffer file03Buffer = null; |
|
| 226 |
+ if (data.getFilename03() != null) {
|
|
| 227 |
+ File file = new File(path + data.getFilename03()); |
|
| 228 |
+ if (file.exists()) {
|
|
| 229 |
+ fileCount++; |
|
| 230 |
+ ByteBuffer fileHeadBuffer = ByteBuffer.allocate(MmsMessage.DELIVER_MMS_FILENAME_LENGTH + MmsMessage.DELIVER_MMS_FILESIZE_LENGTH); |
|
| 231 |
+ ByteBuffer fileBodyBuffer = ByteBuffer.allocate((int) file.length()); |
|
| 232 |
+ fileBodyBuffer.put(Files.readAllBytes(file.toPath())); |
|
| 233 |
+ file03Buffer = ByteBuffer.allocate(fileHeadBuffer.capacity() + fileBodyBuffer.capacity()); |
|
| 234 |
+ Packet.mergeBuffers(file03Buffer, fileHeadBuffer, fileBodyBuffer); |
|
| 235 |
+ } |
|
| 236 |
+ } |
|
| 237 |
+ /* fileCount 저장 */ |
|
| 238 |
+ data.setFileCount(fileCount); |
|
| 239 |
+ |
|
| 240 |
+ Header.putHeader(sendBuffer, Header.COMMAND_DELIVER, MmsMessage.DELIVER_MMS_BODY_LENGTH); |
|
| 241 |
+ MmsMessage.makeDataForDeliver(sendBuffer, data); |
|
| 242 |
+ saveSystemLog("Deliver Send");
|
|
| 243 |
+ |
|
| 244 |
+ ByteBuffer[] byteBuffers = new ByteBuffer[fileCount + 1]; |
|
| 245 |
+ int index = 0; |
|
| 246 |
+ byteBuffers[index] = sendBuffer; |
|
| 247 |
+ index++; |
|
| 248 |
+ if (file01Buffer != null) {
|
|
| 249 |
+ byteBuffers[index] = file01Buffer; |
|
| 250 |
+ index++; |
|
| 251 |
+ } |
|
| 252 |
+ if (file02Buffer != null) {
|
|
| 253 |
+ byteBuffers[index] = file02Buffer; |
|
| 254 |
+ index++; |
|
| 255 |
+ } |
|
| 256 |
+ if (file03Buffer != null) {
|
|
| 257 |
+ byteBuffers[index] = file03Buffer; |
|
| 258 |
+ index++; |
|
| 259 |
+ } |
|
| 260 |
+ |
|
| 261 |
+ socketChannel.write(byteBuffers); |
|
| 262 |
+ |
|
| 263 |
+ while (true) {
|
|
| 264 |
+ int recvCount = socketChannel.read(recvBuffer); |
|
| 265 |
+ if (recvCount == -1) {
|
|
| 266 |
+ throw new RuntimeException("DELIVER ERROR");
|
|
| 267 |
+ } else if (recvCount > 0) {
|
|
| 268 |
+ worker.updateToDeliver(data.getMsgId()); |
|
| 269 |
+ saveSystemLog("Deliver OK");
|
|
| 270 |
+ lastPacketSendTime = System.currentTimeMillis(); |
|
| 271 |
+ break; |
|
| 272 |
+ } |
|
| 273 |
+ } |
|
| 274 |
+ } catch (IOException e) {
|
|
| 275 |
+ throw new RuntimeException(e); |
|
| 276 |
+ } |
|
| 277 |
+ } |
|
| 278 |
+ |
|
| 279 |
+ private int validateErrorCodeForMms(MunjaonMsg data) {
|
|
| 280 |
+ if (data == null) {
|
|
| 281 |
+ return ErrorCode.ERROR_DATA_IS_NULL.getCode(); |
|
| 282 |
+ } |
|
| 283 |
+ if (data.getSubject() == null) {
|
|
| 284 |
+ return ErrorCode.ERROR_SUBJECT_IS_NULL.getCode(); |
|
| 285 |
+ } |
|
| 286 |
+ if (data.getMessage() == null) {
|
|
| 287 |
+ return ErrorCode.ERROR_MESSAGE_IS_NULL.getCode(); |
|
| 288 |
+ } |
|
| 289 |
+ /* 파일 체크 */ |
|
| 290 |
+ String path = System.getProperty("ROOTPATH") + File.separator + "mmsfile" + File.separator;
|
|
| 291 |
+ int fileCount = 0; |
|
| 292 |
+ if (data.getFilename01() != null) {
|
|
| 293 |
+ File file = new File(path + data.getFilename01()); |
|
| 294 |
+ if (file.exists()) {
|
|
| 295 |
+ if (file.length() > MmsMessage.LIMIT_FILE_CAPACITY) {
|
|
| 296 |
+ return ErrorCode.ERROR_FILE_CAPACITY_EXCEED.getCode(); |
|
| 297 |
+ } else {
|
|
| 298 |
+ fileCount++; |
|
| 299 |
+ } |
|
| 300 |
+ } |
|
| 301 |
+ } |
|
| 302 |
+ if (data.getFilename02() != null) {
|
|
| 303 |
+ File file = new File(path + data.getFilename02()); |
|
| 304 |
+ if (file.exists()) {
|
|
| 305 |
+ if (file.length() > MmsMessage.LIMIT_FILE_CAPACITY) {
|
|
| 306 |
+ return ErrorCode.ERROR_FILE_CAPACITY_EXCEED.getCode(); |
|
| 307 |
+ } else {
|
|
| 308 |
+ fileCount++; |
|
| 309 |
+ } |
|
| 310 |
+ } |
|
| 311 |
+ } |
|
| 312 |
+ if (data.getFilename03() != null) {
|
|
| 313 |
+ File file = new File(path + data.getFilename03()); |
|
| 314 |
+ if (file.exists()) {
|
|
| 315 |
+ if (file.length() > MmsMessage.LIMIT_FILE_CAPACITY) {
|
|
| 316 |
+ return ErrorCode.ERROR_FILE_CAPACITY_EXCEED.getCode(); |
|
| 317 |
+ } else {
|
|
| 318 |
+ fileCount++; |
|
| 319 |
+ } |
|
| 320 |
+ } |
|
| 321 |
+ } |
|
| 322 |
+ if (fileCount == 0) {
|
|
| 323 |
+ return ErrorCode.ERROR_FILE_NOT_FOUND.getCode(); |
|
| 324 |
+ } |
|
| 325 |
+ return ErrorCode.OK.getCode(); |
|
| 326 |
+ } |
|
| 327 |
+ |
|
| 328 |
+ private void katMessageService(MunjaonMsg data) {
|
|
| 329 |
+ |
|
| 330 |
+ } |
|
| 331 |
+ |
|
| 332 |
+ private void kftMessageService(MunjaonMsg data) {
|
|
| 333 |
+ |
|
| 334 |
+ } |
|
| 335 |
+ |
|
| 336 |
+ private void smsMessageService(MunjaonMsg data) {
|
|
| 337 |
+ ByteBuffer sendBuffer = ByteBuffer.allocate(Header.HEADER_LENGTH + SmsMessage.DELIVER_SMS_BODY_LENGTH); |
|
| 338 |
+ ByteBuffer recvBuffer = ByteBuffer.allocate(Header.HEADER_LENGTH + SmsMessage.DELIVER_SMS_ACK_BODY_LENGTH); |
|
| 339 |
+ try {
|
|
| 340 |
+ Header.putHeader(sendBuffer, Header.COMMAND_DELIVER, SmsMessage.DELIVER_SMS_BODY_LENGTH); |
|
| 341 |
+ SmsMessage.makeDataForDeliver(sendBuffer, data); |
|
| 342 |
+ saveSystemLog("Deliver Send");
|
|
| 343 |
+ socketChannel.write(sendBuffer); |
|
| 344 |
+ while (true) {
|
|
| 345 |
+ int recvCount = socketChannel.read(recvBuffer); |
|
| 346 |
+ if (recvCount == -1) {
|
|
| 347 |
+ throw new RuntimeException("DELIVER ERROR");
|
|
| 348 |
+ } else if (recvCount > 0) {
|
|
| 349 |
+ worker.updateToDeliver(data.getMsgId()); |
|
| 350 |
+ saveSystemLog("Deliver OK");
|
|
| 351 |
+ lastPacketSendTime = System.currentTimeMillis(); |
|
| 352 |
+ break; |
|
| 353 |
+ } |
|
| 354 |
+ } |
|
| 355 |
+ } catch (IOException e) {
|
|
| 356 |
+ throw new RuntimeException(e); |
|
| 154 | 357 |
} |
| 155 | 358 |
} |
| 156 | 359 |
|
| 157 | 360 |
private void linkCheckService() {
|
| 158 | 361 |
if (System.currentTimeMillis() - lastPacketSendTime < Packet.LINK_CHECK_CYCLE) {
|
| 159 |
- saveSystemLog("LinkCheck Is Not");
|
|
| 362 |
+// saveSystemLog("LinkCheck Is Not");
|
|
| 160 | 363 |
return; |
| 161 | 364 |
} |
| 162 | 365 |
|
--- src/main/java/com/munjaon/client/server/service/ReportClientService.java
+++ src/main/java/com/munjaon/client/server/service/ReportClientService.java
... | ... | @@ -1,9 +1,7 @@ |
| 1 | 1 |
package com.munjaon.client.server.service; |
| 2 | 2 |
|
| 3 |
-import com.munjaon.client.server.packet.Bind; |
|
| 4 |
-import com.munjaon.client.server.packet.Header; |
|
| 5 |
-import com.munjaon.client.server.packet.LinkCheck; |
|
| 6 |
-import com.munjaon.client.server.packet.Packet; |
|
| 3 |
+import com.munjaon.client.model.MunjaonMsg; |
|
| 4 |
+import com.munjaon.client.server.packet.*; |
|
| 7 | 5 |
import com.munjaon.client.service.DatabaseTypeWorker; |
| 8 | 6 |
import org.json.simple.JSONObject; |
| 9 | 7 |
|
... | ... | @@ -19,6 +17,13 @@ |
| 19 | 17 |
private int port; |
| 20 | 18 |
private String id; |
| 21 | 19 |
private String pwd; |
| 20 |
+ private DatabaseTypeWorker worker; |
|
| 21 |
+ |
|
| 22 |
+ ByteBuffer headBuffer = ByteBuffer.allocateDirect(Header.HEADER_LENGTH); |
|
| 23 |
+ ByteBuffer linkBodyBuffer = ByteBuffer.allocateDirect(LinkCheck.LINK_CHECK_BODY_LENGTH); |
|
| 24 |
+ ByteBuffer reportBodyBuffer = ByteBuffer.allocateDirect(Report.REPORT_BODY_LENGTH); |
|
| 25 |
+ ByteBuffer reportBuffer = ByteBuffer.allocateDirect(Header.HEADER_LENGTH + Report.REPORT_BODY_LENGTH); |
|
| 26 |
+ |
|
| 22 | 27 |
|
| 23 | 28 |
public ReportClientService(String serviceName) {
|
| 24 | 29 |
super(serviceName); |
... | ... | @@ -26,7 +31,7 @@ |
| 26 | 31 |
|
| 27 | 32 |
@Override |
| 28 | 33 |
public void checkReady() {
|
| 29 |
- DatabaseTypeWorker worker = DatabaseTypeWorker.find(System.getProperty("DBMS"));
|
|
| 34 |
+ worker = DatabaseTypeWorker.find(System.getProperty("DBMS"));
|
|
| 30 | 35 |
if (worker == null) {
|
| 31 | 36 |
return; |
| 32 | 37 |
} |
... | ... | @@ -62,7 +67,14 @@ |
| 62 | 67 |
|
| 63 | 68 |
@Override |
| 64 | 69 |
public void doService() {
|
| 65 |
- |
|
| 70 |
+ bind(); |
|
| 71 |
+ while (isRun()) {
|
|
| 72 |
+ try {
|
|
| 73 |
+ messageService(); |
|
| 74 |
+ } catch (Exception e) {
|
|
| 75 |
+ throw new RuntimeException(e); |
|
| 76 |
+ } |
|
| 77 |
+ } |
|
| 66 | 78 |
} |
| 67 | 79 |
|
| 68 | 80 |
private void bind() {
|
... | ... | @@ -97,38 +109,68 @@ |
| 97 | 109 |
} |
| 98 | 110 |
|
| 99 | 111 |
private void messageService() {
|
| 100 |
- bind(); |
|
| 101 |
- while (isRun()) {
|
|
| 102 |
- try {
|
|
| 103 |
- messageService(); |
|
| 104 |
- linkCheckService(); |
|
| 105 |
- } catch (Exception e) {
|
|
| 106 |
- throw new RuntimeException(e); |
|
| 112 |
+ |
|
| 113 |
+ try {
|
|
| 114 |
+ while (true) {
|
|
| 115 |
+ headBuffer.clear(); |
|
| 116 |
+ int recvCount = socketChannel.read(headBuffer); |
|
| 117 |
+// saveSystemLog("recvCount : " + recvCount);
|
|
| 118 |
+ if (recvCount == -1) {
|
|
| 119 |
+ throw new RuntimeException("REPORT ERROR : Connection closed");
|
|
| 120 |
+ } else if (recvCount > 0) {
|
|
| 121 |
+// Packet.printBuffer(headBuffer); |
|
| 122 |
+ String command = Header.getCommand(headBuffer); |
|
| 123 |
+ if (command == null) {
|
|
| 124 |
+ continue; |
|
| 125 |
+ } |
|
| 126 |
+ saveSystemLog("command : " + command);
|
|
| 127 |
+ switch (Integer.parseInt(command)) {
|
|
| 128 |
+ case 5 : |
|
| 129 |
+ reportBodyBuffer.clear(); |
|
| 130 |
+ socketChannel.read(reportBodyBuffer); |
|
| 131 |
+ reportService(headBuffer, reportBodyBuffer); |
|
| 132 |
+ break; |
|
| 133 |
+ case 7 : |
|
| 134 |
+ linkBodyBuffer.clear(); |
|
| 135 |
+ socketChannel.read(linkBodyBuffer); |
|
| 136 |
+ linkCheckService(headBuffer, linkBodyBuffer); |
|
| 137 |
+ break; |
|
| 138 |
+ default: throw new RuntimeException("REPORT ERROR");
|
|
| 139 |
+ } |
|
| 140 |
+ } else {
|
|
| 141 |
+ Thread.sleep(10L); |
|
| 142 |
+ } |
|
| 107 | 143 |
} |
| 144 |
+ } catch (IOException e) {
|
|
| 145 |
+ throw new RuntimeException(e); |
|
| 146 |
+ } catch (InterruptedException e) {
|
|
| 147 |
+ throw new RuntimeException(e); |
|
| 108 | 148 |
} |
| 109 | 149 |
} |
| 110 | 150 |
|
| 111 |
- private void linkCheckService() {
|
|
| 112 |
- if (System.currentTimeMillis() - lastPacketSendTime < Packet.LINK_CHECK_CYCLE) {
|
|
| 113 |
- saveSystemLog("LinkCheck Is Not");
|
|
| 114 |
- return; |
|
| 115 |
- } |
|
| 116 |
- |
|
| 117 |
- ByteBuffer recvBuffer = ByteBuffer.allocate(Header.HEADER_LENGTH + LinkCheck.LINK_CHECK_ACK_BODY_LENGTH); |
|
| 151 |
+ private void reportService(ByteBuffer headBuffer, ByteBuffer reportBodyBuffer) {
|
|
| 118 | 152 |
try {
|
| 119 |
- saveSystemLog("LinkCheck Send");
|
|
| 120 |
- socketChannel.write(LinkCheck.makeLinkCheckBuffer()); |
|
| 121 |
- while (true) {
|
|
| 122 |
- int recvCount = socketChannel.read(recvBuffer); |
|
| 123 |
- if (recvCount == -1) {
|
|
| 124 |
- throw new RuntimeException("LINK_CHECK ERROR");
|
|
| 125 |
- } else if (recvCount > 0) {
|
|
| 126 |
- saveSystemLog("LinkCheck OK");
|
|
| 127 |
- lastPacketSendTime = System.currentTimeMillis(); |
|
| 128 |
- break; |
|
| 129 |
- } |
|
| 153 |
+ saveSystemLog("Report Received");
|
|
| 154 |
+ reportBuffer.clear(); |
|
| 155 |
+ Packet.mergeBuffers(reportBuffer, headBuffer, reportBodyBuffer); |
|
| 156 |
+ |
|
| 157 |
+ MunjaonMsg data = Report.getMsgData(reportBuffer); |
|
| 158 |
+ if (data != null) {
|
|
| 159 |
+ saveSystemLog("Report : " + data.toString());
|
|
| 160 |
+ worker.updateToReport(data); |
|
| 161 |
+ socketChannel.write(Report.makeReportAckBuffer()); |
|
| 130 | 162 |
} |
| 131 | 163 |
} catch (Exception e) {
|
| 164 |
+ e.printStackTrace(); |
|
| 165 |
+ throw new RuntimeException(e); |
|
| 166 |
+ } |
|
| 167 |
+ } |
|
| 168 |
+ |
|
| 169 |
+ private void linkCheckService(ByteBuffer headBuffer, ByteBuffer linkBodyBuffer) {
|
|
| 170 |
+ try {
|
|
| 171 |
+ saveSystemLog("LinkCheck Received");
|
|
| 172 |
+ socketChannel.write(LinkCheck.makeLinkCheckAckBuffer()); |
|
| 173 |
+ } catch (Exception e) {
|
|
| 132 | 174 |
throw new RuntimeException(e); |
| 133 | 175 |
} |
| 134 | 176 |
} |
+++ src/main/java/com/munjaon/client/util/MessageUtil.java
... | ... | @@ -0,0 +1,108 @@ |
| 1 | +package com.munjaon.client.util; | |
| 2 | + | |
| 3 | +import java.time.LocalDateTime; | |
| 4 | +import java.time.format.DateTimeFormatter; | |
| 5 | + | |
| 6 | +public final class MessageUtil { | |
| 7 | + public static String getDateFormat(String format) { | |
| 8 | + return LocalDateTime.now().format(DateTimeFormatter.ofPattern(format)); | |
| 9 | + } | |
| 10 | + | |
| 11 | + /** | |
| 12 | + * DateFormat : yyyyMMdd | |
| 13 | + * @return | |
| 14 | + */ | |
| 15 | + public static String getDate() { | |
| 16 | + return getDateFormat("yyyyMMdd"); | |
| 17 | + } | |
| 18 | + | |
| 19 | + /** | |
| 20 | + * DateFormat : yyyyMMddHHmmss | |
| 21 | + * @return | |
| 22 | + */ | |
| 23 | + public static String getTime() { | |
| 24 | + return getDateFormat("yyyyMMddHHmmss"); | |
| 25 | + } | |
| 26 | + | |
| 27 | + public static String doNumber(String spell){ | |
| 28 | + StringBuilder phoneNumber = new StringBuilder(); | |
| 29 | + if (spell == null){ | |
| 30 | + return phoneNumber.toString(); | |
| 31 | + } | |
| 32 | + spell = spell.trim(); | |
| 33 | + int spell_Length = spell.length(); | |
| 34 | + if (spell_Length < 1){ | |
| 35 | + return phoneNumber.toString(); | |
| 36 | + } | |
| 37 | + for (int i=0; i<spell_Length; i++){ | |
| 38 | + char eachChar = spell.charAt(i); | |
| 39 | + if( 0x30 <= eachChar && eachChar <= 0x39 ){ | |
| 40 | + phoneNumber.append(eachChar); | |
| 41 | + } | |
| 42 | + } | |
| 43 | + return phoneNumber.toString(); | |
| 44 | + } | |
| 45 | + | |
| 46 | + // 소수점 뒤에 해당하는 자리만큼 자르기 | |
| 47 | + public static String cutFloatNumber(String srcNum, int digit){ | |
| 48 | + String headNum = ""; | |
| 49 | + String tailNum = ""; | |
| 50 | + String retNum = ""; | |
| 51 | + | |
| 52 | + if(!(srcNum == null || srcNum.trim().isEmpty())){ | |
| 53 | + srcNum = srcNum.trim(); | |
| 54 | + int index = srcNum.indexOf("."); | |
| 55 | + // 소수점 위치가 0보다 큰경우만 처리 | |
| 56 | + if(index > 0){ | |
| 57 | + headNum = srcNum.substring(0, index); | |
| 58 | + tailNum = srcNum.substring((index + 1)); | |
| 59 | + | |
| 60 | + if (tailNum.isEmpty()) { | |
| 61 | + tailNum = "0"; | |
| 62 | + } | |
| 63 | + if(tailNum.length() > digit){ | |
| 64 | + tailNum = tailNum.substring(0, digit); | |
| 65 | + } | |
| 66 | + retNum = headNum + "." + tailNum; | |
| 67 | + } | |
| 68 | + } | |
| 69 | + | |
| 70 | + return retNum; | |
| 71 | + } | |
| 72 | + | |
| 73 | + // 수신번호 체크하기 | |
| 74 | + public static boolean checkPhone(String src) { | |
| 75 | + if(src == null || src.trim().length() < 10) { | |
| 76 | + return false; | |
| 77 | + } | |
| 78 | + | |
| 79 | + return src.startsWith("0"); | |
| 80 | + } | |
| 81 | + // 문자열 공백 제거 | |
| 82 | + public static String trim(String obj) { | |
| 83 | + return StringUtil.trim(obj); | |
| 84 | + } | |
| 85 | + | |
| 86 | + public static boolean isEmptyForMessage(String obj, boolean trimFlag) { | |
| 87 | + if (trimFlag) | |
| 88 | + return obj == null || obj.trim().isEmpty(); | |
| 89 | + else | |
| 90 | + return obj == null || obj.isEmpty(); | |
| 91 | + } | |
| 92 | + | |
| 93 | + public static boolean isEmptyForMessage(String obj) { | |
| 94 | + return isEmptyForMessage(obj, false); | |
| 95 | + } | |
| 96 | + | |
| 97 | + public static boolean isOverByteForMessage(String obj, int limitCount, boolean trimFlag) { | |
| 98 | + if (isEmptyForMessage(obj, trimFlag)) { | |
| 99 | + return true; | |
| 100 | + } | |
| 101 | + | |
| 102 | + return obj.getBytes().length > limitCount; | |
| 103 | + } | |
| 104 | + | |
| 105 | + public static boolean isOverByteForMessage(String obj, int limitCount) { | |
| 106 | + return isOverByteForMessage(obj, limitCount, false); | |
| 107 | + } | |
| 108 | +} |
--- src/main/resources/sqlmap/mariadb/mariadb_sql.xml
+++ src/main/resources/sqlmap/mariadb/mariadb_sql.xml
... | ... | @@ -51,7 +51,7 @@ |
| 51 | 51 |
/* MariaDBMapper.updateToReport */ |
| 52 | 52 |
UPDATE MUNJAON_MSG SET |
| 53 | 53 |
SEND_STATUS = #{sendStatus}
|
| 54 |
- , SENT_DATE = FROM_UNIXTIME(UNIX_TIMESTAMP(#{sentDate}))
|
|
| 54 |
+ , SENT_DATE = FROM_UNIXTIME(UNIX_TIMESTAMP(#{sendDate}))
|
|
| 55 | 55 |
, REPORT_DATE = NOW() |
| 56 | 56 |
, TELECOM = #{telecom}
|
| 57 | 57 |
WHERE MSG_ID = #{msgId}
|
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?