인코딩캐릭터셋 변경, 리포트 프로세스 수정

This commit is contained in:
jangdongsin 2024-10-11 14:35:59 +09:00
parent c38fbfa1ff
commit 23c9b75bc7
18 changed files with 191 additions and 126 deletions

View File

@ -1,5 +1,6 @@
package com.munjaon.client.server.packet; package com.munjaon.client.server.packet;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.Arrays; import java.util.Arrays;
@ -19,32 +20,32 @@ public final class Bind {
public static final String ENCRYPTION = "0"; public static final String ENCRYPTION = "0";
public static ByteBuffer makeBindBuffer(String id, String pwd) { public static ByteBuffer makeBindBuffer(String id, String pwd) throws UnsupportedEncodingException {
ByteBuffer buffer = ByteBuffer.allocate(Header.HEADER_LENGTH + BIND_BODY_LENGTH); ByteBuffer buffer = ByteBuffer.allocate(Header.HEADER_LENGTH + BIND_BODY_LENGTH);
Packet.setDefaultByte(buffer); Packet.setDefaultByte(buffer);
Header.putHeader(buffer, Header.COMMAND_BIND, BIND_BODY_LENGTH); Header.putHeader(buffer, Header.COMMAND_BIND, BIND_BODY_LENGTH);
/* ID */ /* ID */
if (id != null) { if (id != null) {
buffer.put(BIND_ID_POSITION, id.getBytes()); buffer.put(BIND_ID_POSITION, id.getBytes(Packet.AGENT_CHARACTER_SET));
} }
/* PWD */ /* PWD */
if (pwd != null) { if (pwd != null) {
buffer.put(BIND_PWD_POSITION, pwd.getBytes()); buffer.put(BIND_PWD_POSITION, pwd.getBytes(Packet.AGENT_CHARACTER_SET));
} }
/* ENCRYPTION */ /* ENCRYPTION */
buffer.put(BIND_ENCRYPTION_POSITION, ENCRYPTION.getBytes()); buffer.put(BIND_ENCRYPTION_POSITION, ENCRYPTION.getBytes(Packet.AGENT_CHARACTER_SET));
// buffer.limit(buffer.capacity()); // buffer.limit(buffer.capacity());
return buffer; return buffer;
} }
public static ByteBuffer makeBindAckBuffer(String resultCode) { public static ByteBuffer makeBindAckBuffer(String resultCode) throws UnsupportedEncodingException {
ByteBuffer buffer = ByteBuffer.allocate(Header.HEADER_LENGTH + BIND_ACK_BODY_LENGTH); ByteBuffer buffer = ByteBuffer.allocate(Header.HEADER_LENGTH + BIND_ACK_BODY_LENGTH);
Packet.setDefaultByte(buffer); Packet.setDefaultByte(buffer);
Header.putHeader(buffer, Header.COMMAND_BIND_ACK, BIND_ACK_BODY_LENGTH); Header.putHeader(buffer, Header.COMMAND_BIND_ACK, BIND_ACK_BODY_LENGTH);
/* resultCode */ /* resultCode */
if (resultCode != null) { if (resultCode != null) {
buffer.put(BIND_ACK_RESULT_CODE_POSITION, resultCode.getBytes()); buffer.put(BIND_ACK_RESULT_CODE_POSITION, resultCode.getBytes(Packet.AGENT_CHARACTER_SET));
} }
return buffer; return buffer;

View File

@ -2,6 +2,7 @@ package com.munjaon.client.server.packet;
import com.munjaon.client.util.CommonUtil; import com.munjaon.client.util.CommonUtil;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.Arrays; import java.util.Arrays;
@ -34,11 +35,11 @@ public final class CommonMessage {
public static final int DELIVER_ACK_RESULT_LENGTH = 1; public static final int DELIVER_ACK_RESULT_LENGTH = 1;
public static final int DELIVER_ACK_RESULT_POSITION = DELIVER_ACK_MESSAGE_ID_POSITION + DELIVER_ACK_MESSAGE_ID_LENGTH; public static final int DELIVER_ACK_RESULT_POSITION = DELIVER_ACK_MESSAGE_ID_POSITION + DELIVER_ACK_MESSAGE_ID_LENGTH;
public static void putMessageIdForDeliver(ByteBuffer buffer, String messageId) { public static void putMessageIdForDeliver(ByteBuffer buffer, String messageId) throws UnsupportedEncodingException {
if (buffer == null || messageId == null) { if (buffer == null || messageId == null) {
return; return;
} }
buffer.put(DELIVER_MESSAGE_ID_POSITION, messageId.getBytes()); buffer.put(DELIVER_MESSAGE_ID_POSITION, messageId.getBytes(Packet.AGENT_CHARACTER_SET));
} }
public static String getMessageIdForDeliver(ByteBuffer buffer) { public static String getMessageIdForDeliver(ByteBuffer buffer) {
if (buffer == null) { if (buffer == null) {
@ -52,12 +53,12 @@ public final class CommonMessage {
return Packet.getString(destArray); return Packet.getString(destArray);
} }
public static void putSenderForDeliver(ByteBuffer buffer, String sender) { public static void putSenderForDeliver(ByteBuffer buffer, String sender) throws UnsupportedEncodingException {
if (buffer == null || sender == null) { if (buffer == null || sender == null) {
return; return;
} }
sender = CommonUtil.cutString(CommonUtil.doNumber(sender), DELIVER_SENDER_LENGTH); sender = CommonUtil.cutString(CommonUtil.doNumber(sender), DELIVER_SENDER_LENGTH);
buffer.put(DELIVER_SENDER_POSITION, sender.getBytes()); buffer.put(DELIVER_SENDER_POSITION, sender.getBytes(Packet.AGENT_CHARACTER_SET));
} }
public static String getSenderForDeliver(ByteBuffer buffer) { public static String getSenderForDeliver(ByteBuffer buffer) {
if (buffer == null) { if (buffer == null) {
@ -71,12 +72,12 @@ public final class CommonMessage {
return Packet.getString(destArray); return Packet.getString(destArray);
} }
public static void putReceiverForDeliver(ByteBuffer buffer, String receiver) { public static void putReceiverForDeliver(ByteBuffer buffer, String receiver) throws UnsupportedEncodingException {
if (buffer == null || receiver == null) { if (buffer == null || receiver == null) {
return; return;
} }
receiver = CommonUtil.cutString(CommonUtil.doNumber(receiver), DELIVER_RECEIVER_LENGTH); receiver = CommonUtil.cutString(CommonUtil.doNumber(receiver), DELIVER_RECEIVER_LENGTH);
buffer.put(DELIVER_RECEIVER_POSITION, receiver.getBytes()); buffer.put(DELIVER_RECEIVER_POSITION, receiver.getBytes(Packet.AGENT_CHARACTER_SET));
} }
public static String getReceiverForDeliver(ByteBuffer buffer) { public static String getReceiverForDeliver(ByteBuffer buffer) {
if (buffer == null) { if (buffer == null) {
@ -90,11 +91,11 @@ public final class CommonMessage {
return Packet.getString(destArray); return Packet.getString(destArray);
} }
public static void putReserveTimeForDeliver(ByteBuffer buffer, String reserveTime) { public static void putReserveTimeForDeliver(ByteBuffer buffer, String reserveTime) throws UnsupportedEncodingException {
if (buffer == null || reserveTime == null) { if (buffer == null || reserveTime == null) {
return; return;
} }
buffer.put(DELIVER_RESERVE_TIME_POSITION, reserveTime.getBytes()); buffer.put(DELIVER_RESERVE_TIME_POSITION, reserveTime.getBytes(Packet.AGENT_CHARACTER_SET));
} }
public static String getReserveTimeForDeliver(ByteBuffer buffer) { public static String getReserveTimeForDeliver(ByteBuffer buffer) {
if (buffer == null) { if (buffer == null) {
@ -108,11 +109,11 @@ public final class CommonMessage {
return Packet.getString(destArray); return Packet.getString(destArray);
} }
public static void putRequestTimeForDeliver(ByteBuffer buffer, String requestTime) { public static void putRequestTimeForDeliver(ByteBuffer buffer, String requestTime) throws UnsupportedEncodingException {
if (buffer == null || requestTime == null) { if (buffer == null || requestTime == null) {
return; return;
} }
buffer.put(DELIVER_REQUEST_TIME_POSITION, requestTime.getBytes()); buffer.put(DELIVER_REQUEST_TIME_POSITION, requestTime.getBytes(Packet.AGENT_CHARACTER_SET));
} }
public static String getRequestTimeForDeliver(ByteBuffer buffer) { public static String getRequestTimeForDeliver(ByteBuffer buffer) {
if (buffer == null) { if (buffer == null) {
@ -126,11 +127,11 @@ public final class CommonMessage {
return Packet.getString(destArray); return Packet.getString(destArray);
} }
public static void putMsgTypeForDeliver(ByteBuffer buffer, String msgType) { public static void putMsgTypeForDeliver(ByteBuffer buffer, String msgType) throws UnsupportedEncodingException {
if (buffer == null || msgType == null) { if (buffer == null || msgType == null) {
return; return;
} }
buffer.put(DELIVER_MSG_TYPE_POSITION, msgType.getBytes()); buffer.put(DELIVER_MSG_TYPE_POSITION, msgType.getBytes(Packet.AGENT_CHARACTER_SET));
} }
public static String getMsgTypeForDeliver(ByteBuffer buffer) { public static String getMsgTypeForDeliver(ByteBuffer buffer) {
if (buffer == null) { if (buffer == null) {
@ -145,11 +146,11 @@ public final class CommonMessage {
} }
public static void putMessageIdForDeliverAck(ByteBuffer buffer, String messageId) { public static void putMessageIdForDeliverAck(ByteBuffer buffer, String messageId) throws UnsupportedEncodingException {
if (buffer == null || messageId == null) { if (buffer == null || messageId == null) {
return; return;
} }
buffer.put(DELIVER_ACK_MESSAGE_ID_POSITION, messageId.getBytes()); buffer.put(DELIVER_ACK_MESSAGE_ID_POSITION, messageId.getBytes(Packet.AGENT_CHARACTER_SET));
} }
public static String getMessageIdForDeliverAck(ByteBuffer buffer) { public static String getMessageIdForDeliverAck(ByteBuffer buffer) {
if (buffer == null) { if (buffer == null) {
@ -163,11 +164,11 @@ public final class CommonMessage {
return Packet.getString(destArray); return Packet.getString(destArray);
} }
public static void putResultForDeliverAck(ByteBuffer buffer, String result) { public static void putResultForDeliverAck(ByteBuffer buffer, String result) throws UnsupportedEncodingException {
if (buffer == null || result == null) { if (buffer == null || result == null) {
return; return;
} }
buffer.put(DELIVER_ACK_RESULT_POSITION, result.getBytes()); buffer.put(DELIVER_ACK_RESULT_POSITION, result.getBytes(Packet.AGENT_CHARACTER_SET));
} }
public static String getResultForDeliverAck(ByteBuffer buffer) { public static String getResultForDeliverAck(ByteBuffer buffer) {
if (buffer == null) { if (buffer == null) {

View File

@ -2,6 +2,7 @@ package com.munjaon.client.server.packet;
import com.munjaon.client.util.ByteUtil; import com.munjaon.client.util.ByteUtil;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.Arrays; import java.util.Arrays;
@ -40,11 +41,11 @@ public final class Header {
public static final int BODY_REPORT_LENGTH = 58; public static final int BODY_REPORT_LENGTH = 58;
public static final int BODY_REPORT_ACK_LENGTH = 1; public static final int BODY_REPORT_ACK_LENGTH = 1;
public static void putVersion(final ByteBuffer buffer) { public static void putVersion(final ByteBuffer buffer) throws UnsupportedEncodingException {
if (buffer == null) { if (buffer == null) {
return; return;
} }
buffer.put(VERSION_POSITION, VERSION.getBytes()); buffer.put(VERSION_POSITION, VERSION.getBytes(Packet.AGENT_CHARACTER_SET));
} }
public static String getVersion(final ByteBuffer buffer) { public static String getVersion(final ByteBuffer buffer) {
if (buffer == null) { if (buffer == null) {
@ -58,11 +59,11 @@ public final class Header {
return Packet.getString(destArray); return Packet.getString(destArray);
} }
public static void putCommand(final ByteBuffer buffer, String command) { public static void putCommand(final ByteBuffer buffer, String command) throws UnsupportedEncodingException {
if (buffer == null) { if (buffer == null) {
return; return;
} }
buffer.put(COMMAND_POSITION, command.getBytes()); buffer.put(COMMAND_POSITION, command.getBytes(Packet.AGENT_CHARACTER_SET));
} }
public static String getCommand(final ByteBuffer buffer) { public static String getCommand(final ByteBuffer buffer) {
if (buffer == null) { if (buffer == null) {
@ -76,7 +77,7 @@ public final class Header {
return Packet.getString(destArray); return Packet.getString(destArray);
} }
public static void putBodyLength(final ByteBuffer buffer, int bodyLength) { public static void putBodyLength(final ByteBuffer buffer, int bodyLength) throws UnsupportedEncodingException {
putBodyLength(buffer, Integer.toString(bodyLength)); putBodyLength(buffer, Integer.toString(bodyLength));
} }
public static String getBodyLength(final ByteBuffer buffer) { public static String getBodyLength(final ByteBuffer buffer) {
@ -91,18 +92,18 @@ public final class Header {
return Packet.getString(destArray); return Packet.getString(destArray);
} }
public static void putBodyLength(final ByteBuffer buffer, String bodyLength) { public static void putBodyLength(final ByteBuffer buffer, String bodyLength) throws UnsupportedEncodingException {
if (buffer == null) { if (buffer == null) {
return; return;
} }
System.out.println(ByteUtil.byteToHex(bodyLength.getBytes(), true)); // System.out.println(ByteUtil.byteToHex(bodyLength.getBytes(), true));
buffer.put(BODY_POSITION, bodyLength.getBytes()); buffer.put(BODY_POSITION, bodyLength.getBytes(Packet.AGENT_CHARACTER_SET));
} }
public static void putHeader(final ByteBuffer buffer, String command, int bodyLength) { public static void putHeader(final ByteBuffer buffer, String command, int bodyLength) throws UnsupportedEncodingException {
putHeader(buffer, command, Integer.toString(bodyLength)); putHeader(buffer, command, Integer.toString(bodyLength));
} }
public static void putHeader(final ByteBuffer buffer, String command, String bodyLength) { public static void putHeader(final ByteBuffer buffer, String command, String bodyLength) throws UnsupportedEncodingException {
putVersion(buffer); putVersion(buffer);
putCommand(buffer, command); putCommand(buffer, command);
putBodyLength(buffer, bodyLength); putBodyLength(buffer, bodyLength);

View File

@ -5,6 +5,7 @@ import com.munjaon.client.util.CommonUtil;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.file.Files; import java.nio.file.Files;
@ -34,12 +35,12 @@ public final class KakaoMessage {
public static final int DELIVER_KAKAO_TEMPLATE_CODE_LENGTH = 64; 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 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) { public static void putSubjectForDeliver(ByteBuffer buffer, String subject) throws UnsupportedEncodingException {
if (buffer == null || subject == null) { if (buffer == null || subject == null) {
return; return;
} }
subject = CommonUtil.cutString(subject, DELIVER_SUBJECT_LENGTH); subject = CommonUtil.cutString(subject, DELIVER_SUBJECT_LENGTH);
buffer.put(DELIVER_SUBJECT_POSITION, subject.getBytes()); buffer.put(DELIVER_SUBJECT_POSITION, subject.getBytes(Packet.AGENT_CHARACTER_SET));
} }
public static String getSubjectForDeliver(ByteBuffer buffer) { public static String getSubjectForDeliver(ByteBuffer buffer) {
if (buffer == null) { if (buffer == null) {
@ -53,12 +54,12 @@ public final class KakaoMessage {
return Packet.getString(destArray); return Packet.getString(destArray);
} }
public static void putMessageForDeliver(ByteBuffer buffer, String message) { public static void putMessageForDeliver(ByteBuffer buffer, String message) throws UnsupportedEncodingException {
if (buffer == null || message == null) { if (buffer == null || message == null) {
return; return;
} }
message = CommonUtil.cutString(message, DELIVER_MESSAGE_LENGTH); message = CommonUtil.cutString(message, DELIVER_MESSAGE_LENGTH);
buffer.put(DELIVER_MESSAGE_POSITION, message.getBytes()); buffer.put(DELIVER_MESSAGE_POSITION, message.getBytes(Packet.AGENT_CHARACTER_SET));
} }
public static String getMessageForDeliver(ByteBuffer buffer) { public static String getMessageForDeliver(ByteBuffer buffer) {
if (buffer == null) { if (buffer == null) {
@ -71,12 +72,12 @@ public final class KakaoMessage {
return Packet.getString(destArray); return Packet.getString(destArray);
} }
public static void putKakaoSenderKeyForDeliver(ByteBuffer buffer, String kakaoSenderKey) { public static void putKakaoSenderKeyForDeliver(ByteBuffer buffer, String kakaoSenderKey) throws UnsupportedEncodingException {
if (buffer == null || kakaoSenderKey == null) { if (buffer == null || kakaoSenderKey == null) {
return; return;
} }
kakaoSenderKey = CommonUtil.cutString(kakaoSenderKey, DELIVER_KAKAO_SENDER_KEY_LENGTH); kakaoSenderKey = CommonUtil.cutString(kakaoSenderKey, DELIVER_KAKAO_SENDER_KEY_LENGTH);
buffer.put(DELIVER_KAKAO_SENDER_KEY_POSITION, kakaoSenderKey.getBytes()); buffer.put(DELIVER_KAKAO_SENDER_KEY_POSITION, kakaoSenderKey.getBytes(Packet.AGENT_CHARACTER_SET));
} }
public static String getKakaoSenderKeyForDeliver(ByteBuffer buffer) { public static String getKakaoSenderKeyForDeliver(ByteBuffer buffer) {
if (buffer == null) { if (buffer == null) {
@ -89,12 +90,12 @@ public final class KakaoMessage {
return Packet.getString(destArray); return Packet.getString(destArray);
} }
public static void putKakaoTemplateCodeForDeliver(ByteBuffer buffer, String kakaoTemplateCode) { public static void putKakaoTemplateCodeForDeliver(ByteBuffer buffer, String kakaoTemplateCode) throws UnsupportedEncodingException {
if (buffer == null || kakaoTemplateCode == null) { if (buffer == null || kakaoTemplateCode == null) {
return; return;
} }
kakaoTemplateCode = CommonUtil.cutString(kakaoTemplateCode, DELIVER_KAKAO_TEMPLATE_CODE_LENGTH); kakaoTemplateCode = CommonUtil.cutString(kakaoTemplateCode, DELIVER_KAKAO_TEMPLATE_CODE_LENGTH);
buffer.put(DELIVER_KAKAO_TEMPLATE_CODE_POSITION, kakaoTemplateCode.getBytes()); buffer.put(DELIVER_KAKAO_TEMPLATE_CODE_POSITION, kakaoTemplateCode.getBytes(Packet.AGENT_CHARACTER_SET));
} }
public static String getKakaoTemplateCodeForDeliver(ByteBuffer buffer) { public static String getKakaoTemplateCodeForDeliver(ByteBuffer buffer) {
if (buffer == null) { if (buffer == null) {
@ -107,7 +108,7 @@ public final class KakaoMessage {
return Packet.getString(destArray); return Packet.getString(destArray);
} }
public static void makeDataForDeliver(ByteBuffer buffer, MunjaonMsg data) { public static void makeDataForDeliver(ByteBuffer buffer, MunjaonMsg data) throws UnsupportedEncodingException {
if (buffer == null || data == null) { if (buffer == null || data == null) {
return; return;
} }
@ -133,7 +134,7 @@ public final class KakaoMessage {
putKakaoTemplateCodeForDeliver(buffer, data.getKakaoTemplateCode()); putKakaoTemplateCodeForDeliver(buffer, data.getKakaoTemplateCode());
} }
public static ByteBuffer makeJsonForDeliver(String path, String fileName) { public static ByteBuffer makeJsonForDeliver(String path, String fileName) throws UnsupportedEncodingException {
if (path == null || fileName == null) { if (path == null || fileName == null) {
return null; return null;
} }
@ -142,8 +143,8 @@ public final class KakaoMessage {
return null; return null;
} }
ByteBuffer fileHeadBuffer = ByteBuffer.allocate(MmsMessage.DELIVER_MMS_FILENAME_LENGTH + MmsMessage.DELIVER_MMS_FILESIZE_LENGTH); 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_FILENAME_POSITION, fileName.getBytes(Packet.AGENT_CHARACTER_SET));
fileHeadBuffer.put(DELIVER_JSON_FILESIZE_POSITION, String.valueOf(file.length()).getBytes()); fileHeadBuffer.put(DELIVER_JSON_FILESIZE_POSITION, String.valueOf(file.length()).getBytes(Packet.AGENT_CHARACTER_SET));
ByteBuffer fileBodyBuffer = ByteBuffer.allocate((int) file.length()); ByteBuffer fileBodyBuffer = ByteBuffer.allocate((int) file.length());
ByteBuffer fileBuffer = null; ByteBuffer fileBuffer = null;
try { try {

View File

@ -1,5 +1,6 @@
package com.munjaon.client.server.packet; package com.munjaon.client.server.packet;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
public final class LinkCheck { public final class LinkCheck {
@ -11,20 +12,20 @@ public final class LinkCheck {
public static String LINK_CHECK_VALUE = "100"; public static String LINK_CHECK_VALUE = "100";
public static String LINK_CHECK_ACK_VALUE = "100"; public static String LINK_CHECK_ACK_VALUE = "100";
public static ByteBuffer makeLinkCheckBuffer() { public static ByteBuffer makeLinkCheckBuffer() throws UnsupportedEncodingException {
ByteBuffer buffer = ByteBuffer.allocate(Header.HEADER_LENGTH + LINK_CHECK_BODY_LENGTH); ByteBuffer buffer = ByteBuffer.allocate(Header.HEADER_LENGTH + LINK_CHECK_BODY_LENGTH);
Packet.setDefaultByte(buffer); Packet.setDefaultByte(buffer);
Header.putHeader(buffer, Header.COMMAND_LINK_CHECK, LINK_CHECK_BODY_LENGTH); Header.putHeader(buffer, Header.COMMAND_LINK_CHECK, LINK_CHECK_BODY_LENGTH);
buffer.put(LINK_CHECK_BODY_POSITION, LINK_CHECK_VALUE.getBytes()); buffer.put(LINK_CHECK_BODY_POSITION, LINK_CHECK_VALUE.getBytes(Packet.AGENT_CHARACTER_SET));
return buffer; return buffer;
} }
public static ByteBuffer makeLinkCheckAckBuffer() { public static ByteBuffer makeLinkCheckAckBuffer() throws UnsupportedEncodingException {
ByteBuffer buffer = ByteBuffer.allocate(Header.HEADER_LENGTH + LINK_CHECK_ACK_BODY_LENGTH); ByteBuffer buffer = ByteBuffer.allocate(Header.HEADER_LENGTH + LINK_CHECK_ACK_BODY_LENGTH);
Packet.setDefaultByte(buffer); Packet.setDefaultByte(buffer);
Header.putHeader(buffer, Header.COMMAND_LINK_CHECK_ACK, 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()); buffer.put(LINK_CHECK_ACK_BODY_POSITION, LINK_CHECK_ACK_VALUE.getBytes(Packet.AGENT_CHARACTER_SET));
return buffer; return buffer;
} }

View File

@ -3,6 +3,7 @@ package com.munjaon.client.server.packet;
import com.munjaon.client.model.MunjaonMsg; import com.munjaon.client.model.MunjaonMsg;
import com.munjaon.client.util.CommonUtil; import com.munjaon.client.util.CommonUtil;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
public final class LmsMessage { public final class LmsMessage {
@ -17,12 +18,12 @@ public final class LmsMessage {
public static final int DELIVER_MESSAGE_LENGTH = 2000; public static final int DELIVER_MESSAGE_LENGTH = 2000;
public static final int DELIVER_MESSAGE_POSITION = DELIVER_SUBJECT_POSITION + DELIVER_SUBJECT_LENGTH; public static final int DELIVER_MESSAGE_POSITION = DELIVER_SUBJECT_POSITION + DELIVER_SUBJECT_LENGTH;
public static void putSubjectForDeliver(ByteBuffer buffer, String subject) { public static void putSubjectForDeliver(ByteBuffer buffer, String subject) throws UnsupportedEncodingException {
if (buffer == null || subject == null) { if (buffer == null || subject == null) {
return; return;
} }
subject = CommonUtil.cutString(subject, DELIVER_SUBJECT_LENGTH); subject = CommonUtil.cutString(subject, DELIVER_SUBJECT_LENGTH);
buffer.put(DELIVER_SUBJECT_POSITION, subject.getBytes()); buffer.put(DELIVER_SUBJECT_POSITION, subject.getBytes(Packet.AGENT_CHARACTER_SET));
} }
public static String getSubjectForDeliver(ByteBuffer buffer) { public static String getSubjectForDeliver(ByteBuffer buffer) {
if (buffer == null) { if (buffer == null) {
@ -36,12 +37,12 @@ public final class LmsMessage {
return Packet.getString(destArray); return Packet.getString(destArray);
} }
public static void putMessageForDeliver(ByteBuffer buffer, String message) { public static void putMessageForDeliver(ByteBuffer buffer, String message) throws UnsupportedEncodingException {
if (buffer == null || message == null) { if (buffer == null || message == null) {
return; return;
} }
message = CommonUtil.cutString(message, DELIVER_MESSAGE_LENGTH); message = CommonUtil.cutString(message, DELIVER_MESSAGE_LENGTH);
buffer.put(DELIVER_MESSAGE_POSITION, message.getBytes()); buffer.put(DELIVER_MESSAGE_POSITION, message.getBytes(Packet.AGENT_CHARACTER_SET));
} }
public static String getMessageForDeliver(ByteBuffer buffer) { public static String getMessageForDeliver(ByteBuffer buffer) {
if (buffer == null) { if (buffer == null) {
@ -54,7 +55,7 @@ public final class LmsMessage {
return Packet.getString(destArray); return Packet.getString(destArray);
} }
public static void makeDataForDeliver(ByteBuffer buffer, MunjaonMsg data) { public static void makeDataForDeliver(ByteBuffer buffer, MunjaonMsg data) throws UnsupportedEncodingException {
if (buffer == null || data == null) { if (buffer == null || data == null) {
return; return;
} }

View File

@ -5,6 +5,7 @@ import com.munjaon.client.util.CommonUtil;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.file.Files; import java.nio.file.Files;
@ -31,12 +32,12 @@ public final class MmsMessage {
public static final int DELIVER_FILECOUNT_LENGTH = 1; public static final int DELIVER_FILECOUNT_LENGTH = 1;
public static final int DELIVER_FILECOUNT_POSITION = DELIVER_MESSAGE_POSITION + DELIVER_MESSAGE_LENGTH; public static final int DELIVER_FILECOUNT_POSITION = DELIVER_MESSAGE_POSITION + DELIVER_MESSAGE_LENGTH;
public static void putSubjectForDeliver(ByteBuffer buffer, String subject) { public static void putSubjectForDeliver(ByteBuffer buffer, String subject) throws UnsupportedEncodingException {
if (buffer == null || subject == null) { if (buffer == null || subject == null) {
return; return;
} }
subject = CommonUtil.cutString(subject, DELIVER_SUBJECT_LENGTH); subject = CommonUtil.cutString(subject, DELIVER_SUBJECT_LENGTH);
buffer.put(DELIVER_SUBJECT_POSITION, subject.getBytes()); buffer.put(DELIVER_SUBJECT_POSITION, subject.getBytes(Packet.AGENT_CHARACTER_SET));
} }
public static String getSubjectForDeliver(ByteBuffer buffer) { public static String getSubjectForDeliver(ByteBuffer buffer) {
if (buffer == null) { if (buffer == null) {
@ -50,12 +51,12 @@ public final class MmsMessage {
return Packet.getString(destArray); return Packet.getString(destArray);
} }
public static void putMessageForDeliver(ByteBuffer buffer, String message) { public static void putMessageForDeliver(ByteBuffer buffer, String message) throws UnsupportedEncodingException {
if (buffer == null || message == null) { if (buffer == null || message == null) {
return; return;
} }
message = CommonUtil.cutString(message, DELIVER_MESSAGE_LENGTH); message = CommonUtil.cutString(message, DELIVER_MESSAGE_LENGTH);
buffer.put(DELIVER_MESSAGE_POSITION, message.getBytes()); buffer.put(DELIVER_MESSAGE_POSITION, message.getBytes(Packet.AGENT_CHARACTER_SET));
} }
public static String getMessageForDeliver(ByteBuffer buffer) { public static String getMessageForDeliver(ByteBuffer buffer) {
if (buffer == null) { if (buffer == null) {
@ -69,15 +70,15 @@ public final class MmsMessage {
return Packet.getString(destArray); return Packet.getString(destArray);
} }
public static void putFileCountForDeliver(ByteBuffer buffer, int fileCount) { public static void putFileCountForDeliver(ByteBuffer buffer, int fileCount) throws UnsupportedEncodingException {
putFileCountForDeliver(buffer, Integer.toString(fileCount)); putFileCountForDeliver(buffer, Integer.toString(fileCount));
} }
public static void putFileCountForDeliver(ByteBuffer buffer, String fileCount) { public static void putFileCountForDeliver(ByteBuffer buffer, String fileCount) throws UnsupportedEncodingException {
if (buffer == null || fileCount == null) { if (buffer == null || fileCount == null) {
return; return;
} }
buffer.put(DELIVER_FILECOUNT_POSITION, fileCount.getBytes()); buffer.put(DELIVER_FILECOUNT_POSITION, fileCount.getBytes(Packet.AGENT_CHARACTER_SET));
} }
public static String getFileCountForDeliver(ByteBuffer buffer) { public static String getFileCountForDeliver(ByteBuffer buffer) {
if (buffer == null) { if (buffer == null) {
@ -90,7 +91,7 @@ public final class MmsMessage {
return Packet.getString(destArray); return Packet.getString(destArray);
} }
public static void makeDataForDeliver(ByteBuffer buffer, MunjaonMsg data) { public static void makeDataForDeliver(ByteBuffer buffer, MunjaonMsg data) throws UnsupportedEncodingException {
if (buffer == null || data == null) { if (buffer == null || data == null) {
return; return;
} }
@ -114,7 +115,7 @@ public final class MmsMessage {
putFileCountForDeliver(buffer, data.getFileCount()); putFileCountForDeliver(buffer, data.getFileCount());
} }
public static ByteBuffer makeImageForDeliver(String path, String fileName) { public static ByteBuffer makeImageForDeliver(String path, String fileName) throws UnsupportedEncodingException {
if (path == null || fileName == null) { if (path == null || fileName == null) {
return null; return null;
} }
@ -123,8 +124,8 @@ public final class MmsMessage {
return null; return null;
} }
ByteBuffer fileHeadBuffer = ByteBuffer.allocate(MmsMessage.DELIVER_MMS_FILENAME_LENGTH + MmsMessage.DELIVER_MMS_FILESIZE_LENGTH); 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_FILENAME_POSITION, fileName.getBytes(Packet.AGENT_CHARACTER_SET));
fileHeadBuffer.put(DELIVER_MMS_FILESIZE_POSITION, String.valueOf(file.length()).getBytes()); fileHeadBuffer.put(DELIVER_MMS_FILESIZE_POSITION, String.valueOf(file.length()).getBytes(Packet.AGENT_CHARACTER_SET));
ByteBuffer fileBodyBuffer = ByteBuffer.allocate((int) file.length()); ByteBuffer fileBodyBuffer = ByteBuffer.allocate((int) file.length());
ByteBuffer fileBuffer = null; ByteBuffer fileBuffer = null;
try { try {

View File

@ -3,6 +3,7 @@ package com.munjaon.client.server.packet;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
public final class Packet { public final class Packet {
public static final String AGENT_CHARACTER_SET = "EUC-KR";
public static final byte SET_DEFAULT_BYTE = (byte) 0x00; public static final byte SET_DEFAULT_BYTE = (byte) 0x00;
public static final long LINK_CHECK_CYCLE = 10000L; public static final long LINK_CHECK_CYCLE = 10000L;
/* 패킷 만료 시간 체크 */ /* 패킷 만료 시간 체크 */

View File

@ -2,6 +2,7 @@ package com.munjaon.client.server.packet;
import com.munjaon.client.model.MunjaonMsg; import com.munjaon.client.model.MunjaonMsg;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
public final class Report { public final class Report {
@ -22,7 +23,7 @@ public final class Report {
public static final int REPORT_ACK_RESULT_CODE_LENGTH = 1; public static final int REPORT_ACK_RESULT_CODE_LENGTH = 1;
public static final int REPORT_ACK_RESULT_CODE_POSITION = Header.BODY_POSITION + Header.BODY_LENGTH; public static final int REPORT_ACK_RESULT_CODE_POSITION = Header.BODY_POSITION + Header.BODY_LENGTH;
public static ByteBuffer makeReport(MunjaonMsg msgData) { public static ByteBuffer makeReport(MunjaonMsg msgData) throws UnsupportedEncodingException {
ByteBuffer buffer = ByteBuffer.allocate(Header.HEADER_LENGTH + REPORT_BODY_LENGTH); ByteBuffer buffer = ByteBuffer.allocate(Header.HEADER_LENGTH + REPORT_BODY_LENGTH);
Packet.setDefaultByte(buffer); Packet.setDefaultByte(buffer);
Header.putHeader(buffer, Header.COMMAND_REPORT, REPORT_BODY_LENGTH); Header.putHeader(buffer, Header.COMMAND_REPORT, REPORT_BODY_LENGTH);
@ -54,12 +55,12 @@ public final class Report {
return msgData; return msgData;
} }
public static void makeReportForMsgId(final ByteBuffer buffer, final String msgId) { public static void makeReportForMsgId(final ByteBuffer buffer, final String msgId) throws UnsupportedEncodingException {
if (buffer == null || msgId == null) { if (buffer == null || msgId == null) {
return; return;
} }
buffer.put(REPORT_MSG_ID_POSITION, msgId.getBytes()); buffer.put(REPORT_MSG_ID_POSITION, msgId.getBytes(Packet.AGENT_CHARACTER_SET));
} }
public static String getReportForMsgId(final ByteBuffer buffer) { public static String getReportForMsgId(final ByteBuffer buffer) {
@ -74,12 +75,12 @@ public final class Report {
return Packet.getString(destArray); return Packet.getString(destArray);
} }
public static void makeReportForAgentCode(final ByteBuffer buffer, final String agentCode) { public static void makeReportForAgentCode(final ByteBuffer buffer, final String agentCode) throws UnsupportedEncodingException {
if (buffer == null || agentCode == null) { if (buffer == null || agentCode == null) {
return; return;
} }
buffer.put(REPORT_AGENT_CODE_POSITION, agentCode.getBytes()); buffer.put(REPORT_AGENT_CODE_POSITION, agentCode.getBytes(Packet.AGENT_CHARACTER_SET));
} }
public static String getReportForAgentCode(final ByteBuffer buffer) { public static String getReportForAgentCode(final ByteBuffer buffer) {
@ -94,12 +95,12 @@ public final class Report {
return Packet.getString(destArray); return Packet.getString(destArray);
} }
public static void makeReportForSendTime(final ByteBuffer buffer, final String sendTime) { public static void makeReportForSendTime(final ByteBuffer buffer, final String sendTime) throws UnsupportedEncodingException {
if (buffer == null || sendTime == null) { if (buffer == null || sendTime == null) {
return; return;
} }
buffer.put(REPORT_SEND_TIME_POSITION, sendTime.getBytes()); buffer.put(REPORT_SEND_TIME_POSITION, sendTime.getBytes(Packet.AGENT_CHARACTER_SET));
} }
public static String getReportForSendTime(final ByteBuffer buffer) { public static String getReportForSendTime(final ByteBuffer buffer) {
@ -114,12 +115,12 @@ public final class Report {
return Packet.getString(destArray); return Packet.getString(destArray);
} }
public static void makeReportForTelecom(final ByteBuffer buffer, final String telecom) { public static void makeReportForTelecom(final ByteBuffer buffer, final String telecom) throws UnsupportedEncodingException {
if (buffer == null || telecom == null) { if (buffer == null || telecom == null) {
return; return;
} }
buffer.put(REPORT_TELECOM_POSITION, telecom.getBytes()); buffer.put(REPORT_TELECOM_POSITION, telecom.getBytes(Packet.AGENT_CHARACTER_SET));
} }
public static String getReportForTelecom(final ByteBuffer buffer) { public static String getReportForTelecom(final ByteBuffer buffer) {
@ -134,12 +135,12 @@ public final class Report {
return Packet.getString(destArray); return Packet.getString(destArray);
} }
public static void makeReportForResult(final ByteBuffer buffer, final String result) { public static void makeReportForResult(final ByteBuffer buffer, final String result) throws UnsupportedEncodingException {
if (buffer == null || result == null) { if (buffer == null || result == null) {
return; return;
} }
buffer.put(REPORT_RESULT_POSITION, result.getBytes()); buffer.put(REPORT_RESULT_POSITION, result.getBytes(Packet.AGENT_CHARACTER_SET));
} }
public static String getReportForResult(final ByteBuffer buffer) { public static String getReportForResult(final ByteBuffer buffer) {
@ -154,11 +155,11 @@ public final class Report {
return Packet.getString(destArray); return Packet.getString(destArray);
} }
public static ByteBuffer makeReportAckBuffer() { public static ByteBuffer makeReportAckBuffer() throws UnsupportedEncodingException {
ByteBuffer buffer = ByteBuffer.allocate(Header.HEADER_LENGTH + REPORT_ACK_BODY_LENGTH); ByteBuffer buffer = ByteBuffer.allocate(Header.HEADER_LENGTH + REPORT_ACK_BODY_LENGTH);
Packet.setDefaultByte(buffer); Packet.setDefaultByte(buffer);
Header.putHeader(buffer, Header.COMMAND_REPORT_ACK, REPORT_ACK_BODY_LENGTH); Header.putHeader(buffer, Header.COMMAND_REPORT_ACK, REPORT_ACK_BODY_LENGTH);
buffer.put(REPORT_ACK_RESULT_CODE_POSITION, "1".getBytes()); buffer.put(REPORT_ACK_RESULT_CODE_POSITION, "1".getBytes(Packet.AGENT_CHARACTER_SET));
return buffer; return buffer;
} }

View File

@ -3,6 +3,7 @@ package com.munjaon.client.server.packet;
import com.munjaon.client.model.MunjaonMsg; import com.munjaon.client.model.MunjaonMsg;
import com.munjaon.client.util.CommonUtil; import com.munjaon.client.util.CommonUtil;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.Arrays; import java.util.Arrays;
@ -16,12 +17,12 @@ public final class SmsMessage {
public static final int DELIVER_MESSAGE_LENGTH = 160; 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; public static final int DELIVER_MESSAGE_POSITION = CommonMessage.DELIVER_MSG_TYPE_POSITION + CommonMessage.DELIVER_MSG_TYPE_LENGTH;
public static void putMessageForDeliver(ByteBuffer buffer, String message) { public static void putMessageForDeliver(ByteBuffer buffer, String message) throws UnsupportedEncodingException {
if (buffer == null || message == null) { if (buffer == null || message == null) {
return; return;
} }
message = CommonUtil.cutString(message, DELIVER_MESSAGE_LENGTH); message = CommonUtil.cutString(message, DELIVER_MESSAGE_LENGTH);
buffer.put(DELIVER_MESSAGE_POSITION, message.getBytes()); buffer.put(DELIVER_MESSAGE_POSITION, message.getBytes(Packet.AGENT_CHARACTER_SET));
} }
public static String getMessageForDeliver(ByteBuffer buffer) { public static String getMessageForDeliver(ByteBuffer buffer) {
if (buffer == null) { if (buffer == null) {
@ -34,7 +35,7 @@ public final class SmsMessage {
return Packet.getString(destArray); return Packet.getString(destArray);
} }
public static void makeDataForDeliver(ByteBuffer buffer, MunjaonMsg data) { public static void makeDataForDeliver(ByteBuffer buffer, MunjaonMsg data) throws UnsupportedEncodingException {
if (buffer == null || data == null) { if (buffer == null || data == null) {
return; return;
} }

View File

@ -61,6 +61,23 @@ public class CollectClientService extends Service {
try { try {
socketChannel = SocketChannel.open(new InetSocketAddress(this.address, this.port)); socketChannel = SocketChannel.open(new InetSocketAddress(this.address, this.port));
socketChannel.configureBlocking(false); socketChannel.configureBlocking(false);
boolean isConnected = false;
long connectStartTime = System.currentTimeMillis();
while (true) {
if (socketChannel.finishConnect()) {
isConnected = true;
break;
}
if (System.currentTimeMillis() - connectStartTime > 3000) {
break;
}
}
if (isConnected) {
saveSystemLog("Connected to [ADDRESS : " + this.address + "] [PORT : " + this.port + "] [ID : " + this.id + "]");
} else {
throw new IOException("Connection Timeout");
}
} catch (IOException e) { } catch (IOException e) {
saveSystemLog("Connect Fail to [ADDRESS : " + this.address + "] [PORT : " + this.port + "] [ID : " + this.id + "]"); saveSystemLog("Connect Fail to [ADDRESS : " + this.address + "] [PORT : " + this.port + "] [ID : " + this.id + "]");
saveSystemLog("ERROR [" + e.getMessage() + "]"); saveSystemLog("ERROR [" + e.getMessage() + "]");
@ -105,9 +122,10 @@ public class CollectClientService extends Service {
} }
private void bind() { private void bind() {
ByteBuffer sendBuffer = Bind.makeBindBuffer(id, pwd);
ByteBuffer recvBuffer = ByteBuffer.allocate(Header.HEADER_LENGTH + Bind.BIND_ACK_BODY_LENGTH);
try { try {
ByteBuffer sendBuffer = Bind.makeBindBuffer(id, pwd);
ByteBuffer recvBuffer = ByteBuffer.allocate(Header.HEADER_LENGTH + Bind.BIND_ACK_BODY_LENGTH);
saveSystemLog("[BIND REQUEST] [IP : " + this.address + "] [PORT : " + this.port + "] [ID : " + this.id + "]"); saveSystemLog("[BIND REQUEST] [IP : " + this.address + "] [PORT : " + this.port + "] [ID : " + this.id + "]");
socketChannel.write(sendBuffer); socketChannel.write(sendBuffer);
long BIND_SEND_TIME = System.currentTimeMillis(); long BIND_SEND_TIME = System.currentTimeMillis();

View File

@ -55,6 +55,23 @@ public class ReportClientService extends Service {
try { try {
socketChannel = SocketChannel.open(new InetSocketAddress(this.address, this.port)); socketChannel = SocketChannel.open(new InetSocketAddress(this.address, this.port));
socketChannel.configureBlocking(false); socketChannel.configureBlocking(false);
boolean isConnected = false;
long connectStartTime = System.currentTimeMillis();
while (true) {
if (socketChannel.finishConnect()) {
isConnected = true;
break;
}
if (System.currentTimeMillis() - connectStartTime > 3000) {
break;
}
}
if (isConnected) {
saveSystemLog("Connected to [ADDRESS : " + this.address + "] [PORT : " + this.port + "] [ID : " + this.id + "]");
} else {
throw new IOException("Connection Timeout");
}
} catch (IOException e) { } catch (IOException e) {
saveSystemLog("Connect Fail to [ADDRESS : " + this.address + "] [PORT : " + this.port + "] [ID : " + this.id + "]"); saveSystemLog("Connect Fail to [ADDRESS : " + this.address + "] [PORT : " + this.port + "] [ID : " + this.id + "]");
saveSystemLog("ERROR [" + e.getMessage() + "]"); saveSystemLog("ERROR [" + e.getMessage() + "]");
@ -99,15 +116,19 @@ public class ReportClientService extends Service {
} }
private void bind() { private void bind() {
ByteBuffer sendBuffer = Bind.makeBindBuffer(id, pwd);
ByteBuffer recvBuffer = ByteBuffer.allocate(Header.HEADER_LENGTH + Bind.BIND_ACK_BODY_LENGTH);
try { try {
// saveSystemLog("sendBuffer " + sendBuffer.position() + ":" + sendBuffer.limit()); ByteBuffer sendBuffer = Bind.makeBindBuffer(id, pwd);
ByteBuffer recvBuffer = ByteBuffer.allocate(Header.HEADER_LENGTH + Bind.BIND_ACK_BODY_LENGTH);
saveSystemLog("Bind Try Connect to " + this.address + ":" + this.port); saveSystemLog("Bind Try Connect to " + this.address + ":" + this.port);
Thread.sleep(300);
socketChannel.write(sendBuffer); socketChannel.write(sendBuffer);
saveSystemLog("Bind Read to " + this.address + ":" + this.port); saveSystemLog("Bind Read to " + this.address + ":" + this.port);
long BIND_SEND_TIME = System.currentTimeMillis();
while (true) { while (true) {
if (System.currentTimeMillis() - BIND_SEND_TIME >= Packet.LIMIT_PACKET_SEND_TIMEOUT) {
saveSystemLog("[bindTimeOut : Expired ... ... ... ... ... ... ...]");
throw new RuntimeException("bindTimeOut : Expired ... ... ... ... ... ... ...");
}
int recvCount = socketChannel.read(recvBuffer); int recvCount = socketChannel.read(recvBuffer);
if (recvCount == -1) { if (recvCount == -1) {
throw new RuntimeException("BIND ERROR"); throw new RuntimeException("BIND ERROR");

View File

@ -1,5 +1,7 @@
package com.munjaon.client.server.service; package com.munjaon.client.server.service;
import com.munjaon.client.server.packet.Packet;
import java.io.IOException; import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.Socket; import java.net.Socket;
@ -176,7 +178,7 @@ public class Server implements Runnable {
// StringBuffer 초기화 // StringBuffer 초기화
sb.setLength(0); sb.setLength(0);
// byte 형식으로 변환 // byte 형식으로 변환
ByteBuffer buffer = ByteBuffer.wrap(data.getBytes()); ByteBuffer buffer = ByteBuffer.wrap(data.getBytes(Packet.AGENT_CHARACTER_SET));
// ***데이터 송신*** // ***데이터 송신***
channel.write(buffer); channel.write(buffer);
// Socket 채널을 channel에 수신 등록한다 // Socket 채널을 channel에 수신 등록한다

View File

@ -5,6 +5,10 @@
package com.munjaon.client.util; package com.munjaon.client.util;
import com.munjaon.client.server.packet.Packet;
import java.io.UnsupportedEncodingException;
/** /**
* bytes 관련 유틸리티 클래스 * bytes 관련 유틸리티 클래스
* @author JDS * @author JDS
@ -130,10 +134,10 @@ public final class ByteUtil {
return src[offset]; return src[offset];
} }
public static byte[] getBytes(String data) { public static byte[] getBytes(String data) throws UnsupportedEncodingException {
byte[] b = null; byte[] b = null;
b = data.getBytes(); b = data.getBytes(Packet.AGENT_CHARACTER_SET);
return (b); return (b);
} }
@ -171,8 +175,8 @@ public final class ByteUtil {
return dest; return dest;
} }
public static void setBytes(byte[] dest, int offset, String s) { public static void setBytes(byte[] dest, int offset, String s) throws UnsupportedEncodingException {
setBytes(dest, offset, s.getBytes()); setBytes(dest, offset, s.getBytes(Packet.AGENT_CHARACTER_SET));
} }
public static byte[] setBytes(byte dest[], int offset, byte src[]) { public static byte[] setBytes(byte dest[], int offset, byte src[]) {

View File

@ -1,5 +1,8 @@
package com.munjaon.client.util; package com.munjaon.client.util;
import com.munjaon.client.server.packet.Packet;
import java.io.UnsupportedEncodingException;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Calendar; import java.util.Calendar;
@ -69,12 +72,11 @@ public final class CommonUtil {
return isValid; return isValid;
} }
// 해당 길이만큼 문자열을 자르는 함수 // 해당 길이만큼 문자열을 자르는 함수
public static String cutString(String str, int limit) public static String cutString(String str, int limit) throws UnsupportedEncodingException {
{
int len = str.length(); int len = str.length();
int sumLength=0; int sumLength=0;
String cutString = null; String cutString = null;
byte[] toByte = str.getBytes(); byte[] toByte = str.getBytes(Packet.AGENT_CHARACTER_SET);
if(limit < 2) if(limit < 2)
return ""; return "";

View File

@ -5,9 +5,10 @@ import com.munjaon.client.server.config.ErrorCode;
import com.munjaon.client.server.packet.*; import com.munjaon.client.server.packet.*;
import java.io.File; import java.io.File;
import java.io.UnsupportedEncodingException;
public class MessageCheckUtil { public class MessageCheckUtil {
public static int validateMessageForCommon(MunjaonMsg data) { public static int validateMessageForCommon(MunjaonMsg data) throws UnsupportedEncodingException {
int code = isNullMessageForCommon(data); int code = isNullMessageForCommon(data);
if (code != ErrorCode.OK.getCode()) { if (code != ErrorCode.OK.getCode()) {
return code; return code;
@ -15,20 +16,20 @@ public class MessageCheckUtil {
return isLengthMessageForCommon(data); return isLengthMessageForCommon(data);
} }
public static int isLengthMessageForCommon(MunjaonMsg data) { public static int isLengthMessageForCommon(MunjaonMsg data) throws UnsupportedEncodingException {
/* MSG_ID */ /* MSG_ID */
String value = data.getMsgId().trim(); String value = data.getMsgId().trim();
if (value.length() == 0 || value.getBytes().length > CommonMessage.DELIVER_MESSAGE_ID_LENGTH) { if (value.length() == 0 || value.getBytes(Packet.AGENT_CHARACTER_SET).length > CommonMessage.DELIVER_MESSAGE_ID_LENGTH) {
return ErrorCode.ERROR_MSGID_IS_CAPACITY.getCode(); return ErrorCode.ERROR_MSGID_IS_CAPACITY.getCode();
} }
/* SENDER */ /* SENDER */
value = MessageUtil.doNumber(data.getSendPhone()); value = MessageUtil.doNumber(data.getSendPhone());
if (value.getBytes().length < 8 || value.getBytes().length > CommonMessage.DELIVER_SENDER_LENGTH) { if (value.getBytes().length < 8 || value.getBytes(Packet.AGENT_CHARACTER_SET).length > CommonMessage.DELIVER_SENDER_LENGTH) {
return ErrorCode.ERROR_SENDER_IS_CAPACITY.getCode(); return ErrorCode.ERROR_SENDER_IS_CAPACITY.getCode();
} }
/* RECEIVER */ /* RECEIVER */
value = MessageUtil.doNumber(data.getRecvPhone()); value = MessageUtil.doNumber(data.getRecvPhone());
if (value.getBytes().length < 10 || value.getBytes().length > CommonMessage.DELIVER_RECEIVER_LENGTH) { if (value.getBytes().length < 10 || value.getBytes(Packet.AGENT_CHARACTER_SET).length > CommonMessage.DELIVER_RECEIVER_LENGTH) {
return ErrorCode.ERROR_RECEIVER_IS_CAPACITY.getCode(); return ErrorCode.ERROR_RECEIVER_IS_CAPACITY.getCode();
} }
if ("01".equals(value.substring(0, 2)) == false) { if ("01".equals(value.substring(0, 2)) == false) {
@ -55,18 +56,18 @@ public class MessageCheckUtil {
return ErrorCode.OK.getCode(); return ErrorCode.OK.getCode();
} }
public static int validateMessageForSms(MunjaonMsg data) { public static int validateMessageForSms(MunjaonMsg data) throws UnsupportedEncodingException {
if (data.getMessage() == null || data.getMessage().isEmpty()) { if (data.getMessage() == null || data.getMessage().isEmpty()) {
return ErrorCode.ERROR_SMS_MSG_IS_NULL.getCode(); return ErrorCode.ERROR_SMS_MSG_IS_NULL.getCode();
} }
if (data.getMessage().getBytes().length > SmsMessage.DELIVER_MESSAGE_TRANS_LENGTH) { if (data.getMessage().getBytes(Packet.AGENT_CHARACTER_SET).length > SmsMessage.DELIVER_MESSAGE_TRANS_LENGTH) {
return ErrorCode.ERROR_SMS_MSG_IS_CAPACITY.getCode(); return ErrorCode.ERROR_SMS_MSG_IS_CAPACITY.getCode();
} }
return ErrorCode.OK.getCode(); return ErrorCode.OK.getCode();
} }
public static int validateMessageForMedia(MunjaonMsg data) { public static int validateMessageForMedia(MunjaonMsg data) throws UnsupportedEncodingException {
if (data == null) { if (data == null) {
return ErrorCode.ERROR_DATA_IS_NULL.getCode(); return ErrorCode.ERROR_DATA_IS_NULL.getCode();
} }
@ -76,10 +77,10 @@ public class MessageCheckUtil {
if (data.getMessage() == null) { if (data.getMessage() == null) {
return ErrorCode.ERROR_MULTI_MESSAGE_IS_NULL.getCode(); return ErrorCode.ERROR_MULTI_MESSAGE_IS_NULL.getCode();
} }
if (data.getSubject().getBytes().length > LmsMessage.DELIVER_SUBJECT_LENGTH) { if (data.getSubject().getBytes(Packet.AGENT_CHARACTER_SET).length > LmsMessage.DELIVER_SUBJECT_LENGTH) {
return ErrorCode.ERROR_SUBJECT_OVER_CAPACITY.getCode(); return ErrorCode.ERROR_SUBJECT_OVER_CAPACITY.getCode();
} }
if (data.getMessage().getBytes().length > LmsMessage.DELIVER_MESSAGE_LENGTH) { if (data.getMessage().getBytes(Packet.AGENT_CHARACTER_SET).length > LmsMessage.DELIVER_MESSAGE_LENGTH) {
return ErrorCode.ERROR_MULTI_MESSAGE_OVER_CAPACITY.getCode(); return ErrorCode.ERROR_MULTI_MESSAGE_OVER_CAPACITY.getCode();
} }
@ -193,7 +194,7 @@ public class MessageCheckUtil {
return false; return false;
} }
public static int validateMessageForKakao(MunjaonMsg data) { public static int validateMessageForKakao(MunjaonMsg data) throws UnsupportedEncodingException {
if (data == null) { if (data == null) {
return ErrorCode.ERROR_DATA_IS_NULL.getCode(); return ErrorCode.ERROR_DATA_IS_NULL.getCode();
} }
@ -212,16 +213,16 @@ public class MessageCheckUtil {
if (data.getKakaoJsonFile() == null) { if (data.getKakaoJsonFile() == null) {
return ErrorCode.ERROR_KAKAO_JSON_FILE_IS_NULL.getCode(); return ErrorCode.ERROR_KAKAO_JSON_FILE_IS_NULL.getCode();
} }
if (data.getSubject().getBytes().length > LmsMessage.DELIVER_SUBJECT_LENGTH) { if (data.getSubject().getBytes(Packet.AGENT_CHARACTER_SET).length > LmsMessage.DELIVER_SUBJECT_LENGTH) {
return ErrorCode.ERROR_SUBJECT_OVER_CAPACITY.getCode(); return ErrorCode.ERROR_SUBJECT_OVER_CAPACITY.getCode();
} }
if (data.getMessage().getBytes().length > LmsMessage.DELIVER_MESSAGE_LENGTH) { if (data.getMessage().getBytes(Packet.AGENT_CHARACTER_SET).length > LmsMessage.DELIVER_MESSAGE_LENGTH) {
return ErrorCode.ERROR_MULTI_MESSAGE_OVER_CAPACITY.getCode(); return ErrorCode.ERROR_MULTI_MESSAGE_OVER_CAPACITY.getCode();
} }
if (data.getKakaoSenderKey().getBytes().length > KakaoMessage.DELIVER_KAKAO_SENDER_KEY_LENGTH) { if (data.getKakaoSenderKey().getBytes(Packet.AGENT_CHARACTER_SET).length > KakaoMessage.DELIVER_KAKAO_SENDER_KEY_LENGTH) {
return ErrorCode.ERROR_KAKAO_SENDER_KEY_OVER_CAPACITY.getCode(); return ErrorCode.ERROR_KAKAO_SENDER_KEY_OVER_CAPACITY.getCode();
} }
if (data.getKakaoTemplateCode().getBytes().length > KakaoMessage.DELIVER_KAKAO_TEMPLATE_CODE_LENGTH) { if (data.getKakaoTemplateCode().getBytes(Packet.AGENT_CHARACTER_SET).length > KakaoMessage.DELIVER_KAKAO_TEMPLATE_CODE_LENGTH) {
return ErrorCode.ERROR_KAKAO_TEMPLATE_CODE_OVER_CAPACITY.getCode(); return ErrorCode.ERROR_KAKAO_TEMPLATE_CODE_OVER_CAPACITY.getCode();
} }
@ -264,14 +265,15 @@ public class MessageCheckUtil {
} }
public static void main(String[] args) { public static void main(String[] args) throws UnsupportedEncodingException {
String fileName = " .dat"; // String fileName = " .dat";
int lastIndex = fileName.lastIndexOf("."); // int lastIndex = fileName.lastIndexOf(".");
if (lastIndex < 0) { // if (lastIndex < 0) {
System.out.println("EXT is not "); // System.out.println("EXT is not ");
} else { // } else {
System.out.println("EXT : " + fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length())); // System.out.println("EXT : " + fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length()));
} // }
System.out.println("NM :" + fileName.substring(0, lastIndex) + "<<"); // System.out.println("NM :" + fileName.substring(0, lastIndex) + "<<");
System.out.println("한c".getBytes("EUC-KR").length);
} }
} }

View File

@ -1,5 +1,8 @@
package com.munjaon.client.util; package com.munjaon.client.util;
import com.munjaon.client.server.packet.Packet;
import java.io.UnsupportedEncodingException;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
@ -94,15 +97,15 @@ public final class MessageUtil {
return isEmptyForMessage(obj, false); return isEmptyForMessage(obj, false);
} }
public static boolean isOverByteForMessage(String obj, int limitCount, boolean trimFlag) { public static boolean isOverByteForMessage(String obj, int limitCount, boolean trimFlag) throws UnsupportedEncodingException {
if (isEmptyForMessage(obj, trimFlag)) { if (isEmptyForMessage(obj, trimFlag)) {
return true; return true;
} }
return obj.getBytes().length > limitCount; return obj.getBytes(Packet.AGENT_CHARACTER_SET).length > limitCount;
} }
public static boolean isOverByteForMessage(String obj, int limitCount) { public static boolean isOverByteForMessage(String obj, int limitCount) throws UnsupportedEncodingException {
return isOverByteForMessage(obj, limitCount, false); return isOverByteForMessage(obj, limitCount, false);
} }
} }

View File

@ -5,6 +5,9 @@
package com.munjaon.client.util; package com.munjaon.client.util;
import com.munjaon.client.server.packet.Packet;
import java.io.UnsupportedEncodingException;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.ArrayList; import java.util.ArrayList;
@ -123,19 +126,19 @@ public final class StringUtil {
return sRet; return sRet;
} }
public static String substring(String obj, int idx, int length) { public static String substring(String obj, int idx, int length) throws UnsupportedEncodingException {
if( obj.getBytes().length <= idx ) { if( obj.getBytes(Packet.AGENT_CHARACTER_SET).length <= idx ) {
return ""; return "";
} }
if( obj.getBytes().length <= length ) { if( obj.getBytes(Packet.AGENT_CHARACTER_SET).length <= length ) {
return obj; return obj;
} }
int totallen=0; int totallen=0;
int i=idx; int i=idx;
for( i=idx; i<obj.length(); i++ ) { for( i=idx; i<obj.length(); i++ ) {
totallen += obj.substring(i, i+1).getBytes().length; totallen += obj.substring(i, i+1).getBytes(Packet.AGENT_CHARACTER_SET).length;
if( length < totallen ) { if( length < totallen ) {
break; break;
@ -145,7 +148,7 @@ public final class StringUtil {
return obj.substring(idx, i); return obj.substring(idx, i);
} }
public static String substring(String obj, int length) { public static String substring(String obj, int length) throws UnsupportedEncodingException {
return substring(obj, 0, length); return substring(obj, 0, length);
} }